I would like to verify that delayed_job callbacks are called, but I don’t see how to get RSpec to do this, especially when multiple class layers are involved.
Assuming I have an ActiveRecord model:
class MyJob < ActiveRecord::Base
def perform
end
def after(job)
end
end
Conceptually, I need the RSpec test in these lines (although I know this is wrong):
it 'should call the :after callback hook' do
my_job = MyJob.create
my_job.should_receive(:after).with(an_instance_of(Delayed::Backend::ActiveRecord::Job))
Delayed::Job.enqueue(my_job)
Delayed::Worker.new.work_off
end
I looked at stackoverflow, relishapp.com/rspec and all the other places that I can think of. It can't be too hard, can it? (I bet @zetetic knows the answer in a dream ...;)
(Caution: in my actual case, the “strip” class is used between MyJob and DJ. The answer to this simple case may cause a more complicated continuation!)