Skip to content

Commit

Permalink
Respect #without_partial_double_verification block for job/mailer sig…
Browse files Browse the repository at this point in the history
…nature verification
  • Loading branch information
odlp committed Oct 25, 2024
1 parent 2f519d4 commit 67a538f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
7 changes: 6 additions & 1 deletion lib/rspec/rails/matchers/active_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def arguments_match?(job)
end

def detect_args_signature_mismatch(jobs)
return unless RSpec::Mocks.configuration.verify_partial_doubles?
return if skip_signature_verification?

jobs.each do |job|
args = deserialize_arguments(job)
Expand All @@ -191,6 +191,11 @@ def detect_args_signature_mismatch(jobs)
nil
end

def skip_signature_verification?
!RSpec::Mocks.configuration.verify_partial_doubles? ||
RSpec::Mocks.configuration.temporarily_suppress_partial_double_verification
end

def check_args_signature_mismatch(job_class, job_method, args)
signature = Support::MethodSignature.new(job_class.public_instance_method(job_method))
verifier = Support::StrictSignatureVerifier.new(signature, args)
Expand Down
2 changes: 1 addition & 1 deletion lib/rspec/rails/matchers/have_enqueued_mail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def arguments_match?(job)

def detect_args_signature_mismatch(jobs)
return if @method_name.nil?
return unless RSpec::Mocks.configuration.verify_partial_doubles?
return if skip_signature_verification?

mailer_class = mailer_class_name.constantize

Expand Down
20 changes: 20 additions & 0 deletions spec/rspec/rails/matchers/active_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,16 @@ def perform; raise StandardError; end
}
end
end

context "when partial double verification is temporarily suspended" do
it "skips signature checks" do
without_partial_double_verification {
expect {
two_args_job.perform_later(1)
}.to have_enqueued_job.with(1)
}
end
end
end

it "passes with provided arguments containing global id object" do
Expand Down Expand Up @@ -559,6 +569,16 @@ def perform; raise StandardError; end
}
end
end

context "when partial double verification is temporarily suspended" do
it "skips signature checks" do
keyword_args_job.perform_later(1, 2)

without_partial_double_verification {
expect(keyword_args_job).to have_been_enqueued.with(1, 2)
}
end
end
end

it "fails when negated and several jobs enqueued" do
Expand Down
10 changes: 10 additions & 0 deletions spec/rspec/rails/matchers/have_enqueued_mail_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,16 @@ def test_email; end
}
end
end

context "when partial double verification is temporarily suspended" do
it "skips signature checks" do
without_partial_double_verification {
expect {
TestMailer.email_with_args(1).deliver_later
}.to have_enqueued_mail(TestMailer, :email_with_args).with(1)
}
end
end
end

it "generates a failure message" do
Expand Down

0 comments on commit 67a538f

Please sign in to comment.