【问题标题】:Resque job not being queued according to resque_spec but is available in job listResque 作业未根据 resque_spec 排队,但在作业列表中可用
【发布时间】:2014-08-26 16:35:26
【问题描述】:

我在 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

puts 语句打印出以下内容:

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

它没有达到最终的期望。关于我哪里出错的任何想法或建议?

谢谢

【问题讨论】:

  • 您能否分享失败的详细信息(结果与预期值的对比)以及您如何将工作排入post :run?试图将其与github.com/leshill/resque_spec/blob/master/spec/resque_spec/… 中的已知用途相匹配
  • 我已经由一位朋友解决了这个问题,他指出应该是:expect(ReportMapWorker).to have_queued(report.id.to_s).in(:default_queue)

标签: ruby rspec resque


【解决方案1】:

错误是 id 作为字符串添加到队列中,因此当期望在队列中期望 [1537] 时,它应该期望 ["1537"]。将代码断言更新为:

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

成功了,期望通过了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-28
    • 2012-05-11
    • 2012-08-22
    • 2012-10-18
    • 1970-01-01
    相关资源
    最近更新 更多