I think that the approach @tenderlove has suggested to avoid monkey-patching MiniTest (and the way MiniTest works) means that to use Mocha with MiniTest, you would either need to include the Mocha integration module into every test case, or define your own test case class inheriting from MiniTest::Unit::TestCase.
This works well for Rails (i.e. ActiveSupport), because it already defines a new test case class (ActiveSupport::TestCase) which is a suitable place to include the Mocha integration module.
If we were to go down this route, in non-Rails Ruby projects you'd need to do one of the following...
class MyTestCase < MiniTest::Unit::TestCase
include Mocha::Integration::MiniTest
end
class TestCaseOne < MyTestCase
def test_foo
o = mock
o.expects(:foo)
end
end
class TestCaseTwo < MyTestCase
def test_bar
o = mock
mock.expects(:bar)
end
end class TestCaseOne < MiniTest::Unit::TestCase
include Mocha::Integration::MiniTest
def test_foo
o = mock
o.expects(:foo)
end
end
class TestCaseTwo < MiniTest::Unit::TestCase
include Mocha::Integration::MiniTest
def test_foo
o = mock
o.expects(:foo)
end
endThe explicit-ness and the lack of monkey-patching is clearly beneficial, but do you think the above options are too onerous compared to the current behaviour where MiniTest::Unit::TestCase itself is monkey-patched and you could simply do the following :-
require "minitest/unit"
require "mocha"
class TestCaseOne < MiniTest::Unit::TestCase
def test_foo
o = mock
o.expects(:foo)
end
end
class TestCaseTwo < MiniTest::Unit::TestCase
def test_foo
o = mock
o.expects(:foo)
end
end
Using Mocha with Rspec works like this :-
The configuration setting causes Rspec to require "mocha/standalone" and "mocha/object" which is the equivalent of require "mocha/api" and "mocha/object" which is in turn the equivalent of require "mocha_standalone".