Jar*_*red 12 ruby rspec ruby-on-rails delayed-job
目前我的代码中有一个延迟方法,如下所示:
CommentMailer.delay.deliver_comments(@comment, true)
Run Code Online (Sandbox Code Playgroud)
我在我的规范中写了这样的东西:
dj = mock("DelayProxy")
CommentMailer.should_receive(:delay).and_return(dj)
dj.should_receive(:deliver_comments).with(comment, true)
Run Code Online (Sandbox Code Playgroud)
是否有更好的方法来处理这种和/或链式方法,例如rSpec中的方法?
Anh*_*yen 27
我们可以在前面的块中再添加一行,如下所示:
CommentMailer.stub(:delay).and_return(CommentMailer)
Run Code Online (Sandbox Code Playgroud)
然后,您可以进行正常的模拟检查,如下所示:
CommentMailer.should_receive(:deliver_comments).with(comment, true)
Run Code Online (Sandbox Code Playgroud)
以下是一些关于 rSpec 中链接方法的讨论,我发现这些讨论很有帮助:
http://groups.google.com/group/rspec/browse_thread/thread/6b8394836d2390b0#