How do I deal with rspec should_receive replacing the method when I want the method to actually be executed?

StackOverflow https://stackoverflow.com/questions/21412305

  •  04-10-2022
  •  | 
  •  

Pergunta

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?

Foi útil?

Solução

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`?

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top