On 25/10/06, <b class="gmail_sendername">Francois Beausoleil</b> <<a href="mailto:francois.beausoleil@gmail.com">francois.beausoleil@gmail.com</a>> wrote:<div><span class="gmail_quote"></span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Running this:<br>@payout = stub_everything(:id => 141)<br>Payout.stubs(:find).with(@<a href="http://payout.id">payout.id</a>).returns(@payout)<br><br>Generates this warning:<br>./test/functional/payouts_controller_test.rb:22: warning: Object#id
<br>will be deprecated; use Object#object_id<br><br>What am I missing ? :id is a fairly frequent method to override in<br>Rails-based applications.<br><br>I'm using Mocha from svn://rubyforge.org/var/svn/mocha/trunk @ r70.
<br></blockquote></div><br clear="all">On 25/10/06, Francois Beausoleil <<a href="mailto:francois.beausoleil@gmail.com">francois.beausoleil@gmail.com</a>> wrote:<br><br> Running this:<br> @payout = stub_everything(:id => 141)
<br> Payout.stubs(:find).with(@<a href="http://payout.id">payout.id</a>).returns(@payout)<br><br> Generates this warning:<br> ./test/functional/payouts_controller_test.rb:22: warning: Object#id<br> will be deprecated; use Object#object_id
<br><br> What am I missing ? :id is a fairly frequent method to override in<br> Rails-based applications.<br><br> I'm using Mocha from svn://rubyforge.org/var/svn/mocha/trunk @ r70.<br><br><br>Hi Francois,<br><br>
The reason you get this warning is that the mock object (@payout) inherits Object methods like Object#id.This means that calls to @<a href="http://payout.id">payout.id</a> are dispatched to the Object#id implementation and not to Mock#method_missing which is what would normally return the stub result. You will see the same warning if you do...
<br><br>irb(main):001:0> <a href="http://Object.new.id">Object.new.id</a><br>(irb):1: warning: Object#id will be deprecated; use Object#object_id<br>=> 179090<br><br>The reason Mock inherits from Object is that many of these methods can be useful
e.g. asserting that two references to mock objects are the same requires the #eql? method.<br><br>I have been working on implementing a way of having a BlankSlate-type mock, but am a bit undecided about the API. So far I have blank_mock() and blank_stub() equivalents of mock() and stub(). But I haven't had any time to spare for work on Mocha recently. Sorry.
<br><br>To be honest we haven't run into this problem much at Reevoo. In your example above, what's wrong with doing this instead...?<br><br>@payout = stub_everything()<br>Payout.stubs(:find).with(141).returns(@payout)<br>
<br>or...<br><br>@payout = Payout.new { |payout| <a href="http://payout.id">payout.id</a> = 141 }<br>Payout.stubs(:find).with(@<a href="http://payout.id">payout.id</a>).returns(@payout)<br><br>One other comment I would make, is that I rarely use the with() method with a stubs() call. If it is important that the find() method is called with a particular value, I would use expects() like this...
<br><br>Payout.expects(:find).with(@<a href="http://payout.id">payout.id</a>).returns(@payout)<br><br>...on the other hand if the actual value is unimportant, I would use stubs() without with()...<br><br>Payout.stubs(:find).returns(@payout)
<br><br>Can you explain any more about what you are trying to test?<br><br>By the way, many thanks for your work on the Piston project.<br>-- <br>James.<br><a href="http://blog.floehopper.org">http://blog.floehopper.org</a>
<br>-- <br>James.<br><a href="http://blog.floehopper.org">http://blog.floehopper.org</a>