Skip to content

Commit 19baec8

Browse files
committed
Use around/before hooks to edit verify partial doubles config
#2808 (review)
1 parent 67a538f commit 19baec8

File tree

3 files changed

+30
-31
lines changed

3 files changed

+30
-31
lines changed

spec/rspec/rails/matchers/active_job_spec.rb

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
require "rspec/rails/feature_check"
2-
require "support/temporary_assignment"
32

43
if RSpec::Rails::FeatureCheck.has_active_job?
54
require "rspec/rails/matchers/active_job"
@@ -35,7 +34,6 @@ def self.find(_id)
3534

3635
RSpec.describe "ActiveJob matchers", skip: !RSpec::Rails::FeatureCheck.has_active_job? do
3736
include ActiveSupport::Testing::TimeHelpers
38-
include TemporaryAssignment
3937

4038
around do |example|
4139
original_logger = ActiveJob::Base.logger
@@ -44,6 +42,13 @@ def self.find(_id)
4442
ActiveJob::Base.logger = original_logger
4543
end
4644

45+
around do |example|
46+
original_value = RSpec::Mocks.configuration.verify_partial_doubles?
47+
example.run
48+
ensure
49+
RSpec::Mocks.configuration.verify_partial_doubles = original_value
50+
end
51+
4752
let(:heavy_lifting_job) do
4853
Class.new(ActiveJob::Base) do
4954
def perform; end
@@ -392,10 +397,12 @@ def perform; raise StandardError; end
392397
end
393398

394399
context "with partial double verification disabled" do
400+
before do
401+
RSpec::Mocks.configuration.verify_partial_doubles = false
402+
end
403+
395404
it "skips signature checks" do
396-
with_temporary_assignment(RSpec::Mocks.configuration, :verify_partial_doubles, false) {
397-
expect { two_args_job.perform_later(1) }.to have_enqueued_job.with(1)
398-
}
405+
expect { two_args_job.perform_later(1) }.to have_enqueued_job.with(1)
399406
end
400407
end
401408

@@ -561,12 +568,14 @@ def perform; raise StandardError; end
561568
end
562569

563570
context "with partial double verification disabled" do
571+
before do
572+
RSpec::Mocks.configuration.verify_partial_doubles = false
573+
end
574+
564575
it "skips signature checks" do
565576
keyword_args_job.perform_later(1, 2)
566577

567-
with_temporary_assignment(RSpec::Mocks.configuration, :verify_partial_doubles, false) {
568-
expect(keyword_args_job).to have_been_enqueued.with(1, 2)
569-
}
578+
expect(keyword_args_job).to have_been_enqueued.with(1, 2)
570579
end
571580
end
572581

spec/rspec/rails/matchers/have_enqueued_mail_spec.rb

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
require "rspec/rails/feature_check"
2-
require "support/temporary_assignment"
32

43
if RSpec::Rails::FeatureCheck.has_active_job?
54
require "action_mailer"
@@ -50,8 +49,6 @@ def test_email; end
5049
end
5150

5251
RSpec.describe "HaveEnqueuedMail matchers", skip: !RSpec::Rails::FeatureCheck.has_active_job? do
53-
include TemporaryAssignment
54-
5552
before do
5653
ActiveJob::Base.queue_adapter = :test
5754
end
@@ -63,6 +60,13 @@ def test_email; end
6360
ActiveJob::Base.logger = original_logger
6461
end
6562

63+
around do |example|
64+
original_value = RSpec::Mocks.configuration.verify_partial_doubles?
65+
example.run
66+
ensure
67+
RSpec::Mocks.configuration.verify_partial_doubles = original_value
68+
end
69+
6670
describe "have_enqueued_mail" do
6771
it "passes when a mailer method is called with deliver_later" do
6872
expect {
@@ -264,12 +268,13 @@ def test_email; end
264268
end
265269

266270
context "with partial double verification disabled" do
271+
before do
272+
RSpec::Mocks.configuration.verify_partial_doubles = false
273+
end
274+
267275
it "skips signature checks" do
268-
with_temporary_assignment(RSpec::Mocks.configuration, :verify_partial_doubles, false) {
269-
expect {
270-
TestMailer.email_with_args(1).deliver_later
271-
}.to have_enqueued_mail(TestMailer, :email_with_args).with(1)
272-
}
276+
expect { TestMailer.email_with_args(1).deliver_later }
277+
.to have_enqueued_mail(TestMailer, :email_with_args).with(1)
273278
end
274279
end
275280

spec/support/temporary_assignment.rb

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)