lib/test/unit/testcase.rb in test-unit-2.5.5 vs lib/test/unit/testcase.rb in test-unit-3.0.0

- old
+ new

@@ -6,22 +6,22 @@ # * Copyright (c) 2008-2012 Kouhei Sutou <tt><kou@clear-code.com></tt> # License:: Ruby license. require 'test/unit/attribute' require 'test/unit/fixture' -require 'test/unit/exceptionhandler' +require 'test/unit/exception-handler' require 'test/unit/assertions' require 'test/unit/failure' require 'test/unit/error' require 'test/unit/pending' require 'test/unit/omission' require 'test/unit/notification' require 'test/unit/priority' require 'test/unit/data' require 'test/unit/testsuite' -require 'test/unit/testsuitecreator' -require 'test/unit/assertionfailederror' +require 'test/unit/test-suite-creator' +require 'test/unit/assertion-failed-error' require 'test/unit/util/backtracefilter' require 'test/unit/util/output' require 'test/unit/util/method-owner-finder' module Test @@ -115,12 +115,18 @@ _added_methods = added_methods stringified_name = name.to_s if _added_methods.include?(stringified_name) attribute(:redefined, {:backtrace => caller}, {}, stringified_name) end - path, line, = caller[0].split(/:(\d+)/,2) - line = line.to_i if line + _attributes = attributes_table[stringified_name] || {} + source_location = _attributes[:source_location] + if source_location + path, line = source_location + else + path, line, = caller[0].split(/:(\d+)/,2) + line = line.to_i if line + end method_locations << { :method_name => stringified_name, :path => path, :line => line, } @@ -265,16 +271,16 @@ if n_arguments > 1 message = "wrong number of arguments (#{n_arguments} for 1)" raise ArgumentError, message end method_name = "test: #{test_description}" - define_method(method_name, &block) description(test_description, method_name) attribute(:test, true, {}, method_name) if block.respond_to?(:source_location) attribute(:source_location, block.source_location, {}, method_name) end + define_method(method_name, &block) else targets = test_description_or_targets attribute(:test, true, {}, *targets) end end @@ -328,13 +334,14 @@ # @yield # The block is evaludated under the newly created sub test # case class context. # @return [Test::Unit::TestCase] Created sub test case class. def sub_test_case(name, &block) + parent_test_case = self sub_test_case = Class.new(self) do singleton_class = class << self; self; end singleton_class.send(:define_method, :name) do - name + [parent_test_case.name, name].compact.join("::") end end sub_test_case.class_eval(&block) sub_test_case end