On 25/09/06, <b class="gmail_sendername">Chris Roos</b> <<a href="mailto:chrisjroos@gmail.com">chrisjroos@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;">
Hi James,<br><br>An instance retains its mocha between tests if that instance is<br>pointed to by a constant. 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__), "test_helper")<br><br>require 'stubba'<br><br>class WemStubbaTest < Test::Unit::TestCase<br><br> Arr = [1, 2, 3]<br><br> def test_a<br> Arr.stubs(:size).returns(6)<br> assert_equal 6,
Arr.size<br> end<br><br> def test_b<br> assert_equal 3, Arr.size #=> Failing test when both tests run consecutively<br> end<br><br>end<br><br>#--/code--<br><br>I got as far as noticing that Stubba::InstanceMethod#unstub is
<br>'intentionally empty'. This is fine for most object instances but not<br>ones that hang around (like the array above). 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 & #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>