目前,当我的代码中有一个延迟方法时,如下所示:
CommentMailer.delay.deliver_comments(@comment, true)
我在规范中写了这样的东西:
dj = mock("DelayProxy")
CommentMailer.should_receive(:delay).and_return(dj)
dj.should_receive(:deliver_comments).with(comment, true)
一般来说,有没有更好的方法来处理这个和/或类似 rSpec 中的链式方法?
最佳答案
我们可以在 before block 中再增加一行,如下所示:
CommentMailer.stub(:delay).and_return(CommentMailer)
然后您就可以进行正常的模拟检查,如下所示:
CommentMailer.should_receive(:deliver_comments).with(comment, true)
关于ruby-on-rails - 使用 rSpec 测试 delayed_job 链的最佳方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7030974/