wspurgin / rspec-sidekiq

RSpec for Sidekiq
https://github.com/wspurgin/rspec-sidekiq
Other
662 stars 133 forks source link

Is there a way to use have_enqueued_job but only check the first argument? #98

Closed axelson closed 8 years ago

axelson commented 8 years ago

Is there a way to use have_enqueued_job but only check the first argument? My use case is that for testing purposes it is only relevant to check the first argument, since the second argument is a detailed object hash that will change often in the future, thus making the test fragile.

wpolicarpo commented 8 years ago

@axelson can you provide us a more detailed use case, maybe an example?

xtagon commented 8 years ago

I have a similar situation where one parameter of my job is a DateTime that could be anything. In my spec I can't test that it has been enqueued because that param is not known in the setup and not easily stubbed.

In fact I don't even care about testing the datetime, but the result is that I can't test that the job has been enqueued at all.

packrat386 commented 8 years ago

You could try passing the anything matcher in RSpec for that argument. Something like expect(worker_class).to have_enqueued_job(anything, known_argument)

xtagon commented 8 years ago

@packrat386 Just tested. Worked like a charm! Would you happen to know where I can find anything in the RSpec docs? I think there are more wildcard-like argument matchers but I'm not sure where to look.

xtagon commented 8 years ago

Found it! http://www.rubydoc.info/gems/rspec-mocks/RSpec/Mocks/ArgumentMatchers

axelson commented 8 years ago

@packrat386 Thanks! That sounds like it'll work perfectly.

VStetsyshyn commented 1 year ago

@packrat386 thank you from 2023 :D