Simplify code by taking advantage of latest mocha (v0.13.0). #8180

Merged
merged 1 commit into from Nov 13, 2012

2 participants

@floehopper

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.

@floehopper floehopper Simplify code by taking advantage of latest mocha (v0.13.0).
This only works with mocha v0.13.0 or later.

Note that this also fixes a few subtle 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`.
57b333e
@floehopper

The alternative pull request I mentioned above is this one.

@floehopper

I have also submitted a pull request for 3-2-stable so Rails v3.2 works with Mocha v0.13.0.

@carlosantoniodasilva
Ruby on Rails member

I think we're going to stick with support for Mocha >= 0.13.0 for now, thanks!

@carlosantoniodasilva carlosantoniodasilva merged commit 395d6b4 into rails:master Nov 13, 2012
@carlosantoniodasilva carlosantoniodasilva referenced this pull request Nov 13, 2012
Closed

Mocha fixes #8181

@floehopper

Great. That'd be my preferred option anyway!

I think that since require 'mocha/setup' will fail for earlier versions of Mocha, then no Mocha-related functionality will be available and it'll be pretty obvious that something is wrong.

@bobbus bobbus pushed a commit to bobbus/minitest-rails that referenced this pull request May 19, 2014
@floehopper floehopper Avoid deprecation warning in Mocha 0.13.0.
I'm not entirely sure why this code is duplicated from ActiveSupport,
but this deprecation warning has been fixed in 3-2-stable [1] and in
master [2].

[1] rails/rails#8200
[2] rails/rails#8180
b3aa657
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment