diff --git a/lib/rspec/rails/matchers/active_job.rb b/lib/rspec/rails/matchers/active_job.rb index f3da81e48..f1c2347b1 100644 --- a/lib/rspec/rails/matchers/active_job.rb +++ b/lib/rspec/rails/matchers/active_job.rb @@ -320,6 +320,10 @@ def does_not_match?(proc) !matches?(proc) end + + def supports_block_expectations? + false + end end # @private @@ -352,6 +356,10 @@ def matches?(job) @job = job check(queue_adapter.performed_jobs) end + + def supports_block_expectations? + false + end end end diff --git a/spec/rspec/rails/matchers/active_job_spec.rb b/spec/rspec/rails/matchers/active_job_spec.rb index 2111e3435..cbf947fba 100644 --- a/spec/rspec/rails/matchers/active_job_spec.rb +++ b/spec/rspec/rails/matchers/active_job_spec.rb @@ -541,6 +541,12 @@ def perform; raise StandardError; end describe "have_been_enqueued" do before { ActiveJob::Base.queue_adapter.enqueued_jobs.clear } + it "raises RSpec::Expectations::ExpectationNotMetError when Proc passed to expect" do + expect { + expect { heavy_lifting_job }.to have_been_enqueued + }.to raise_error(RSpec::Expectations::ExpectationNotMetError) + end + it "passes with default jobs count (exactly one)" do heavy_lifting_job.perform_later expect(heavy_lifting_job).to have_been_enqueued @@ -861,6 +867,12 @@ def perform; raise StandardError; end stub_const('HeavyLiftingJob', heavy_lifting_job) end + it "raises RSpec::Expectations::ExpectationNotMetError when Proc passed to expect" do + expect { + expect { heavy_lifting_job }.to have_been_performed + }.to raise_error(RSpec::Expectations::ExpectationNotMetError) + end + it "passes with default jobs count (exactly one)" do heavy_lifting_job.perform_later expect(heavy_lifting_job).to have_been_performed