Skip to content

Commit ce9663e

Browse files
authored
Do not support block expectations on HaveBeenPerformed/HaveBeenEnqueued (#2851)
1 parent 71e15f3 commit ce9663e

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

lib/rspec/rails/matchers/active_job.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,10 @@ def does_not_match?(proc)
320320

321321
!matches?(proc)
322322
end
323+
324+
def supports_block_expectations?
325+
false
326+
end
323327
end
324328

325329
# @private
@@ -352,6 +356,10 @@ def matches?(job)
352356
@job = job
353357
check(queue_adapter.performed_jobs)
354358
end
359+
360+
def supports_block_expectations?
361+
false
362+
end
355363
end
356364
end
357365

spec/rspec/rails/matchers/active_job_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,12 @@ def perform; raise StandardError; end
541541
describe "have_been_enqueued" do
542542
before { ActiveJob::Base.queue_adapter.enqueued_jobs.clear }
543543

544+
it "raises RSpec::Expectations::ExpectationNotMetError when Proc passed to expect" do
545+
expect {
546+
expect { heavy_lifting_job }.to have_been_enqueued
547+
}.to raise_error(RSpec::Expectations::ExpectationNotMetError)
548+
end
549+
544550
it "passes with default jobs count (exactly one)" do
545551
heavy_lifting_job.perform_later
546552
expect(heavy_lifting_job).to have_been_enqueued
@@ -861,6 +867,12 @@ def perform; raise StandardError; end
861867
stub_const('HeavyLiftingJob', heavy_lifting_job)
862868
end
863869

870+
it "raises RSpec::Expectations::ExpectationNotMetError when Proc passed to expect" do
871+
expect {
872+
expect { heavy_lifting_job }.to have_been_performed
873+
}.to raise_error(RSpec::Expectations::ExpectationNotMetError)
874+
end
875+
864876
it "passes with default jobs count (exactly one)" do
865877
heavy_lifting_job.perform_later
866878
expect(heavy_lifting_job).to have_been_performed

0 commit comments

Comments
 (0)