rails/rails — pull request #8181 by floehopper (2012-11-12 10:02:17+00:00)
Title: Mocha fixes

These commits fix a number of subtle mocha-related bugs that have been present for a while :-

* 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`.

The code has unfortunately become relatively complicated to support different versions of mocha. If it is acceptable to only support the latest version of mocha (v0.13.0) onwards, I'd suggest it would be preferable to accept [this other pull request](https://github.com/rails/rails/pull/8180) which simplifies the code considerably.

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