I have a method like this:
def self.method
  #API CALL
end
And I was writing a test for the controller method that calls this static method. It is like this:
it 'update order to confirmed' do
    Order.should_receive(:process_payment).and_return({})
    sign_in user
    attributes = FactoryGirl.attributes_for(:order, :valid_order)
    patch :confirm_order, params: { id: order.id, order: attributes }
    order.reload
    expect(order.confirmed).to eq true
end
And it was working fine. But I had to make this method not static, and the test starts to fail.
In my controller, I am calling the method like this now:
Order.new.process_payment(@order)
The problem is with my mock I guess, but I cannot see how to solve it. Any ideas on how I can adapt my mock to this new format?
You can use allow_any_instance_of method:
allow_any_instance_of(Order).to receive(:process_payment).and_return({})
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With