lib/test/unit/testcase.rb in test-unit-3.2.3 vs lib/test/unit/testcase.rb in test-unit-3.2.4

- old
+ new

@@ -80,10 +80,29 @@ # 1. setup # 1. test_my_method2 # 1. cleanup # 1. teardown # 1. shutdown + # + # You can set an attribute to each test. + # + # Example: + # + # class TestMyClass < Test::Unit::TestCase + # attribute :speed, :fast + # def test_my_fast_method + # # You can get the attribute via `self[]` + # self[:speed] # => :fast + # ... + # end + # + # attribute :speed, :slow + # def test_my_slow_method + # self[:speed] # => :slow + # ... + # end + # end class TestCase include Attribute include Fixture include ExceptionHandler include ErrorHandler @@ -318,19 +337,19 @@ # # This is a syntax sugar. The both of the following codes are # the same in meaning: # # Standard: - # class TestParent < Test::UnitTestCase + # class TestParent < Test::Unit::TestCase # class TestChild < self # def test_in_child # end # end # end # # Syntax sugar: - # class TestParent < Test::UnitTestCase + # class TestParent < Test::Unit::TestCase # sub_test_case("TestChild") do # def test_in_child # end # end # end @@ -392,11 +411,12 @@ return [] if available_location[:test_case] != self available_locations = [available_location] end if query_method_name available_location = available_locations.find do |location| - query_method_name == location[:method_name] + location[:test_case] == self and + query_method_name == location[:method_name] end return [] if available_location.nil? available_locations = [available_location] end @@ -659,14 +679,23 @@ end # Returns a human-readable name for the specific test that # this instance of TestCase represents. def name + "#{local_name}(#{self.class.name})" + end + + # Returns a human-readable name for the specific test that this + # instance of TestCase represents. + # + # `#local_name` doesn't include class name. `#name` includes + # class name. + def local_name if @internal_data.have_test_data? - "#{@method_name}[#{data_label}](#{self.class.name})" + "#{@method_name}[#{data_label}]" else - "#{@method_name}(#{self.class.name})" + @method_name.to_s end end # Returns a description for the test. A description # will be associated by Test::Unit::TestCase.test or @@ -743,11 +772,11 @@ def run_test signature = "#{self.class}\##{@method_name}" redefined_info = self[:redefined] if redefined_info - notify("#{signature} was redefined", + notify("<#{signature}> was redefined", :backtrace => redefined_info[:backtrace]) end if @internal_data.have_test_data? test_method = method(@method_name) if test_method.arity == 1 or test_method.arity < 0 @@ -755,10 +784,10 @@ else locations = self.class.find_locations(:method_name => @method_name) backtrace = locations.collect do |location| "#{location[:path]}:#{location[:line]}" end - notify("#{signature} misses a parameter to take test data", + notify("<#{signature}> misses a parameter to take test data", :backtrace => backtrace) end else __send__(@method_name) end