0
@@ -3,30 +3,15 @@ require 'active_support/callbacks'
0
module SetupAndTeardown
0
- # For compatibility with Ruby < 1.8.6
0
- PASSTHROUGH_EXCEPTIONS =
0
- if defined?(Test::Unit::TestCase::PASSTHROUGH_EXCEPTIONS)
0
- Test::Unit::TestCase::PASSTHROUGH_EXCEPTIONS
0
- [NoMemoryError, SignalException, Interrupt, SystemExit]
0
def self.included(base)
0
include ActiveSupport::Callbacks
0
define_callbacks :setup, :teardown
0
- if defined?
(::MiniTest)0
- alias_method :run, :run_with_callbacks_and_mocha
0
- alias_method :run, :run_with_callbacks_and_testunit
0
+ include ForClassicTestUnit
0
@@ -50,74 +35,51 @@ module ActiveSupport
0
- # This redefinition is unfortunate but test/unit shows us no alternative.
0
- def run_with_callbacks_and_testunit(result) #:nodoc:
0
- return if @method_name.to_s == "default_test"
0
+ module ForClassicTestUnit
0
+ # For compatibility with Ruby < 1.8.6
0
+ PASSTHROUGH_EXCEPTIONS = Test::Unit::TestCase::PASSTHROUGH_EXCEPTIONS rescue [NoMemoryError, SignalException, Interrupt, SystemExit]
0
- yield(Test::Unit::TestCase::STARTED, name)
0
- __send__(@method_name)
0
- rescue Test::Unit::AssertionFailedError => e
0
- add_failure(e.message, e.backtrace)
0
- rescue *PASSTHROUGH_EXCEPTIONS
0
- run_callbacks :teardown, :enumerator => :reverse_each
0
- rescue Test::Unit::AssertionFailedError => e
0
- add_failure(e.message, e.backtrace)
0
- rescue *PASSTHROUGH_EXCEPTIONS
0
- yield(Test::Unit::TestCase::FINISHED, name)
0
+ # This redefinition is unfortunate but test/unit shows us no alternative.
0
+ # Doubly unfortunate: hax to support Mocha's hax.
0
+ return if @method_name.to_s == "default_test"
0
- # Doubly unfortunate: mocha does the same so we have to hax their hax.
0
- def run_with_callbacks_and_mocha(result)
0
- return if @method_name.to_s == "default_test"
0
+ if using_mocha = respond_to?(:mocha_verify)
0
+ assertion_counter = Mocha::TestCaseAdapter::AssertionCounter.new(result)
0
- assertion_counter = Mocha::TestCaseAdapter::AssertionCounter.new(result)
0
- yield(Test::Unit::TestCase::STARTED, name)
0
+ yield(Test::Unit::TestCase::STARTED, name)
0
- __send__(@method_name)
0
- mocha_verify(assertion_counter)
0
- rescue Mocha::ExpectationError => e
0
- add_failure(e.message, e.backtrace)
0
- rescue Test::Unit::AssertionFailedError => e
0
- add_failure(e.message, e.backtrace)
0
- raise if Test::Unit::TestCase::PASSTHROUGH_EXCEPTIONS.include? $!.class
0
- run_callbacks :teardown, :enumerator => :reverse_each
0
+ __send__(@method_name)
0
+ mocha_verify(assertion_counter) if using_mocha
0
+ rescue Mocha::ExpectationError => e
0
+ add_failure(e.message, e.backtrace)
0
rescue Test::Unit::AssertionFailedError => e
0
add_failure(e.message, e.backtrace)
0
- raise if Test::Unit::TestCase::PASSTHROUGH_EXCEPTIONS.include? $!.class
0
+ raise if PASSTHROUGH_EXCEPTIONS.include?(e.class)
0
+ run_callbacks :teardown, :enumerator => :reverse_each
0
+ rescue Test::Unit::AssertionFailedError => e
0
+ add_failure(e.message, e.backtrace)
0
+ raise if PASSTHROUGH_EXCEPTIONS.include?(e.class)
0
+ mocha_teardown if using_mocha
0
+ yield(Test::Unit::TestCase::FINISHED, name)
0
- yield(Test::Unit::TestCase::FINISHED, name)