关于 ruby?? on rails:RSpec should_receive 宏,包含需要测试的 id
RSpec should_receive macro that includes id of what needs to be tested
我怎样才能写出这样它才能通过而不用硬编码1。鸡和蛋。
|
1
2 3 4 5 6 7 8 9 |
@sender = Factory(:user)
@receiver = Factory(:user) mailer = double # This will create an object with id #1 to make this test pass |
相关讨论
- 我认为 rspec 使用 should-matchers 来验证 \'should_receive\' 上的预期参数,否则任何东西()之类的东西都不起作用?我的想法是编写一个自己的参数匹配器,它与数据库中的第一个 id 匹配。
- 虽然这仍然是一个抽象的问题,但我在我的具体问题中解决了它。我在 test.rb 中打开了投递,并正在使用 ActionMailer::Base.deliveries 来测试邮件。
这个怎么样?
|
1
|
Mailer.should_receive(:email).with(an_instance_of(Fixnum), @sender.id, @receiver.id).and_return(mailer)
|
THE END
二维码