test-unit/lib/test/unit/priority.rb in activeldap-1.0.1 vs test-unit/lib/test/unit/priority.rb in activeldap-1.0.2
- old
+ new
@@ -11,10 +11,23 @@
base.class_eval do
setup :priority_setup, :before => :prepend
teardown :priority_teardown, :after => :append
end
end
+
+ @@enabled = false
+ def enabled?
+ @@enabled
+ end
+
+ def enable
+ @@enabled = true
+ end
+
+ def disable
+ @@enabled = false
+ end
end
class Checker
class << self
def have_priority?(name)
@@ -88,11 +101,11 @@
end
def result_dir
components = [".test-result",
@test.class.name || "AnonymousTestCase",
- @test.method_name.to_s]
+ escaped_method_name]
parent_directories = [File.dirname($0), Dir.pwd]
if Process.respond_to?(:uid)
parent_directories << File.join(Dir.tmpdir, Process.uid.to_s)
end
parent_directories.each do |parent_directory|
@@ -110,11 +123,11 @@
def passed_file
File.join(result_dir, "passed")
end
def escaped_method_name
- @method_name.to_s.gsub(/[!?=]$/) do |matched|
+ @test.method_name.to_s.gsub(/[!?=]$/) do |matched|
case matched
when "!"
".destructive"
when "?"
".predicate"
@@ -133,13 +146,15 @@
attribute(:priority, name, {:keep => true}, *tests)
end
end
def priority_setup
+ return unless Priority.enabled?
Checker.new(self).setup
end
def priority_teardown
+ return unless Priority.enabled?
Checker.new(self).teardown
end
end
end
end