There’re two ways to test delayed jobs under RSpec.
The first is to use the library “as is”, invoking
Delayed::Worker.new.work_off and examining the job results.
Unfortunately, this requires a lot of extra work to reach exceptions generated inside the delayed job worker.
A second solution that immediately executes delayed jobs has the advantage of failing loudly, predictably, and inline within your tests.
spec/support/delayed_job.rb in your
This causes immediate execution of the job in the following code.
Delayed::Worker.delay_jobs can also be a
Proc. You may want to delay jobs that are scheduled in the future and immediately execute all other jobs. This is our default setup in Ruby projects at Artsy.
If you must turn off this behavior in a specific test, set