niku -E:)
2010-Dec-17 14:12 UTC
[rspec-users] [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 http://gist.github.com/744935 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.
David Chelimsky
2010-Dec-17 15:44 UTC
[rspec-users] [Mock]How do I check order of method argument ?
On Dec 17, 2010, at 8:12 AM, niku -E:) wrote:> Hello. > My name is niku. > > I''m using rspec 2.2.1 > > /tmp% rspec --version > 2.2.1 > > I tested http://gist.github.com/744935 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.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> > How do I check order of argument ? > > regards. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
niku -E:)
2010-Dec-18 03:19 UTC
[rspec-users] [Mock]How do I check order of method argument ?
Hello. My question was solved by David''s answer. Thank you David! On Sat, Dec 18, 2010 at 12:44 AM, David Chelimsky <dchelimsky at gmail.com> wrote:> > On Dec 17, 2010, at 8:12 AM, niku -E:) wrote: > >> Hello. >> My name is niku. >> >> I''m using rspec 2.2.1 >> >> /tmp% rspec --version >> 2.2.1 >> >> I tested http://gist.github.com/744935 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. > > > 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 > > > >> >> How do I check order of argument ? >> >> regards. >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
Pat Maddox
2010-Dec-18 12:01 UTC
[rspec-users] [Mock]How do I check order of method argument ?
mock.should_receive(:write).with("\n").ordered Append .ordered as above On Dec 17, 2010, at 6:12 AM, "niku -E:)" <niku at niku.name> wrote:> Hello. > My name is niku. > > I''m using rspec 2.2.1 > > /tmp% rspec --version > 2.2.1 > > I tested http://gist.github.com/744935 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. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20101218/2de56348/attachment-0001.html>