Skip to content
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

Remove default .once in singular matchers #2

Merged
merged 1 commit into from
May 3, 2023

Conversation

inkstak
Copy link
Owner

@inkstak inkstak commented May 2, 2023

The previous situation

Implicitely, both matchers enqueue_sidekiq_job and have_enqueued_sidekiq_job matched that exactly only one job was enqueued.

it "asserts that only job has been enqueued" do
  expect {
    SampleJob.perform_async
  }.to enqueue_sidekiq_job(SampleJob)
end

A plural (and undocumented) version of both matchers was available to not care about of how many jobs were enqueued.

it "asserts that at least one jobs has been enqueued" do
  expect {
    SampleJob.perform_async
    SampleJob.perform_async
  }.to enqueue_sidekiq_jobs(SampleJob)
end

The problem

Using this singular matcher may be confusing, especially when using negative assertions:

it "succeed, but it smells like a false positive" do
  expect {
    SampleJob.perform_async
    SampleJob.perform_async
  }.not_to enqueue_sidekiq_job(SampleJob)
end

The solution

The implicit .once option will be removed. Both singular and plural matchers are now aliased.
If you want to verify that only one and exactly only one job has been enqueued, you have to do it explicitely :

it do
  expect {
    SampleJob.perform_async
  }.to enqueue_sidekiq_job(SampleJob).once
end

it do
  expect {
    SampleJob.perform_async
    SampleJob.perform_async
  }.not_to enqueue_sidekiq_job(SampleJob).once
end

This solution should not break existing specs, except ambiguous negative assertions.

@inkstak inkstak force-pushed the feature-fix_singular_matchers branch 2 times, most recently from 14535b6 to 867b1f7 Compare May 2, 2023 19:30
@inkstak inkstak force-pushed the feature-fix_singular_matchers branch from 867b1f7 to 983d579 Compare May 3, 2023 10:04
@inkstak inkstak merged commit daa410e into main May 3, 2023
11 checks passed
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.

None yet

2 participants