简体   繁体   English

ActiveJob Rspec 测试失败

[英]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

  • which below answers.下面的答案。
      expect do
        subject.run
      end.to have_enqueued_job(DeliverWebhookJob).on_queue('webhooks').at_least(:twice)
    end

Now onto OP:现在进入OP:

  • report factory it seems is implementing 2 jobs / that would be my attack vector to solving this quite old of questions.. and OP is most likely a ruby god by now.. report工厂似乎正在实施 2 个工作/这将是我解决这个相当古老的问题的攻击向量.. OP现在很可能是ruby神..

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM