wspurgin / rspec-sidekiq

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

Matchers for scheduled jobs always pass #107

Closed jagthedrummer closed 7 years ago

jagthedrummer commented 8 years ago

I'm using the latest work in the develop branch by using this in my Gemfile:

gem 'rspec-sidekiq', :git => 'https://github.com/philostler/rspec-sidekiq.git', :branch => 'develop'

I'm queueing a job in the future like this:

AccountPermissionWorker.perform_at(2.days.from_now, self.id)

And I'm trying to make a test fail by doing:

expect(::AccountPermissionWorker).to have_enqueued_sidekiq_job(@account.id).at(4.days.from_now)

No matter what at time I test for the test always passes when it should fail.

Morred commented 8 years ago

Can confirm, the same happens for me.

wpolicarpo commented 8 years ago

I'm working on it @jagthedrummer and @Morred. We'll release a fix soon.

wpolicarpo commented 8 years ago

@jagthedrummer @Morred could you please point your Gemfile to #109 branch and give us some feedback on this issue?

jagthedrummer commented 8 years ago

@wpolicarpo I'll try to give this a look later tonight. Thanks for the work on it.

jagthedrummer commented 8 years ago

@wpolicarpo I can now get a spec to fail with the fix-scheduled-jobs-testing in my Gemfile, but the error messages are somewhat confusing.

With the example above when the tests fail I'm seeing this reported:

  1) Account start_premium_trial should queue the AccountPermissionWorker to run after the trial period is over
     Failure/Error: expect(::AccountPermissionWorker).to have_enqueued_sidekiq_job(@account.id).at(3.days.from_now)

       expected to have an enqueued AccountPermissionWorker job with arguments [4847]

       found: [[4847]]

It seems like it's just saying that the arguments are incorrect, when the real issue is that the value of at is incorrect. If I fix the time expectations so that they match the test passes.

I think that ideally if it found a job queued, but with a timestamp other than expected it would say something like:

expected to have a scheduled AccountPermissionWorker job with arguments [4847] at 2.days.from.now

found: [4847] at 4.days.from.now

Or maybe instead of showing something like 2.days.from.nowin the output it would just show timestamps that don't match. Or really anything else that would clue you in that it's a problem with the timing of the scheduled job vs expectations for the scheduled job instead of being some other problem with job arguments.

Anyway, thanks for the quick work on this! 😄

wpolicarpo commented 8 years ago

@jagthedrummer you're right. I'll see what can be done to make output better.