rspec-sidekiq icon indicating copy to clipboard operation
rspec-sidekiq copied to clipboard

have_enqueued_job and Sidekiq::Testing.disabled!

Open Bartuz opened this issue 9 years ago • 1 comments

I'm running my specs with real Redis (via https://github.com/guilleiguaran/fakeredis), with Sidekiq::Testing.disable! and with this little hack to make thing working.

I think the problem is that have_enqueued_job doesn't look for jobs in Sidekiq::Queue object but rather Worker.jobs array. (it's my guess)

MyWorker.perform_async 'SuperAwesome'
=> "6983e6462239240363aa9280"

to ensure it's actually inside sidekiq queue I'll try:

Sidekiq::Queue.new('my que').to_a.first
=> #<Sidekiq::Job:0x007fb3ffdd4dd8
 @item=
  {"class"=>"MyWorker",
   "args"=>["SuperAwesome"],
   "queue"=>"my que",
   "jid"=>"6983e6462239240363aa9280",
   "created_at"=>1441896216.818053,
   "enqueued_at"=>1441896216.818154},
 @queue="leads",
 @value= ...

Now let's run matcher:

expect(MyWorker).to have_enqueued_job('SuperAwesome')
RSpec::Expectations::ExpectationNotMetError: expected to have an enqueued MyWorker job with arguments ["SuperAwesome"]

found: []

Bartuz avatar Sep 10 '15 14:09 Bartuz

I am having this exact same problem....

chrishough avatar Jun 20 '17 22:06 chrishough

The lib fully relies on the use of Sidekiq::Testing so I don't think rspec-sidekiq is intended to work in that kind of complete integration test scenario with a live (or fake live) Redis instance pushing real jobs.

wspurgin avatar Jul 27 '23 15:07 wspurgin