当我想要实际执行该方法时,如何处理rspec should_receive替换方法?

时间:2014-01-28 17:15:33

标签: rspec expectations

我是新手使用rspec should_receive并且遇到很多问题因为它“替换”了这个方法。例如:

UserMailer.should_receive(:new_order).with(order) 

为nil提供未定义的方法`deliver':NilClass,因为rspec使该方法停止工作。我该如何处理?

1 个答案:

答案 0 :(得分:2)

您可以通过将.and_call_original添加到方法链中来解决此问题,如下所示:

UserMailer.should_receive(:new_order).with(order).and_call_original

https://www.relishapp.com/rspec/rspec-mocks/v/2-13/docs/message-expectations/calling-the-original-method中记录并在Is there a less intrusive alternative to Rspec's `should_receive`?

中讨论过