[rspec-users] checking order of method calls on different mocks

207 views
Skip to first unread message

Fregas

unread,
Jan 26, 2011, 11:07:31 AM1/26/11
to rspec...@rubyforge.org
I have a spec where I need to check that the order of 2 method calls
to 2 different mocks is correct:

mock_customer.should_receive(:save).ordered
mock_customer.should_recieve(:id).and_return(1).ordered
mock_order.should_receive(:customer_id=).with(1).ordered

however this does not work. I can set order.customer_id at the
beginning, before save and id are called and the spec passes.

_______________________________________________
rspec-users mailing list
rspec...@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

David Chelimsky

unread,
Jan 27, 2011, 10:20:32 PM1/27/11
to rspec-users
On Jan 26, 2011, at 10:07 AM, Fregas wrote:

> I have a spec where I need to check that the order of 2 method calls
> to 2 different mocks is correct:
>
> mock_customer.should_receive(:save).ordered
> mock_customer.should_recieve(:id).and_return(1).ordered

Don't think it's related, but receive is misspelled here ^^.

> mock_order.should_receive(:customer_id=).with(1).ordered
>
> however this does not work. I can set order.customer_id at the
> beginning, before save and id are called and the spec passes.

Ordering does not work across objects. Does this really need to happen in order? What's the real requirement you're trying to express (not how the code is doing it, but what's supposed to happen at a high level)?

Reply all
Reply to author
Forward
0 new messages