Fix 3-0-stable to work with Mocha >= v0.13.0 #8872

merged 1 commit into from Jan 16, 2013


None yet

4 participants


Backport of #8200. The equivalent of 17ccefc by @carlosantoniodasilva would fix Mocha deprecation warnings in Rails tests.

@rafaelfranca rafaelfranca and 2 others commented on an outdated diff Jan 14, 2013
@@ -16,7 +16,9 @@
module ActiveSupport
- class TestCase < ::Test::Unit::TestCase
+ test_library = defined?(MiniTest) ? ::MiniTest : ::Test
+ class TestCase < test_library::Unit::TestCase
rafaelfranca Jan 14, 2013 Member

Why do we need this change?

floehopper Jan 14, 2013 Contributor

Without this change it is not possible to use the MiniTest gem in a Rails app with Mocha in Ruby v1.8. There may even be problems just using the MiniTest gem in a Rails app in Ruby v1.8, irrespective of whether Mocha is used, although I haven't had a chance to investigate that any further. For a fuller explanation see the relevant commit note.

floehopper Jan 14, 2013 Contributor

Note that the same fix has already been merged into 3-2-stable.

carlosantoniodasilva Jan 14, 2013 Member

Sorry, this has been reverted later in 267fb61 because it caused too many inconsistencies in the test suite, making tests fail.

floehopper Jan 14, 2013 Contributor

Note that I've added a pull request for 3-2-stable that solves the same problem in a different way. If that's acceptable, it could be back-ported to 3-1-stable and 3-0-stable.


I will remove ce6395560c5434f1ab989c42acab1338fb8173f3 from this pull request. Do you also want me to squash the commits into a single commit as per @parndt's request over in the equivalent pull request (#8871) for 3-1-stable? Personally I'd prefer to keep them separate, but if it increases the chance of the changes getting merged, I will do it.


Since it is a stable branch that we don't maintain anymore I prefer to merge they squashed.

@floehopper floehopper Fix 3-0-stable to work with Mocha >= v0.13.0
A) Update code in ActiveSupport which monkey-patches Test::Unit to
include Mocha bug fix.

A bug was fixed [1] in Mocha's integration with Test::Unit, but this
monkey-patching code was copied before the fix. We need to copy the
fixed version.

The bug meant that an unexpected invocation against a mock within the
teardown method caused a test *error* and not a test *failure*.

B) Fix for Test::Unit/Mocha compatibility.

Mocha is now using a single AssertionCounter which needs a reference to
the testcase as opposed to the result.

This change is an unfortunate consequence of the copying of a chunk of
Mocha's internal code in order to monkey-patch Test::Unit.

C) Avoid a Mocha deprecation warning.

commit 0591f6d 1 parent 8b3109a

As planned, I've removed the commit mentioned above and squashed the remaining 3 commits into 1. I've also rebased against 3-0-stable.

@rafaelfranca rafaelfranca merged commit d116e90 into rails:3-0-stable Jan 16, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment