lib/ae/adapters/testunit.rb in ae-1.7.0 vs lib/ae/adapters/testunit.rb in ae-1.7.1
- old
+ new
@@ -4,18 +4,55 @@
# TestUnit uses #add_assertion on it's +result+ object to track counts.
# We capture the result object by overriding the TestCase#run method,
# store it in a global variable and then use it when AE increments
# assertion counts.
+#
+# In addition we teach #run to recognize any Exception class that
+# responds to #assertion? in the affirmative as an assertion
+# rather than an error.
module Test #:nodoc:
module Unit #:nodoc:
class TestCase #:nodoc:
- alias_method :_run, :run
- def run(result, &block)
+ # These exceptions are not caught by #run.
+ PASSTHROUGH_EXCEPTIONS = [NoMemoryError, SignalException, Interrupt, SystemExit]
+ # Runs the individual test method represented by this
+ # instance of the fixture, collecting statistics, failures
+ # and errors in result.
+ def run(result)
$_test_unit_result = result
- _run(result, &block)
- end
+ yield(STARTED, name)
+ @_result = result
+ begin
+ setup
+ __send__(@method_name)
+ rescue AssertionFailedError => e
+ add_failure(e.message, e.backtrace)
+ rescue Exception => e
+ if e.respond_to?(:assertion?) && e.assertion?
+ add_failure(e.message, e.backtrace)
+ else
+ raise if PASSTHROUGH_EXCEPTIONS.include? $!.class
+ add_error($!)
+ end
+ ensure
+ begin
+ teardown
+ rescue AssertionFailedError => e
+ add_failure(e.message, e.backtrace)
+ rescue Exception => e
+ if e.respond_to?(:assertion?) && e.assertion?
+ add_failure(e.message, e.backtrace)
+ else
+ raise if PASSTHROUGH_EXCEPTIONS.include? $!.class
+ add_error($!)
+ end
+ end
+ end
+ result.add_run
+ yield(FINISHED, name)
+ end
end
end
end
class AE::Assertor #:nodoc: