From 716bdfc01d45a61d211dbd766f494cb984fc9f9c Mon Sep 17 00:00:00 2001 From: James Mead Date: Sun, 26 Aug 2012 16:32:47 +0100 Subject: Copy 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*. [1] https://github.com/freerange/mocha/commit/f1ff6475ca2871f2977ab84cabbbfe2adadbbee6#diff-5 --- activesupport/lib/active_support/testing/setup_and_teardown.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/testing/setup_and_teardown.rb b/activesupport/lib/active_support/testing/setup_and_teardown.rb index f2268d1767..0a78442f17 100644 --- a/activesupport/lib/active_support/testing/setup_and_teardown.rb +++ b/activesupport/lib/active_support/testing/setup_and_teardown.rb @@ -83,6 +83,8 @@ module ActiveSupport begin teardown run_callbacks :teardown + rescue Mocha::ExpectationError => e + add_failure(e.message, e.backtrace) rescue Test::Unit::AssertionFailedError => e add_failure(e.message, e.backtrace) rescue Exception => e -- cgit v1.2.3 From c3e186ec8dcb2ec26d5d56f3e89123b1350c4a6f Mon Sep 17 00:00:00 2001 From: James Mead Date: Sun, 26 Aug 2012 17:45:26 +0100 Subject: 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. --- activesupport/lib/active_support/test_case.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/test_case.rb b/activesupport/lib/active_support/test_case.rb index 8d6c27e381..8f75cf98f4 100644 --- a/activesupport/lib/active_support/test_case.rb +++ b/activesupport/lib/active_support/test_case.rb @@ -9,7 +9,9 @@ require 'active_support/testing/mochaing' 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 -- cgit v1.2.3 From 5573c1d29565f17aca48b6a320a676bf9f962f20 Mon Sep 17 00:00:00 2001 From: James Mead Date: Mon, 27 Aug 2012 14:16:34 +0100 Subject: 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. --- activesupport/lib/active_support/testing/setup_and_teardown.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/testing/setup_and_teardown.rb b/activesupport/lib/active_support/testing/setup_and_teardown.rb index 0a78442f17..d21511d4db 100644 --- a/activesupport/lib/active_support/testing/setup_and_teardown.rb +++ b/activesupport/lib/active_support/testing/setup_and_teardown.rb @@ -61,7 +61,7 @@ module ActiveSupport def run(result) return if @method_name.to_s == "default_test" - mocha_counter = retrieve_mocha_counter(result) + mocha_counter = retrieve_mocha_counter(self, result) yield(Test::Unit::TestCase::STARTED, name) @_result = result @@ -102,14 +102,16 @@ module ActiveSupport protected - def retrieve_mocha_counter(result) #:nodoc: + def retrieve_mocha_counter(test_case, result) #:nodoc: if respond_to?(:mocha_verify) # using mocha if defined?(Mocha::TestCaseAdapter::AssertionCounter) Mocha::TestCaseAdapter::AssertionCounter.new(result) elsif defined?(Mocha::Integration::TestUnit::AssertionCounter) Mocha::Integration::TestUnit::AssertionCounter.new(result) - else + elsif defined?(Mocha::MonkeyPatching::TestUnit::AssertionCounter) Mocha::MonkeyPatching::TestUnit::AssertionCounter.new(result) + else + Mocha::Integration::AssertionCounter.new(test_case) end end end -- cgit v1.2.3 From 3791cac8747b5e36fe9619301a55d69f8feff982 Mon Sep 17 00:00:00 2001 From: James Mead Date: Sat, 3 Nov 2012 17:53:35 +0000 Subject: Avoid a Mocha deprecation warning. --- activesupport/lib/active_support/testing/mochaing.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/testing/mochaing.rb b/activesupport/lib/active_support/testing/mochaing.rb index 4ad75a6681..0161476d79 100644 --- a/activesupport/lib/active_support/testing/mochaing.rb +++ b/activesupport/lib/active_support/testing/mochaing.rb @@ -1,5 +1,5 @@ begin - silence_warnings { require 'mocha' } + silence_warnings { require 'mocha/setup' } rescue LoadError # Fake Mocha::ExpectationError so we can rescue it in #run. Bleh. Object.const_set :Mocha, Module.new -- cgit v1.2.3