On 25/09/06, <b class="gmail_sendername">Chris Roos</b> &lt;<a href="mailto:chrisjroos@gmail.com">chrisjroos@gmail.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;">
Hi James,<br><br>An instance retains its mocha between tests if that instance is<br>pointed to by a constant.&nbsp;&nbsp;The simplest failing test is something like<br>(add as a new file in mocha/test)..<br><br>#--code--<br><br>require 
File.join(File.dirname(__FILE__), &quot;test_helper&quot;)<br><br>require 'stubba'<br><br>class WemStubbaTest &lt; Test::Unit::TestCase<br><br>&nbsp;&nbsp;Arr = [1, 2, 3]<br><br>&nbsp;&nbsp;def test_a<br>&nbsp;&nbsp;&nbsp;&nbsp;Arr.stubs(:size).returns(6)<br>&nbsp;&nbsp;&nbsp;&nbsp;assert_equal 6, 
Arr.size<br>&nbsp;&nbsp;end<br><br>&nbsp;&nbsp;def test_b<br>&nbsp;&nbsp;&nbsp;&nbsp;assert_equal 3, Arr.size #=&gt; Failing test when both tests run consecutively<br>&nbsp;&nbsp;end<br><br>end<br><br>#--/code--<br><br>I got as far as noticing that Stubba::InstanceMethod#unstub is
<br>'intentionally empty'.&nbsp;&nbsp;This is fine for most object instances but not<br>ones that hang around (like the array above).&nbsp;&nbsp;Sadly, I don't have (or<br>even know whether there should be) a fix.<br></blockquote></div><br>Hi Chris,
<br><br>I'm pretty sure the solution is just to make InstanceMethod even more
like ClassMethod in #stub &amp; #unstub. I think the difference was
only ever an optimization with the assumption that instances wouldn't
persist between tests.<br><br>However, I also wonder if this scenario is itself a code
smell i.e. I'm not sure anything should persist between tests - but
maybe your actual scenario involves a constant within an external class...?<br><br>I'll try to have a look at it soon.<br clear="all">Thanks.<br>-- <br>James.<br><a href="http://blog.floehopper.org">http://blog.floehopper.org
</a>