Forum: RSpec How do you mock an object to expect A then B then A?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
84c84653587de6fccb811e156b0d6039?d=identicon&s=25 Nigel Thorne (Guest)
on 2009-04-14 05:32
(Received via mailing list)
Hi Folks,

I want to assert on an order of interaction between two objects where
one
method gets repeated.

Here is a simple example...

# this fails "Mock 'x' expected :a with (any args) once, but received it
twice"

x = mock("x")
x.should_receive(:a).once.ordered
x.should_receive(:b).once.ordered
x.should_receive(:a).once.ordered

x.a
x.b
x.a


http://gist.github.com/94849

Am I setting up the ordered expectations incorrectly, or is this a bug?

Cheers
Nigel
8b227e7c37d5f8788dec0c2f91d88c5e?d=identicon&s=25 Nigel Thorne (Guest)
on 2009-04-14 05:34
(Received via mailing list)
Hi Folks,

I want to assert on an order of interaction between two objects where
one
method gets repeated.

Here is a simple example...

# this fails "Mock 'x' expected :a with (any args) once, but received it
twice"
x = mock("x")
x.should_receive(:a).once.ordered
x.should_receive(:b).once.ordered
x.should_receive(:a).once.ordered

x.a
x.b
x.a


http://gist.github.com/94849

Am I setting up the ordered expectations incorrectly, or is this a bug?

Cheers
Nigel
2837408ba0375c40b235f0a5a5107d37?d=identicon&s=25 Doug Livesey (biot023)
on 2009-04-14 11:31
(Received via mailing list)
Could be wrong, but what about removing the stipulation that each call
should be received once?
Is that superfluous to requirements, there? I think so.
You've already specified three calls in order, so that should cover it.

2009/4/14 Nigel Thorne <nigel.thorne@gmail.com>
84c84653587de6fccb811e156b0d6039?d=identicon&s=25 Nigel Thorne (Guest)
on 2009-04-15 01:21
(Received via mailing list)
In my case I need to specify this behaviour. (I'm making sure the
logging
happens in the right order).

I believe it really is a bug, so I have forked rspec (on github),
written a
failing test and fixed my version of rspec to handle this case.

My version now matches against unsatisfied expectations in preference to
satisfied ones.

I'm not sure what the next step is in contributing a patch back..I guess
I
raise a ticket in lighthouse.

2009/4/14 doug livesey <biot023@gmail.com>
2837408ba0375c40b235f0a5a5107d37?d=identicon&s=25 Doug Livesey (biot023)
on 2009-04-15 08:41
(Received via mailing list)
> I'm not sure what the next step is in contributing a patch back.
Me either, but I salute your go-to attitude & community-mindedness!

2009/4/15 Nigel Thorne <nigel@nigelthorne.com>
This topic is locked and can not be replied to.