lib/test/unit/testcase.rb in test-unit-3.1.0 vs lib/test/unit/testcase.rb in test-unit-3.1.1

- old
+ new

@@ -358,21 +358,20 @@ def test_defined?(query) query_path = query[:path] query_line = query[:line] query_method_name = query[:method_name] - available_locations = method_locations - if query_path - available_locations = available_locations.find_all do |location| - location[:path].end_with?(query_path) - end - end + available_locations = target_method_locations(query_path) if query_line - available_location = available_locations.reverse.find do |location| + available_locations = available_locations.sort_by do |location| + -location[:line] + end + available_location = available_locations.find do |location| query_line >= location[:line] end return false if available_location.nil? + return false 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] @@ -388,9 +387,28 @@ # @private @@method_locations = {} # @private def method_locations @@method_locations[self] ||= [] + end + + # @private + def target_method_locations(path) + if path.nil? + self_location = method_locations.first + path = self_location[:path] if self_location + end + return [] if path.nil? + + target_locations = [] + @@method_locations.each do |test_case, locations| + locations.each do |location| + if location[:path].end_with?(path) + target_locations << location.merge(:test_case => test_case) + end + end + end + target_locations end end attr_reader :method_name