1
require 'active_support/callbacks'
5
module SetupAndTeardown
6
def self.included(base)
8
include ActiveSupport::Callbacks
9
define_callbacks :setup, :teardown
11
if defined?(MiniTest::Assertions) && TestCase < MiniTest::Assertions
14
include ForClassicTestUnit
26
result = runner.puke(self.class, self.name, e)
29
run_callbacks :teardown, :enumerator => :reverse_each
31
result = runner.puke(self.class, self.name, e)
38
module ForClassicTestUnit
39
# For compatibility with Ruby < 1.8.6
40
PASSTHROUGH_EXCEPTIONS = Test::Unit::TestCase::PASSTHROUGH_EXCEPTIONS rescue [NoMemoryError, SignalException, Interrupt, SystemExit]
42
# This redefinition is unfortunate but test/unit shows us no alternative.
43
# Doubly unfortunate: hax to support Mocha's hax.
45
return if @method_name.to_s == "default_test"
47
if using_mocha = respond_to?(:mocha_verify)
48
assertion_counter_klass = if defined?(Mocha::TestCaseAdapter::AssertionCounter)
49
Mocha::TestCaseAdapter::AssertionCounter
51
Mocha::Integration::TestUnit::AssertionCounter
53
assertion_counter = assertion_counter_klass.new(result)
56
yield(Test::Unit::TestCase::STARTED, name)
62
__send__(@method_name)
63
mocha_verify(assertion_counter) if using_mocha
64
rescue Mocha::ExpectationError => e
65
add_failure(e.message, e.backtrace)
66
rescue Test::Unit::AssertionFailedError => e
67
add_failure(e.message, e.backtrace)
69
raise if PASSTHROUGH_EXCEPTIONS.include?(e.class)
74
run_callbacks :teardown, :enumerator => :reverse_each
75
rescue Test::Unit::AssertionFailedError => e
76
add_failure(e.message, e.backtrace)
78
raise if PASSTHROUGH_EXCEPTIONS.include?(e.class)
83
mocha_teardown if using_mocha
86
yield(Test::Unit::TestCase::FINISHED, name)