使用rSpec 测试delayed_job 链的最佳方法是什么?
目前,当我的代码中有如下延迟方法时:
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 中那样的链式方法?
Currently when I have a delayed method in my code like the following:
CommentMailer.delay.deliver_comments(@comment, true)
I write something like this in my spec:
dj = mock("DelayProxy")
CommentMailer.should_receive(:delay).and_return(dj)
dj.should_receive(:deliver_comments).with(comment, true)
Is there a better way to handle this and/or chained methods like that in rSpec in general?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我们可以在 before 块中再添加一行,如下所示:
然后您就可以进行正常的模拟检查,如下所示:
We can just have one more line in the before block as following:
Then you then can have the normal mock check as following:
以下是一些关于 rSpec 中链接方法的讨论,我发现这些讨论很有帮助:
使用 Rspec 打桩链接方法
http://groups.google.com/group/rspec/browse_thread/thread/6b8394836d2390b0#
Here are some discussions about chaining methods in rSpec that I found helpful:
Stubbing Chained Methods with Rspec
http://groups.google.com/group/rspec/browse_thread/thread/6b8394836d2390b0#
将延迟作业设置为 false,您可以像简单一样测试它
Set delayed job as false and u can test it like simple