Skip to content

Change negated active job matcher, fixes #1870 #2069

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

Merged
merged 1 commit into from
Jan 15, 2019

Conversation

Istanful
Copy link
Contributor

@Istanful Istanful commented Jan 15, 2019

Change negated active job matcher, fixes #1870

When using the active job matchers, they will default to expecting a job to be enqueued exactly once. This results in some non intuitional behaviour, when using the negated matcher.

Consider the following example:

expect {
  heavy_lifting_job.perform_later
  heavy_lifting_job.perform_later
}.not_to have_enqueued_job

Some would read this as "When enqueuing two heavy lifting jobs I expect no jobs to have been enqueued". Since two jobs are actually enqueued it should fail, which it previously would not.

This pull request fixes this issue by setting the default expectation to use "at least once" when using the negated matcher.

When expecting no job to be enqueued, the matcher would expect exactly
one job not to have been enqueued. This commit changes so that it now expects
no jobs to have been enqueued.
@JonRowe
Copy link
Member

JonRowe commented Jan 15, 2019

Thanks!

@JonRowe JonRowe mentioned this pull request Jan 15, 2019
8 tasks
JonRowe added a commit that referenced this pull request Jan 15, 2019
benoittgt pushed a commit to benoittgt/rspec-rails that referenced this pull request Jan 17, 2019
This is a partial backport of rspec#2069 that doesn't include changes on
"have_enqueued_mail" tests.

When expecting no job to be enqueued, the matcher would expect exactly
one job not to have been enqueued. This commit changes so that it now expects
no jobs to have been enqueued.
sebjacobs pushed a commit to futurelearn/rspec-rails that referenced this pull request Mar 15, 2019
This is a partial backport of rspec#2069 that doesn't include changes on
"have_enqueued_mail" tests.

When expecting no job to be enqueued, the matcher would expect exactly
one job not to have been enqueued. This commit changes so that it now expects
no jobs to have been enqueued.
benoittgt pushed a commit to benoittgt/rspec-rails that referenced this pull request May 1, 2019
When expecting no job to be enqueued, the matcher would expect exactly
one job not to have been enqueued. This commit changes so that it now expects
no jobs to have been enqueued.
benoittgt pushed a commit to benoittgt/rspec-rails that referenced this pull request May 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Negative have_enqueued_job does not work as expected with multiple jobs of same kind
2 participants