我有以下工人
class JobBlastingWorker
include Sidekiq::Worker
sidekiq_options queue: 'job_blasting_worker'
def perform(job_id, action=nil)
job = Job.find(job_id)
JobBlastingService.new(job).call
end
end
我也有以下job_blasting_service
class JobBlastingService
def initialize(job)
@job = job
end
def call
ScoringWorker.perform_async(@job.id, 0, 'create')
end
end
并且在scoring_worker
class ScoringWorker
include Sidekiq::Worker
sidekiq_options queue: 'scoring_worker'
def perform(job_id, version, action=nil)
job = Job.find(job_id)
job.version = version
job.save
end
end
现在我想编写一个 rspec 测试来验证发送到的参数ScoringWorker
是否准确。
require 'rails_helper'
describe JobBlastingWorker do
before(:all) do
Rails.cache.clear
end
describe 'perform' do
context 'create' do
it 'sends correct arguments for scoring worker' do
@job = create(:job)
expect(ScoringWorker).to receive(:perform_async).with(@job.id, 0, 'create').and_call_original
worker = JobBlastingWorker.new
expect(JobBlastingWorker).to receive(:perform_in)
expect(ScoringWorker).to receive(:perform_async).exactly(1).times
worker.perform(@job.id, 'create')
end
end
end
end
我有这个 rspec 测试,当我运行它时,我收到一个错误,因为它没有任何带有参数的 sidekiq 作业。
我怎样才能为它编写这个测试以获得所需的响应