Class: Test::Unit::TestCase

Inherits:
Object
  • Object
show all
Includes:
AssertionsWithDiff, AssertionsWithNotify, AssertionsWithPend
Defined in:
lib/test-unit-ext/pending.rb,
lib/test-unit-ext/priority.rb,
lib/test-unit-ext/assertions.rb,
lib/test-unit-ext/attributes.rb,
lib/test-unit-ext/xml-report.rb,
lib/test-unit-ext/notification.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from AssertionsWithNotify

#notify

Methods included from AssertionsWithDiff

#assert_equal, #fold

Methods included from AssertionsWithPend

#pend

Class Method Details

.attribute(name, value, options = {}, *tests) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/test-unit-ext/attributes.rb', line 22

def attribute(name, value, options={}, *tests)
  unless options.is_a?(Hash)
    tests << options
    options = {}
  end
  @current_attributes ||= {}
  if tests.empty?
    @current_attributes[name] = options.merge(:value => value)
  else
    tests.each do |test|
      set_attribute(test, {name => value})
    end
  end
end

.attributes(test_name) ⇒ Object



49
50
51
52
53
# File 'lib/test-unit-ext/attributes.rb', line 49

def attributes(test_name)
  test_name = normalize_test_name(test_name)
  @attributes ||= {}
  @attributes[test_name]
end

.bug(value, *tests) ⇒ Object



37
38
39
# File 'lib/test-unit-ext/attributes.rb', line 37

def bug(value, *tests)
  attribute(:bug, value, *tests)
end

.method_added(name) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/test-unit-ext/attributes.rb', line 8

def method_added(name)
  method_added_without_attributes(name)
  if defined?(@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

.method_added_without_attributesObject



7
# File 'lib/test-unit-ext/attributes.rb', line 7

alias_method :method_added_without_attributes, :method_added

.need_to_run?(test_name) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
24
# File 'lib/test-unit-ext/priority.rb', line 21

def need_to_run?(test_name)
  priority = (attributes(test_name) || {})[:priority] || :normal
  __send__(priority_check_method_name(priority), test_name)
end

.priority(name, *tests) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/test-unit-ext/priority.rb', line 12

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
  attribute(:priority, name, {:keep => true}, *tests)
end

.set_attributes(test_name, attributes) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/test-unit-ext/attributes.rb', line 41

def set_attributes(test_name, attributes)
  return if attributes.empty?
  test_name = normalize_test_name(test_name)
  @attributes ||= {}
  @attributes[test_name] ||= {}
  @attributes[test_name] = @attributes[test_name].merge(attributes)
end

Instance Method Details

#add_error(*args) ⇒ Object



89
90
91
92
93
94
95
96
# File 'lib/test-unit-ext/pending.rb', line 89

def add_error(exception)
  if exception.is_a?(PendedError)
    pending = Pending.new(name, exception.backtrace, exception.message)
    @_result.add_pending(pending)
  else
    add_error_without_pending(exception)
  end
end

#add_error_without_pendingObject



88
# File 'lib/test-unit-ext/pending.rb', line 88

alias_method(:add_error_without_pending, :add_error)

#add_error_without_test_case_setObject



144
145
146
147
148
149
150
151
# File 'lib/test-unit-ext/xml-report.rb', line 144

def add_error(exception)
  if exception.is_a?(PendedError)
    pending = Pending.new(name, exception.backtrace, exception.message)
    @_result.add_pending(pending)
  else
    add_error_without_pending(exception)
  end
end

#add_failure(*args) ⇒ Object



137
138
139
140
141
142
# File 'lib/test-unit-ext/xml-report.rb', line 137

def add_failure(*args)
  add_failure_without_test_case_set(*args)
  failure = @_result.failures.last
  failure.test = self
  failure.elapsed_time = Time.now - @_start_time
end

#add_failure_without_test_case_setObject



136
# File 'lib/test-unit-ext/xml-report.rb', line 136

alias_method(:add_failure_without_test_case_set, :add_failure)

#attributesObject



67
68
69
# File 'lib/test-unit-ext/attributes.rb', line 67

def attributes
  self.class.attributes(@method_name) || {}
end

#need_to_run?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/test-unit-ext/priority.rb', line 60

def need_to_run?
  !previous_test_success? or self.class.need_to_run?(@method_name)
end

#run(result, &block) ⇒ Object



65
66
67
68
69
70
71
72
73
# File 'lib/test-unit-ext/priority.rb', line 65

def run(result, &block)
  run_without_priority(result, &block)
ensure
  if passed?
    FileUtils.touch(passed_file)
  else
    FileUtils.rm_f(passed_file)
  end
end

#run_without_attributesObject



61
62
63
64
65
66
67
68
69
# File 'lib/test-unit-ext/attributes.rb', line 61

def run(result, &block)
  run_without_priority(result, &block)
ensure
  if passed?
    FileUtils.touch(passed_file)
  else
    FileUtils.rm_f(passed_file)
  end
end

#run_without_priorityObject



64
# File 'lib/test-unit-ext/priority.rb', line 64

alias_method :run_without_priority, :run

#run_without_success_notifyObject



128
129
130
131
132
133
134
135
136
# File 'lib/test-unit-ext/xml-report.rb', line 128

def run(result, &block)
  run_without_priority(result, &block)
ensure
  if passed?
    FileUtils.touch(passed_file)
  else
    FileUtils.rm_f(passed_file)
  end
end