lib/test-unit-ext/priority.rb in test-unit-ext-0.4.0 vs lib/test-unit-ext/priority.rb in test-unit-ext-0.5.0

- old
+ new

@@ -1,65 +1,32 @@ require "test/unit" require "fileutils" require "tmpdir" +require "test-unit-ext/attributes" + module Test module Unit class TestCase class << self - def inherited(sub) - super - sub.instance_variable_set("@priority_initialized", true) - sub.instance_variable_set("@priority_table", {}) - sub.priority :normal - end - - def include(*args) - args.reverse_each do |mod| - super(mod) - next unless defined?(@priority_initialized) - mod.instance_methods(false).each do |name| - set_priority(name) - end - end - end - - alias_method :method_added_without_priority, :method_added - def method_added(name) - method_added_without_priority(name) - set_priority(name) if defined?(@priority_initialized) - end - def priority(name, *tests) singleton_class = (class << self; self; end) priority_check_method = priority_check_method_name(name) unless singleton_class.private_method_defined?(priority_check_method) raise ArgumentError, "unknown priority: #{name}" end - if tests.empty? - @current_priority = name - else - tests.each do |test| - set_priority(test, name) - end - end + attribute(:priority, name, {:keep => true}, *tests) end def need_to_run?(test_name) - normalized_test_name = normalize_test_name(test_name) - priority = @priority_table[normalized_test_name] - return true unless priority + priority = (attributes(test_name) || {})[:priority] || :normal __send__(priority_check_method_name(priority), test_name) end private def priority_check_method_name(priority_name) "run_priority_#{priority_name}?" - end - - def normalize_test_name(test_name) - "test_#{test_name.to_s.sub(/^test_/, '')}" end def set_priority(name, priority=@current_priority) @priority_table[normalize_test_name(name)] = priority end