gocardless / rspec-que

RSpec matchers for testing Que
MIT License
1 stars 1 forks source link

Confusing behaviour with negative expectations #17

Open matthieuprat opened 5 years ago

matthieuprat commented 5 years ago

I stumbled upon an arguably surprising behavior on how queue_up behaves with negative expectations:

expect {
  2.times { FooJob.enqueue }
}.not_to queue_up(FooJob)

I would have assumed that this expectation would fail—but it doesn't. (I presume this is because the queue_up matcher returns true if one and only one job matches.)

Is this by design or shall we fix it?

matthieuprat commented 5 years ago

FWIW, RSpec Rails exhibits the "right" behavior (IMO, at least). So, for instance, this expectation would fail:

expect {
  2.times { FooJob.perform_later }
}.not_to have_enqueued_job(FooJob)

They achieve this by implementing RSpec::Matchers::MatcherProtocol#does_not_match?. This is nice because it preserves the "exactly once" default when using expect(...).to have_enqueued_job.