[Mock]How do I check order of method argument?

Hello.
My name is niku.

I’m using rspec 2.2.1

/tmp% rspec --version
2.2.1

I tested fixed_stdout_spec.rb · GitHub and passed.

/tmp% rspec stdout_spec.rb

Finished in 0.00105 seconds
2 examples, 0 failures

But I expected test fail.
Because It’s wrong order that argument of ‘write’ method.

How do I check order of argument ?

regards.

On Dec 17, 2010, at 8:12 AM, niku -E:) wrote:

/tmp% rspec stdout_spec.rb

Finished in 0.00105 seconds
2 examples, 0 failures

But I expected test fail.
Because It’s wrong order that argument of ‘write’ method.

Message expectations are not constrained by order unless you explicitly
tell them to be. This is documented for rspec-1 here:
http://rspec.info/documentation/mocks/message_expectations.html. The
docs for rspec-mocks-2 don’t have this yet, but will soon.

Basically, do this instead.

it “puts ‘foo’ and ‘bar’” do
mock = double(“stdout”)
mock.should_receive(:write).with(“\n”).ordered
mock.should_receive(:write).with(“\n”).ordered
mock.should_receive(:write).with(“foo”).ordered
mock.should_receive(:write).with(“bar”).ordered
$stdout = mock

puts "foo"
puts "bar"

end

HTH,
David

Hello.

My question was solved by David’s answer.

Thank you David!

mock.should_receive(:write).with("\n").ordered

Append .ordered as above