Class: Test::Unit::Error

Inherits:
Object
  • Object
show all
Includes:
Util::BacktraceFilter
Defined in:
lib/test/unit/error.rb

Overview

Encapsulates an error in a test. Created by Test::Unit::TestCase when it rescues an exception thrown during the processing of a test.

Constant Summary collapse

SINGLE_CHARACTER =
'E'
LABEL =
"Error"

Constants included from Util::BacktraceFilter

Util::BacktraceFilter::POWERASSERT_PREFIX, Util::BacktraceFilter::TESTUNIT_FILE_SEPARATORS, Util::BacktraceFilter::TESTUNIT_PREFIX, Util::BacktraceFilter::TESTUNIT_RB_FILE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util::BacktraceFilter

filter_backtrace

Constructor Details

#initialize(test_name, exception, options = {}) ⇒ Error

Creates a new Error with the given test_name and exception.



27
28
29
30
31
# File 'lib/test/unit/error.rb', line 27

def initialize(test_name, exception, options={})
  @test_name = test_name
  @exception = exception
  @method_name = options[:method_name]
end

Instance Attribute Details

#exception ⇒ Object (readonly)

Returns the value of attribute exception.



19
20
21
# File 'lib/test/unit/error.rb', line 19

def exception
  @exception
end

#method_name ⇒ Object (readonly)

Returns the value of attribute method_name.



20
21
22
# File 'lib/test/unit/error.rb', line 20

def method_name
  @method_name
end

#test_name ⇒ Object (readonly)

Returns the value of attribute test_name.



19
20
21
# File 'lib/test/unit/error.rb', line 19

def test_name
  @test_name
end

Instance Method Details

#critical? ⇒ Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/test/unit/error.rb', line 68

def critical?
  true
end

#label ⇒ Object



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

def label
  LABEL
end

#location ⇒ Object Also known as: backtrace



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

def location
  @location ||= filter_backtrace(@exception.backtrace)
end

#long_display ⇒ Object

Returns a verbose version of the error description.



53
54
55
56
# File 'lib/test/unit/error.rb', line 53

def long_display
  backtrace_display = location.join("\n    ")
  "#{label}:\n#@test_name:\n#{message}\n    #{backtrace_display}"
end

#message ⇒ Object

Returns the message associated with the error.



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

def message
  "#{@exception.class.name}: #{@exception.message}"
end

#short_display ⇒ Object

Returns a brief version of the error description.



48
49
50
# File 'lib/test/unit/error.rb', line 48

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

#single_character_display ⇒ Object

Returns a single character representation of an error.



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

def single_character_display
  SINGLE_CHARACTER
end

#to_s ⇒ Object

Overridden to return long_display.



64
65
66
# File 'lib/test/unit/error.rb', line 64

def to_s
  long_display
end