3 module SetupAndTeardown
4 # For compatibility with Ruby < 1.8.6
5 PASSTHROUGH_EXCEPTIONS
=
6 if defined?(Test
::Unit::TestCase::PASSTHROUGH_EXCEPTIONS)
7 Test
::Unit::TestCase::PASSTHROUGH_EXCEPTIONS
9 [NoMemoryError
, SignalException
, Interrupt
, SystemExit
]
12 def self.included(base
)
14 include ActiveSupport
::Callbacks
15 define_callbacks
:setup, :teardown
19 alias_method
:run, :run_with_callbacks_and_miniunit
24 alias_method
:run, :run_with_callbacks_and_mocha
27 alias_method
:run, :run_with_callbacks_and_testunit
33 def run_with_callbacks_and_miniunit(runner
)
39 result
= runner
.puke(self.class, self.name
, e
)
43 run_callbacks
:teardown, :enumerator => :reverse_each
45 result
= runner
.puke(self.class, self.name
, e
)
51 # This redefinition is unfortunate but test/unit shows us no alternative.
52 def run_with_callbacks_and_testunit(result
) #:nodoc:
53 return if @method_name.to_s
== "default_test"
55 yield(Test
::Unit::TestCase::STARTED, name
)
60 __send__(@method_name)
61 rescue Test
::Unit::AssertionFailedError => e
62 add_failure(e
.message
, e
.backtrace
)
63 rescue *PASSTHROUGH_EXCEPTIONS
70 run_callbacks
:teardown, :enumerator => :reverse_each
71 rescue Test
::Unit::AssertionFailedError => e
72 add_failure(e
.message
, e
.backtrace
)
73 rescue *PASSTHROUGH_EXCEPTIONS
80 yield(Test
::Unit::TestCase::FINISHED, name
)
83 # Doubly unfortunate: mocha does the same so we have to hax their hax.
84 def run_with_callbacks_and_mocha(result
)
85 return if @method_name.to_s
== "default_test"
87 yield(Test
::Unit::TestCase::STARTED, name
)
94 __send__(@method_name)
95 mocha_verify
{ add_assertion
}
96 rescue Mocha
::ExpectationError => e
97 add_failure(e
.message
, e
.backtrace
)
98 rescue Test
::Unit::AssertionFailedError => e
99 add_failure(e
.message
, e
.backtrace
)
100 rescue StandardError
, ScriptError
105 run_callbacks
:teardown, :enumerator => :reverse_each
106 rescue Test
::Unit::AssertionFailedError => e
107 add_failure(e
.message
, e
.backtrace
)
108 rescue StandardError
, ScriptError
116 yield(Test
::Unit::TestCase::FINISHED, name
)