On Sun, Jul 13, 2008 at 9:49 AM, Sven Fuchs <[EMAIL PROTECTED]> wrote:
> I've been wondering how to expect arbitrary methods being called in a
> particular order. The RSpec documentation for expecting method calls on mock
> objects mentions that it is possible to pass a block to #should_receive, but
> does not mention that it can be used to track the method call order pretty
> easily:
>
> http://www.artweb-design.de/2008/7/13/expecting-arbitrary-method-calls-in-a-particular-order-in-rspec
>
> Is there a better way of doing this?
>
> If not, do you think it would make sense to add this to the RSpec docs?
> http://rspec.info/documentation/mocks/message_expectations.html
Hey Sven,
Mock objects have an optional notion of ordering. Check out the following spec:
describe "a mock object" do
it "should expect ordered messages" do
foo = mock("ordered mock")
foo.should_receive(:first).ordered
foo.should_receive(:second).ordered
foo.should_receive(:third).ordered
foo.first
foo.second
foo.third
end
end
Changing the order in which they're called will raise an ExpectationNotMetError.
Pat
_______________________________________________
rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users