RSpec should_receive macro that includes id of what needs to be tested

本秂侑毒 提交于 2019-12-07 18:06:55

问题


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)

回答1:


How about this?

Mailer.should_receive(:email).with(an_instance_of(Fixnum), @sender.id, @receiver.id).and_return(mailer)


来源:https://stackoverflow.com/questions/7397177/rspec-should-receive-macro-that-includes-id-of-what-needs-to-be-tested

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!