Search code examples
rubyrspecresque

Resque job not being queued according to resque_spec but is available in job list


I have the following test in rspec

it "should add the item to the resque queue" do
    post :run, id: report.id
    resque_job = Resque.peek(:default_queue)
    expect(resque_job).to be_present
    puts "Job is #{resque_job}"
    expect(ReportMapWorker).to have_queue_size_of(1)
    expect(ReportMapWorker).to have_queued(report.id).in(:default_queue)
end

The puts statement prints out the following:

Job is [{"class"=>"ReportMapWorker", "args"=>["1537"]}]

It is failing on the final expectation. Any ideas or suggestions as to where I am going wrong?

Thanks


Solution

  • The error is that the id is being added to the queue as a string, so when the expectation is expecting [1537] on the queue it should be expecting ["1537"]. Updating the code assertion to:

    expect(ReportMapWorker).to have_queued(report.id.to_s).in(:default_queue)
    

    works and the expectation passes.