Post

Active Jobが失敗した場合のリトライについてテストする

解決

described_class.perform_later rescue nil

RSpec.describe MyJob, type: :job do include ActiveJob::TestHelper context 'when `MyError` is raised' do before do allow_any_instance_of(described_class).to receive(:perform).and_raise(MyError.new) end it 'makes 4 attempts' do assert_performed_jobs 4 do described_class.perform_later rescue nil end end it 'does something in the `retry_on` block' do expect(Something).to receive(:something) perform_enqueued_jobs do described_class.perform_later rescue nil end end end end
perform_nowでは再実施は発生しないよう

疑問

rescue nil を付与しなくても動きそう?

ruby on rails - How to properly test ActiveJob’s retry_on method with rspec? - Stack Overflow

This post is licensed under CC BY 4.0 by the author.