我尝试在rspec中测试此方法:
def resend_if_failed
ResendWorker.new(self).resend_message
end
如何测试ResendWorker.new(self).resend_message
被执行?
答案 0 :(得分:2)
如果你的规范中有实例,你可以这样做:
expect(instance).to receive(:resend_if_failed)
instance.resend_if_failed
显然我猜resend_if_failed
是由另一种方法触发的。
然后,如有必要,单独测试resend_if_failed
行为。
答案 1 :(得分:1)
worker = double
allow(ResendWorker).to receive(:new).and_return(worker)
expect(worker).to receive(:resend_message)
instance.resend_if_failed