#controller file
def update
@payment = Payment.find_by(reference_id: params[:reference_id])
if @payment.update(update_params)
@payment.do_something
end
end
when trying to spec if do_something method was called, by
expect(@payment).to receive(:do_something)
it says
expected: 1 time with any arguments
received: 0 times with any arguments
do_something is in my Payment Class. It is actually being called, but rspec says not.
Any ideas? thanks in advance
Your @payment in specs is actually a totally different variable, which is part of specs class, not the controller. I may be wrong, but that is my assumption from the parts of code you post - add specs code for more info. As of the solution, may use 'stub any instance'
Payment.any_instance.stub(:do_something).and_return(:smthing)
A more complicated approach - using doubles