-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Include ActiveSupport::Testing::TaggedLogging for Rails >= 7
- Loading branch information
1 parent
72ec96f
commit d372749
Showing
3 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
if __FILE__ =~ /^snippets/ | ||
fail "Snippets are supposed to be run from their own directory to avoid side " \ | ||
"effects as e.g. the root `Gemfile`, or `spec/spec_helpers.rb` to be " \ | ||
"loaded by the root `.rspec`." | ||
end | ||
|
||
# We opt-out from using RubyGems, but `bundler/inline` requires it | ||
require 'rubygems' | ||
|
||
require "bundler/inline" | ||
|
||
# We pass `false` to `gemfile` to skip the installation of gems, | ||
# because it may install versions that would conflict with versions | ||
# from the main `Gemfile.lock`. | ||
gemfile(false) do | ||
source "https://rubygems.org" | ||
|
||
git_source(:github) { |repo| "https://github.com/#{repo}.git" } | ||
|
||
# Those Gemfiles carefully pick the right versions depending on | ||
# settings in the ENV, `.rails-version` and `maintenance-branch`. | ||
Dir.chdir('..') do | ||
eval_gemfile 'Gemfile-sqlite-dependencies' | ||
# This Gemfile expects `maintenance-branch` file to be present | ||
# in the current directory. | ||
eval_gemfile 'Gemfile-rspec-dependencies' | ||
# This Gemfile expects `.rails-version` file | ||
eval_gemfile 'Gemfile-rails-dependencies' | ||
end | ||
|
||
gem "rspec-rails", path: "../" | ||
end | ||
|
||
# Run specs at exit | ||
require "rspec/autorun" | ||
|
||
require "rails" | ||
require "active_record/railtie" | ||
require "active_job/railtie" | ||
require "rspec/rails" | ||
|
||
ActiveJob::Base.queue_adapter = :test | ||
|
||
# This connection will do for database-independent bug reports | ||
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:") | ||
|
||
class TestJob < ActiveJob::Base | ||
def perform; end | ||
end | ||
|
||
class TestError < StandardError; end | ||
|
||
RSpec.describe 'Foo', type: :job do | ||
include ::ActiveJob::TestHelper | ||
|
||
describe 'error raised in perform_enqueued_jobs with block' do | ||
it 'raises the explicitly thrown error' do | ||
allow_any_instance_of(TestJob).to receive(:perform).and_raise(TestError) | ||
|
||
# Rails 6.1+ wraps unexpected errors in tests | ||
expected_error = if Rails::VERSION::STRING.to_f >= 6.1 | ||
Minitest::UnexpectedError.new(TestError) | ||
else | ||
TestError | ||
end | ||
|
||
expect { perform_enqueued_jobs { TestJob.perform_later } } | ||
.to raise_error(expected_error) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module RSpec::Rails | ||
RSpec.describe RailsExampleGroup do | ||
if ::Rails::VERSION::MAJOR >= 7 | ||
it 'includes ActiveSupport::Testing::TaggedLogging' do | ||
expect(described_class.include?(::ActiveSupport::Testing::TaggedLogging)).to eq(true) | ||
expect(described_class.private_instance_methods).to include(:tagged_logger) | ||
end | ||
end | ||
end | ||
end |