[英]ActiveJob Rspec Test failing
I have the following Rspec test for an ActiveJob:我对 ActiveJob 进行了以下 Rspec 测试:
require 'rails_helper'
RSpec.describe ProofreadDocumentReportJob, type: :job do
before do
ActiveJob::Base.queue_adapter = :test
end
subject(:job) { described_class.perform_later(create(:report)) }
it 'queues the job' do
expect { job }
.to have_enqueued_job
end
end
This tests fails with the following message:此测试失败并显示以下消息:
expected to enqueue exactly 1 jobs, but enqueued 2
However if I do write my tests as follows not using the subject job it passes:但是,如果我确实按如下方式编写我的测试而不使用它通过的主题作业:
it 'queues the job' do
expect { ProofreadDocumentReportJob.perform_later }
.to have_enqueued_job
end
Why does using the subject job not work?为什么使用主题作业不起作用?
an oldie but hey I ended up here in and google brought be here for: expected to enqueue exactly 1 jobs, but enqueued 2
一个老歌,但嘿,我最终来到这里,谷歌带来了这里:
expected to enqueue exactly 1 jobs, but enqueued 2
expect do
subject.run
end.to have_enqueued_job(DeliverWebhookJob).on_queue('webhooks').at_least(:twice)
end
Now onto OP:现在进入OP:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.