Class: Test::Unit::Error

Inherits:
Object
  • Object
show all
Includes:
Util::BacktraceFilter
Defined in:
lib/test/unit/error.rb,
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.



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

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

Instance Attribute Details

#exceptionObject (readonly)

Returns the value of attribute exception



12
13
14
# File 'lib/test/unit/error.rb', line 12

def exception
  @exception
end

#method_nameObject (readonly)

Returns the value of attribute method_name



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

def method_name
  @method_name
end

#test_nameObject (readonly)

Returns the value of attribute test_name



12
13
14
# File 'lib/test/unit/error.rb', line 12

def test_name
  @test_name
end

Instance Method Details

#critical?Boolean

Returns:

  • (Boolean)


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

def critical?
  true
end

#labelObject



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

def label
  LABEL
end

#locationObject Also known as: backtrace



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

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

#long_displayObject

Returns a verbose version of the error description.



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

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

#messageObject

Returns the message associated with the error.



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

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

#short_displayObject

Returns a brief version of the error description.



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

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

#single_character_displayObject

Returns a single character representation of an error.



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

def single_character_display
  SINGLE_CHARACTER
end

#to_sObject

Overridden to return long_display.



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

def to_s
  long_display
end