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::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) ⇒ Error

Creates a new Error with the given test_name and exception.



25
26
27
28
# File 'lib/test/unit/error.rb', line 25

def initialize(test_name, exception)
  @test_name = test_name
  @exception = exception
end

Instance Attribute Details

#exceptionObject (readonly)

Returns the value of attribute exception.



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

def exception
  @exception
end

#test_nameObject (readonly)

Returns the value of attribute test_name.



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

def test_name
  @test_name
end

Instance Method Details

#backtraceObject



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

def backtrace
  filter_backtrace(@exception.backtrace)
end

#critical?Boolean

Returns:

  • (Boolean)


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

def critical?
  true
end

#labelObject



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

def label
  LABEL
end

#long_displayObject

Returns a verbose version of the error description.



50
51
52
53
# File 'lib/test/unit/error.rb', line 50

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

#messageObject

Returns the message associated with the error.



40
41
42
# File 'lib/test/unit/error.rb', line 40

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

#short_displayObject

Returns a brief version of the error description.



45
46
47
# File 'lib/test/unit/error.rb', line 45

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

#single_character_displayObject

Returns a single character representation of an error.



31
32
33
# File 'lib/test/unit/error.rb', line 31

def single_character_display
  SINGLE_CHARACTER
end

#to_sObject

Overridden to return long_display.



60
61
62
# File 'lib/test/unit/error.rb', line 60

def to_s
  long_display
end