diff --git a/lib/rspec/rails/matchers/active_job.rb b/lib/rspec/rails/matchers/active_job.rb index 7e9492299d..d4957c5072 100644 --- a/lib/rspec/rails/matchers/active_job.rb +++ b/lib/rspec/rails/matchers/active_job.rb @@ -16,7 +16,7 @@ def initialize @queue = nil @at = nil @block = Proc.new {} - set_expected_number(:exactly, 1) + set_expected_number(:at_least, 1) end def with(*args, &block) diff --git a/spec/rspec/rails/matchers/active_job_spec.rb b/spec/rspec/rails/matchers/active_job_spec.rb index e9255add1e..34d807d3c1 100644 --- a/spec/rspec/rails/matchers/active_job_spec.rb +++ b/spec/rspec/rails/matchers/active_job_spec.rb @@ -94,7 +94,7 @@ def self.name; "LoggingJob"; end it "fails when job is not enqueued" do expect { expect { }.to have_enqueued_job - }.to raise_error(/expected to enqueue exactly 1 jobs, but enqueued 0/) + }.to raise_error(/expected to enqueue at least 1 jobs, but enqueued 0/) end it "fails when too many jobs enqueued" do @@ -116,7 +116,16 @@ def self.name; "LoggingJob"; end it "fails when negated and job is enqueued" do expect { expect { heavy_lifting_job.perform_later }.not_to have_enqueued_job - }.to raise_error(/expected not to enqueue exactly 1 jobs, but enqueued 1/) + }.to raise_error(/expected not to enqueue at least 1 jobs, but enqueued 1/) + end + + it "fails when negated and job is enqueued more than one time" do + expect { + expect { + heavy_lifting_job.perform_later + heavy_lifting_job.perform_later + }.not_to have_enqueued_job + }.to raise_error(/expected not to enqueue at least 1 jobs, but enqueued 2/) end it "passes with job name" do @@ -306,7 +315,7 @@ def self.name; "LoggingJob"; end it "fails when job is not enqueued" do expect { expect(heavy_lifting_job).to have_been_enqueued - }.to raise_error(/expected to enqueue exactly 1 jobs, but enqueued 0/) + }.to raise_error(/expected to enqueue at least 1 jobs, but enqueued 0/) end end end