1

我不熟悉使用 rspec should_receive 并且遇到很多问题,因为它“替换”了该方法。例如:

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

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

4

1 回答 1

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 `应该接收?

于 2014-01-28T18:36:53.737 回答