floehopper/mocha — Issue #65: Setting an expectation on the same object in multiple tests fails
Author: pcarlisle
Created: 2012-02-04 01:16:55+00:00
State: open

If you set an expectation on the same class in two tests, it doesn't get set up properly the second time. This was broken in commit 3fbcad2da6906e80e8c91d659790748d9d9ee7ad. The issue appears to be that in the second test add_mock does not get called (because the mocha object is no longer cleaned up after the first test).

I've managed to write a failing acceptance test:

```ruby
require File.expand_path('../acceptance_test_helper', __FILE__)
require 'mocha'

module TestExpectTwice
def foo
1
end
end

class SequenceTest < Test::Unit::TestCase

include AcceptanceTest

def setup
setup_acceptance_test
end

def teardown
teardown_acceptance_test
end

def test_expect_should_work_twice_in_a_row
test1 = run_as_test do
TestExpectTwice.expects(:foo).never
end
assert_passed(test1)
test2 = run_as_test do
TestExpectTwice.expects(:foo)
end
assert_failed(test2)
end
end
```