rails/rails — pull request #8180 by floehopper (2012-11-12 10:01:04+00:00)
Title: Simplify code by taking advantage of latest mocha (v0.13.0).

As well as simplifying the code considerably and reducing coupling to mocha, these changes also fix a few subtle mocha-related bugs present in the current implementation :-

* Mocha was raising a `MiniTest::Assertion` instead of a
`Mocha::ExpectationError` as intended. The latter is not recognized by
MiniTest as an assertion failure and so it is recorded as a test
*error*, not a test *failure* as it ought to. This leads to
potentially confusing output in the test results.

* Mocha verification should happen as part of the test. The verification
of expectations is equivalent to a set of assertions. These assertions
should happen as *part of* the test so that they have a chance to
cause the test to fail, and not just as part of the teardown. Also if
an assertion fails during the test, then there is no need to verify
expectations, because only the first assertion failure is normally
reported and all subsequent bets are off.

* Expectation verification should be counted as an assertion. Mocha
cannot record each expectation verification as an assertion, because
we weren't passing in an assertion counter to `#mocha_verify`.

These changes only work with mocha v0.13.0 or later. In case you would prefer to support older versions of mocha, I will submit an alternative pull request, however the code in that pull request will be necessarily more complicated/messy.

I'd be more than happy to provide back-ported fixes to 3-x-stable branches if these would be useful.