[mocha-developer] Problem stubbing instances referred to by constants

Chris Roos chrisjroos at gmail.com
Mon Sep 25 13:43:28 EDT 2006

Hi James,

An instance retains its mocha between tests if that instance is
pointed to by a constant.  The simplest failing test is something like
(add as a new file in mocha/test)..


require File.join(File.dirname(__FILE__), "test_helper")

require 'stubba'

class WemStubbaTest < Test::Unit::TestCase

  Arr = [1, 2, 3]

  def test_a
    assert_equal 6, Arr.size

  def test_b
    assert_equal 3, Arr.size #=> Failing test when both tests run consecutively



I got as far as noticing that Stubba::InstanceMethod#unstub is
'intentionally empty'.  This is fine for most object instances but not
ones that hang around (like the array above).  Sadly, I don't have (or
even know whether there should be) a fix.


More information about the mocha-developer mailing list