Line | |
---|
1 | #--
|
---|
2 | #
|
---|
3 | # Author:: Nathaniel Talbott.
|
---|
4 | # Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved.
|
---|
5 | # License:: Ruby license.
|
---|
6 |
|
---|
7 | module Test
|
---|
8 | module Unit
|
---|
9 |
|
---|
10 | # Encapsulates a test failure. Created by Test::Unit::TestCase
|
---|
11 | # when an assertion fails.
|
---|
12 | class Failure
|
---|
13 | attr_reader :test_name, :location, :message
|
---|
14 |
|
---|
15 | SINGLE_CHARACTER = 'F'
|
---|
16 |
|
---|
17 | # Creates a new Failure with the given location and
|
---|
18 | # message.
|
---|
19 | def initialize(test_name, location, message)
|
---|
20 | @test_name = test_name
|
---|
21 | @location = location
|
---|
22 | @message = message
|
---|
23 | end
|
---|
24 |
|
---|
25 | # Returns a single character representation of a failure.
|
---|
26 | def single_character_display
|
---|
27 | SINGLE_CHARACTER
|
---|
28 | end
|
---|
29 |
|
---|
30 | # Returns a brief version of the error description.
|
---|
31 | def short_display
|
---|
32 | "#@test_name: #{@message.split("\n")[0]}"
|
---|
33 | end
|
---|
34 |
|
---|
35 | # Returns a verbose version of the error description.
|
---|
36 | def long_display
|
---|
37 | location_display = if(location.size == 1)
|
---|
38 | location[0].sub(/\A(.+:\d+).*/, ' [\\1]')
|
---|
39 | else
|
---|
40 | "\n [#{location.join("\n ")}]"
|
---|
41 | end
|
---|
42 | "Failure:\n#@test_name#{location_display}:\n#@message"
|
---|
43 | end
|
---|
44 |
|
---|
45 | # Overridden to return long_display.
|
---|
46 | def to_s
|
---|
47 | long_display
|
---|
48 | end
|
---|
49 | end
|
---|
50 | end
|
---|
51 | end
|
---|
Note:
See
TracBrowser
for help on using the repository browser.