Skip to content
Browse files

Merge pull request #8871 from freerange/3-1-stable-with-mocha-fixes

Fix 3-1-stable to work with Mocha >= v0.13.0
  • Loading branch information...
2 parents 8b3109a + 0591f6d commit b0a2c67fbe23d278c4f5d02df14f76970847d999 @rafaelfranca rafaelfranca committed Jan 16, 2013
View
2 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
View
10 activesupport/lib/active_support/testing/setup_and_teardown.rb
@@ -61,7 +61,7 @@ module ForClassicTestUnit
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
@@ -83,6 +83,8 @@ def run(result)
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
@@ -100,12 +102,14 @@ def run(result)
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)
- else
+ elsif defined?(Mocha::Integration::TestUnit::AssertionCounter)
Mocha::Integration::TestUnit::AssertionCounter.new(result)
+ else
+ Mocha::Integration::AssertionCounter.new(test_case)
end
end
end

0 comments on commit b0a2c67

Please sign in to comment.
Something went wrong with that request. Please try again.