Class: Test::Unit::Failure

Inherits:
Object
  • Object
show all
Defined in:
lib/test/unit/failure.rb

Overview

Encapsulates a test failure. Created by Test::Unit::TestCase when an assertion fails.

Constant Summary collapse

SINGLE_CHARACTER =
'F'
LABEL =
"Failure"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(test_name, location, message, options = {}) ⇒ Failure

Creates a new Failure with the given location and message.



22
23
24
25
26
27
28
29
30
31
# File 'lib/test/unit/failure.rb', line 22

def initialize(test_name, location, message, options={})
  @test_name = test_name
  @location = location
  @message = message
  @expected = options[:expected]
  @actual = options[:actual]
  @inspected_expected = options[:inspected_expected]
  @inspected_actual = options[:inspected_actual]
  @user_message = options[:user_message]
end

Instance Attribute Details

#actualObject (readonly)

Returns the value of attribute actual.



14
15
16
# File 'lib/test/unit/failure.rb', line 14

def actual
  @actual
end

#expectedObject (readonly)

Returns the value of attribute expected.



14
15
16
# File 'lib/test/unit/failure.rb', line 14

def expected
  @expected
end

#inspected_actualObject (readonly)

Returns the value of attribute inspected_actual.



15
16
17
# File 'lib/test/unit/failure.rb', line 15

def inspected_actual
  @inspected_actual
end

#inspected_expectedObject (readonly)

Returns the value of attribute inspected_expected.



15
16
17
# File 'lib/test/unit/failure.rb', line 15

def inspected_expected
  @inspected_expected
end

#locationObject (readonly)

Returns the value of attribute location.



13
14
15
# File 'lib/test/unit/failure.rb', line 13

def location
  @location
end

#messageObject (readonly)

Returns the value of attribute message.



13
14
15
# File 'lib/test/unit/failure.rb', line 13

def message
  @message
end

#test_nameObject (readonly)

Returns the value of attribute test_name.



13
14
15
# File 'lib/test/unit/failure.rb', line 13

def test_name
  @test_name
end

#user_messageObject (readonly)

Returns the value of attribute user_message.



14
15
16
# File 'lib/test/unit/failure.rb', line 14

def user_message
  @user_message
end

Instance Method Details

#critical?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/test/unit/failure.rb', line 62

def critical?
  true
end

#diffObject



66
67
68
# File 'lib/test/unit/failure.rb', line 66

def diff
  @diff ||= compute_diff
end

#labelObject



38
39
40
# File 'lib/test/unit/failure.rb', line 38

def label
  LABEL
end

#long_displayObject

Returns a verbose version of the error description.



48
49
50
51
52
53
54
55
# File 'lib/test/unit/failure.rb', line 48

def long_display
  if location.size == 1
    location_display = location[0].sub(/\A(.+:\d+).*/, ' [\\1]')
  else
    location_display = "\n    [#{location.join("\n     ")}]"
  end
  "#{label}:\n#@test_name#{location_display}:\n#@message"
end

#short_displayObject

Returns a brief version of the error description.



43
44
45
# File 'lib/test/unit/failure.rb', line 43

def short_display
  "#@test_name: #{@message.split("\n")[0]}"
end

#single_character_displayObject

Returns a single character representation of a failure.



34
35
36
# File 'lib/test/unit/failure.rb', line 34

def single_character_display
  SINGLE_CHARACTER
end

#to_sObject

Overridden to return long_display.



58
59
60
# File 'lib/test/unit/failure.rb', line 58

def to_s
  long_display
end