ActiveJob Rspec测试失败

时间:2018-03-09 07:29:50

标签: ruby-on-rails rspec-rails rails-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

此测试失败,并显示以下消息:

expected to enqueue exactly 1 jobs, but enqueued 2

但是,如果我按照以下方式编写我的测试而不使用它通过的主题作业:

  it 'queues the job' do
    expect { ProofreadDocumentReportJob.perform_later }
      .to have_enqueued_job
  end

为什么使用主题作业不起作用?

0 个答案:

没有答案