我对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
此测试失败,并显示以下消息:
expected to enqueue exactly 1 jobs, but enqueued 2
但是,如果我按照以下方式编写我的测试而不使用它通过的主题作业:
it 'queues the job' do
expect { ProofreadDocumentReportJob.perform_later }
.to have_enqueued_job
end
为什么使用主题作业不起作用?