I have the following code:
require_relative '../spec_helper'
describe PaymentProcessor do
before(:each) do
@processor = PaymentProcessor.new
end
describe '#process' do
context 'payment accepted, sha digest valid' do
it 'should return true and have no errors' do
GamePlayResult.stub(:new).and_return(mock('GamePlayResult'))
ticket = stub_model(Ticket, player: stub_model(Player, has_funds?: true))
Ticket.stub(:find).and_return ticket
game = stub_model(Game, play: ticket, tolerance: 10)
query = 'orderID=1060&STATUS=5&PAYID=17314217&NCERROR=0&SHASIGN=E969563B64ED6F93F5DC47A86B1B04DFC884B4A7'
@processor.process(query, game).should_not be_false
game.should_receive(:play)
@processor.error.should equal nil
end
end
end
end
All assertions other other than game.should_receive(:play) are being met. However i know that :play is being called, as a) the other assertions would fail if it wasnt and b) if I don’t stub it, I get a unexpected message error.
Thanks in advance.
You have to set your RSpec expectation before you call your code that will execute that expectation.
So this:
Should be changed to this: