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

- old
+ new

@@ -6,19 +6,29 @@ class << self alias_method :method_added_without_attributes, :method_added def method_added(name) method_added_without_attributes(name) if defined?(@current_attributes) - set_attributes(name, @current_attributes) - @current_attributes = {} + attributes = {} + kept_attributes = {} + @current_attributes.each do |attribute_name, attribute| + attributes[attribute_name] = attribute[:value] + kept_attributes[attribute_name] = attribute if attribute[:keep] + end + set_attributes(name, attributes) + @current_attributes = kept_attributes end end - def attribute(name, value, *tests) + def attribute(name, value, options={}, *tests) + unless options.is_a?(Hash) + tests << options + options = {} + end @current_attributes ||= {} if tests.empty? - @current_attributes[name] = value + @current_attributes[name] = options.merge(:value => value) else tests.each do |test| set_attribute(test, {name => value}) end end @@ -38,9 +48,14 @@ def attributes(test_name) test_name = normalize_test_name(test_name) @attributes ||= {} @attributes[test_name] + end + + private + def normalize_test_name(test_name) + "test_#{test_name.to_s.sub(/^test_/, '')}" end end alias_method :run_without_attributes, :run def run(result, &block)