lib/test/unit/testcase.rb in test-unit-2.0.0 vs lib/test/unit/testcase.rb in test-unit-2.0.1

- old
+ new

@@ -107,19 +107,99 @@ suite << new("default_test") end end suite end + + # Called before every test case runs. Can be used + # to set up fixture information used in test case + # scope. + # + # Here is an example test case: + # class TestMyClass < Test::Unit::TestCase + # class << self + # def startup + # ... + # end + # end + # + # def setup + # ... + # end + # + # def test_my_class1 + # ... + # end + # + # def test_my_class2 + # ... + # end + # end + # + # Here is a call order: + # * startup + # * setup + # * test_my_class1 (or test_my_class2) + # * setup + # * test_my_class2 (or test_my_class1) + # + # Note that you should not assume test order. Tests + # should be worked in any order. + def startup + end + + # Called after every test case runs. Can be used to tear + # down fixture information used in test case scope. + # + # Here is an example test case: + # class TestMyClass < Test::Unit::TestCase + # class << self + # def shutdown + # ... + # end + # end + # + # def teardown + # ... + # end + # + # def test_my_class1 + # ... + # end + # + # def test_my_class2 + # ... + # end + # end + # + # Here is a call order: + # * test_my_class1 (or test_my_class2) + # * teardown + # * test_my_class2 (or test_my_class1) + # * teardown + # * shutdown + # + # Note that you should not assume test order. Tests + # should be worked in any order. + def shutdown + end end attr_reader :method_name # Creates a new instance of the fixture for running the # test represented by test_method_name. def initialize(test_method_name) throw :invalid_test unless respond_to?(test_method_name) - throw :invalid_test if method(test_method_name).arity > 0 + test_method = method(test_method_name) + throw :invalid_test if test_method.arity > 0 + if test_method.respond_to?(:owner) + if test_method.owner.class != Module and + self.class != test_method.owner + throw :invalid_test + end + end @method_name = test_method_name @test_passed = true @interrupted = false end @@ -130,11 +210,11 @@ begin @_result = result yield(STARTED, name) begin run_setup - __send__(@method_name) + run_test rescue Exception @interrupted = true raise unless handle_exception($!) ensure begin @@ -247,9 +327,13 @@ end private def current_result @_result + end + + def run_test + __send__(@method_name) end def handle_exception(exception) self.class.exception_handlers.each do |handler| return true if send(handler, exception)