RSpec should_receive 宏,包含需要测试的内容的 id
我该如何编写它,以便它在不进行硬编码 1
的情况下通过。先有鸡还是先有蛋。
@sender = Factory(:user)
@receiver = Factory(:user)
mailer = double
mailer.should_receive(:deliver)
Mailer.should_receive(:email).with(1, @sender.id, @receiver.id).and_return(mailer)
# This will create an object with id #1 to make this test pass
@object = Object.create(:sender => @sender, :receiver => @receiver)
How can I write this so it passes without hardcoding 1
. Chicken and the egg.
@sender = Factory(:user)
@receiver = Factory(:user)
mailer = double
mailer.should_receive(:deliver)
Mailer.should_receive(:email).with(1, @sender.id, @receiver.id).and_return(mailer)
# This will create an object with id #1 to make this test pass
@object = Object.create(:sender => @sender, :receiver => @receiver)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这个怎么样?
How about this?