RSpec should_receive宏包含需要测试的内容的id

时间:2011-09-13 05:21:37

标签: ruby-on-rails ruby ruby-on-rails-3 rspec rspec2

如何写这个,以便在没有硬编码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)

1 个答案:

答案 0 :(得分:4)

这个怎么样?

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