On 02/01/07, <b class="gmail_sendername">Jay</b> &lt;<a href="mailto:jay@jayfields.com">jay@jayfields.com</a>&gt; 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;">
On my current project I needed to create a stub that responded<br>correctly to the id message.&nbsp;&nbsp;Here&#39;s the change I put into my copy of<br>head.<br><br>Index: lib/mocha/mock_methods.rb<br>===================================================================
<br>--- lib/mocha/mock_methods.rb&nbsp;&nbsp; (revision 1114)<br>+++ lib/mocha/mock_methods.rb&nbsp;&nbsp; (working copy)<br>@@ -68,6 +68,7 @@<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; method_names = method_names.is_a?(Hash) ? method_names :<br>{ method_names =&gt; nil }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; method_names.each do |method_name, return_value|<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; expectations &lt;&lt; Stub.new(self, method_name,<br>backtrace).returns(return_value)<br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.metaclass.send :undef_method, method_name if<br>self.metaclass.method_defined?
 method_name<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; expectations.last<br>&nbsp;&nbsp;&nbsp;&nbsp; end<br><br>Index: test/mocha/auto_verify_test.rb<br>===================================================================<br>--- test/mocha/auto_verify_test.rb&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(revision 1114)
<br>+++ test/mocha/auto_verify_test.rb&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(working copy)<br>@@ -155,6 +155,11 @@<br>&nbsp;&nbsp;&nbsp;&nbsp; assert_equal &#39;named_stub&#39;, stub.__mock_name<br>&nbsp;&nbsp; end<br><br>+&nbsp;&nbsp;def test_stub_should_respond_to_already_defined_method<br>
+&nbsp;&nbsp;&nbsp;&nbsp;stub = test_case.stub(:id=&gt;&quot;id&quot;)<br>+&nbsp;&nbsp;&nbsp;&nbsp;assert_equal &quot;id&quot;, <a href="http://stub.id">stub.id</a><br>+&nbsp;&nbsp;end<br>+<br>&nbsp;&nbsp; def test_should_create_greedy_stub_with_name<br>&nbsp;&nbsp;&nbsp;&nbsp; greedy_stub = test_case.stub_everything(&#39;named_greedy_stub&#39;)
<br>&nbsp;&nbsp;&nbsp;&nbsp; assert_equal &#39;named_greedy_stub&#39;, greedy_stub.__mock_name</blockquote><div><br>Thanks for the patch. This has been on the todo list for quite some time.<br><br>Your solution works fine for some methods (e.g
. id), but not for methods that Mocha currently relies on (e.g. inspect).<br></div></div><br>I have been working on a more generic solution which I hope to commit shortly.<br clear="all"><br>-- <br>James.<br><a href="http://blog.floehopper.org">
http://blog.floehopper.org</a>