1

I'm new to using rspec should_receive and having a lot of problems because it "replaces" the method. For example:

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

gives undefined method `deliver' for nil:NilClass, since rspec makes the method stop working. How do I deal with this?

pixelearth
  • 13,674
  • 10
  • 62
  • 110

1 Answers1

2

You deal with this by adding .and_call_original to your method chain as follows:

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

as documented in https://www.relishapp.com/rspec/rspec-mocks/v/2-13/docs/message-expectations/calling-the-original-method and discussed in Is there a less intrusive alternative to Rspec's `should_receive`?

Community
  • 1
  • 1
Peter Alfvin
  • 28,599
  • 8
  • 68
  • 106