Skip to content

Negative matcher should be failed if have_enqueued_job have 1 or more jobs #1973

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/rspec/rails/matchers/active_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 12 additions & 3 deletions spec/rspec/rails/matchers/active_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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