Permalink
Browse files

Use MiniTest in Ruby 1.8 if it is available.

ActiveSupport::TestCase was always inheriting from Test::Unit::TestCase.
This works fine in Ruby 1.9 where Test::Unit::TestCase is a thin wrapper
around MiniTest::Unit::TestCase, but does not work in Ruby 1.8 if the
MiniTest gem is used. What happens is that ActiveSupport inherits from
the Test::Unit::TestCase provided by the standard library, but then
since Minitest is defined, it then seems to proceed on the assumption
that ActiveSupport::TestCase has MiniTest::Unit::TestCase in its
ancestor chain. However, in this case it does not.

The fix is simply to choose which test library TestCase to inherit from
using the same logic used elsewhere to detect MiniTest.

I noticed this bug causing issues when using MiniTest and Mocha
in Ruby 1.8, but there may well be other issues.
  • Loading branch information...
1 parent 716bdfc commit c3e186ec8dcb2ec26d5d56f3e89123b1350c4a6f @floehopper floehopper committed Aug 26, 2012
Showing with 3 additions and 1 deletion.
  1. +3 −1 activesupport/lib/active_support/test_case.rb
@@ -9,7 +9,9 @@
require 'active_support/core_ext/kernel/reporting'
module ActiveSupport
- class TestCase < ::Test::Unit::TestCase
+ test_library = defined?(MiniTest) ? ::MiniTest : ::Test
+
+ class TestCase < test_library::Unit::TestCase
if defined? MiniTest
Assertion = MiniTest::Assertion
alias_method :method_name, :name if method_defined? :name

0 comments on commit c3e186e

Please sign in to comment.