lib/test/unit/testcase.rb in test-unit-2.0.6 vs lib/test/unit/testcase.rb in test-unit-2.0.7
- old
+ new
@@ -92,14 +92,19 @@
class << self
def inherited(sub_class) # :nodoc:
DESCENDANTS << sub_class
end
- @@added_methods = []
+ @@added_methods = {}
def method_added(name) # :nodoc:
super
- @@added_methods << name.to_s
+ added_methods = (@@added_methods[self] ||= [])
+ stringified_name = name.to_s
+ if added_methods.include?(stringified_name)
+ attribute(:redefined, true, {}, stringified_name)
+ end
+ added_methods << stringified_name
end
# Rolls up all of the test* methods in the fixture into
# one suite, creating a new instance of the fixture for
# each method.
@@ -189,16 +194,16 @@
# Note that you should not assume test order. Tests
# should be worked in any order.
def shutdown
end
- @@test_order = AVAILABLE_ORDERS.first
+ @@test_orders = {}
# Returns the current test order. This returns
# +:alphabetic+ by default.
def test_order
- @@test_order
+ @@test_orders[self] || AVAILABLE_ORDERS.first
end
# Sets the current test order.
#
# Here are the available _order_:
@@ -207,11 +212,11 @@
# [:random]
# Tests are sorted in random order.
# [:defined]
# Tests are sorted in defined order.
def test_order=(order)
- @@test_order = order
+ @@test_orders[self] = order
end
# Defines a test in declarative syntax.
#
# The following two test definitions are the same:
@@ -264,13 +269,14 @@
def sort_test_names_in_random_order(test_names)
test_names.sort_by {rand(test_names.size)}
end
def sort_test_names_in_defined_order(test_names)
+ added_methods = @@added_methods[self]
test_names.sort do |test1, test2|
- test1_defined_order = @@added_methods.index(test1)
- test2_defined_order = @@added_methods.index(test2)
+ test1_defined_order = added_methods.index(test1)
+ test2_defined_order = added_methods.index(test2)
if test1_defined_order and test2_defined_order
test1_defined_order <=> test2_defined_order
elsif test1_defined_order
1
elsif test2_defined_order
@@ -436,9 +442,12 @@
def current_result
@_result
end
def run_test
+ if self.class.get_attribute(@method_name, :redefined)
+ notify("#{self.class}\##{@method_name} was redefined")
+ end
__send__(@method_name)
end
def handle_exception(exception)
self.class.exception_handlers.each do |handler|