test-unit 3.4.2 → 3.4.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +4 -3
- data/Rakefile +0 -9
- data/doc/text/getting-started.md +1 -1
- data/doc/text/news.md +52 -0
- data/lib/test/unit/assertion-failed-error.rb +35 -0
- data/lib/test/unit/assertions.rb +206 -13
- data/lib/test/unit/autorunner.rb +13 -1
- data/lib/test/unit/collector/descendant.rb +1 -0
- data/lib/test/unit/collector/dir.rb +4 -2
- data/lib/test/unit/collector/load.rb +2 -0
- data/lib/test/unit/collector/objectspace.rb +1 -0
- data/lib/test/unit/collector.rb +31 -0
- data/lib/test/unit/testcase.rb +33 -2
- data/lib/test/unit/testsuite.rb +1 -1
- data/lib/test/unit/util/memory-usage.rb +47 -0
- data/lib/test/unit/version.rb +1 -1
- data/lib/test/unit.rb +4 -4
- metadata +6 -83
- data/test/collector/test-descendant.rb +0 -182
- data/test/collector/test-load.rb +0 -475
- data/test/collector/test_dir.rb +0 -407
- data/test/collector/test_objectspace.rb +0 -102
- data/test/fixtures/header-label.csv +0 -3
- data/test/fixtures/header-label.tsv +0 -3
- data/test/fixtures/header.csv +0 -3
- data/test/fixtures/header.tsv +0 -3
- data/test/fixtures/no-header.csv +0 -2
- data/test/fixtures/no-header.tsv +0 -2
- data/test/fixtures/plus.csv +0 -3
- data/test/run-test.rb +0 -22
- data/test/test-assertions.rb +0 -2187
- data/test/test-attribute-matcher.rb +0 -38
- data/test/test-attribute.rb +0 -123
- data/test/test-code-snippet.rb +0 -79
- data/test/test-color-scheme.rb +0 -123
- data/test/test-color.rb +0 -47
- data/test/test-data.rb +0 -419
- data/test/test-diff.rb +0 -518
- data/test/test-emacs-runner.rb +0 -60
- data/test/test-error.rb +0 -26
- data/test/test-failure.rb +0 -33
- data/test/test-fault-location-detector.rb +0 -163
- data/test/test-fixture.rb +0 -713
- data/test/test-notification.rb +0 -33
- data/test/test-omission.rb +0 -81
- data/test/test-pending.rb +0 -70
- data/test/test-priority.rb +0 -184
- data/test/test-test-case.rb +0 -1284
- data/test/test-test-result.rb +0 -113
- data/test/test-test-suite-creator.rb +0 -97
- data/test/test-test-suite.rb +0 -151
- data/test/testunit-test-util.rb +0 -33
- data/test/ui/test_testrunmediator.rb +0 -20
- data/test/util/test-method-owner-finder.rb +0 -38
- data/test/util/test-output.rb +0 -11
- data/test/util/test_backtracefilter.rb +0 -52
- data/test/util/test_observable.rb +0 -102
- data/test/util/test_procwrapper.rb +0 -36
data/test/test-emacs-runner.rb
DELETED
@@ -1,60 +0,0 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
require 'test/unit/ui/emacs/testrunner'
|
3
|
-
|
4
|
-
class TestUnitEmacsRunner < Test::Unit::TestCase
|
5
|
-
def test_format_failure_with_a_location
|
6
|
-
runner = create_runner
|
7
|
-
test_name = "test_failure"
|
8
|
-
file = "/home/user/test_xxx.rb"
|
9
|
-
line = "3"
|
10
|
-
info = "in `xxx'"
|
11
|
-
location = "#{file}:#{line}: #{info}"
|
12
|
-
message = "FAIL!!!"
|
13
|
-
failure = Test::Unit::Failure.new(test_name, [location], message)
|
14
|
-
assert_equal(<<-EOM.chomp, runner.send(:format_fault, failure))
|
15
|
-
Failure:
|
16
|
-
#{test_name} [#{file}:#{line}]:
|
17
|
-
#{message}
|
18
|
-
EOM
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_format_failure_with_locations
|
22
|
-
runner = create_runner
|
23
|
-
test_name = "test_failure"
|
24
|
-
locations = ["/home/user/test_xxx.rb:3: in `xxx'",
|
25
|
-
"/home/user/yyy/test_yyy.rb:999: in `yyy'",
|
26
|
-
"/home/user/xyz/zzz.rb:29: in `zzz'"]
|
27
|
-
message = "Many backtrace!!!"
|
28
|
-
failure = Test::Unit::Failure.new(test_name, locations, message)
|
29
|
-
assert_equal(<<-EOM.chomp, runner.send(:format_fault, failure))
|
30
|
-
Failure:
|
31
|
-
#{test_name}
|
32
|
-
#{locations.join("\n")}:
|
33
|
-
#{message}
|
34
|
-
EOM
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_format_error
|
38
|
-
runner = create_runner
|
39
|
-
test_name = "test_error"
|
40
|
-
message = "Error Message!!!"
|
41
|
-
backtrace = ["/home/user/test_xxx.rb:3: in `xxx'",
|
42
|
-
"/home/user/yyy/test_yyy.rb:999: in `yyy'",
|
43
|
-
"/home/user/xyz/zzz.rb:29: in `zzz'"]
|
44
|
-
exception = RuntimeError.new(message)
|
45
|
-
exception.set_backtrace(backtrace)
|
46
|
-
error = Test::Unit::Error.new(test_name, exception)
|
47
|
-
assert_equal(<<-EOM.chomp, runner.send(:format_fault, error))
|
48
|
-
Error:
|
49
|
-
#{test_name}:
|
50
|
-
#{exception.class.name}: #{message}
|
51
|
-
#{backtrace.join("\n")}
|
52
|
-
EOM
|
53
|
-
end
|
54
|
-
|
55
|
-
private
|
56
|
-
def create_runner(suite=nil)
|
57
|
-
suite ||= Test::Unit::TestSuite.new
|
58
|
-
Test::Unit::UI::Emacs::TestRunner.new(suite)
|
59
|
-
end
|
60
|
-
end
|
data/test/test-error.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
# Author:: Nathaniel Talbott.
|
2
|
-
# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved.
|
3
|
-
# License:: Ruby license.
|
4
|
-
|
5
|
-
require 'test/unit'
|
6
|
-
|
7
|
-
module Test
|
8
|
-
module Unit
|
9
|
-
class TC_Error < TestCase
|
10
|
-
TF_Exception = Struct.new('TF_Exception', :message, :backtrace)
|
11
|
-
def test_display
|
12
|
-
ex = TF_Exception.new("message1\nmessage2", ['line1', 'line2'])
|
13
|
-
e = Error.new("name", ex)
|
14
|
-
assert_equal("name: #{TF_Exception.name}: message1", e.short_display)
|
15
|
-
assert_equal(<<EOM.strip, e.long_display)
|
16
|
-
Error:
|
17
|
-
name:
|
18
|
-
Struct::TF_Exception: message1
|
19
|
-
message2
|
20
|
-
line1
|
21
|
-
line2
|
22
|
-
EOM
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
data/test/test-failure.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
# Author:: Nathaniel Talbott.
|
2
|
-
# Copyright:: Copyright (c) 2003 Nathaniel Talbott. All rights reserved.
|
3
|
-
# License:: Ruby license.
|
4
|
-
|
5
|
-
require 'test/unit'
|
6
|
-
require 'test/unit/failure'
|
7
|
-
|
8
|
-
module Test::Unit
|
9
|
-
class TestFailure < TestCase
|
10
|
-
def test_display
|
11
|
-
f = Failure.new("name", [%q{location:1 in 'l'}], "message1\nmessage2")
|
12
|
-
assert_equal("name: message1", f.short_display)
|
13
|
-
assert_equal(<<EOM.strip, f.long_display)
|
14
|
-
Failure:
|
15
|
-
name [location:1]:
|
16
|
-
message1
|
17
|
-
message2
|
18
|
-
EOM
|
19
|
-
|
20
|
-
f = Failure.new("name", [%q{location1:2 in 'l1'}, 'location2:1', %q{location3:3 in 'l3'}], "message1\nmessage2")
|
21
|
-
assert_equal("name: message1", f.short_display)
|
22
|
-
assert_equal(<<EOM.strip, f.long_display)
|
23
|
-
Failure:
|
24
|
-
name
|
25
|
-
[location1:2 in 'l1'
|
26
|
-
location2:1
|
27
|
-
location3:3 in 'l3']:
|
28
|
-
message1
|
29
|
-
message2
|
30
|
-
EOM
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,163 +0,0 @@
|
|
1
|
-
# Copyright (C) 2012 Kouhei Sutou <kou@clear-code.com>
|
2
|
-
#
|
3
|
-
# License: Ruby's
|
4
|
-
|
5
|
-
require "test-unit"
|
6
|
-
require "test/unit/fault-location-detector"
|
7
|
-
require "testunit-test-util"
|
8
|
-
|
9
|
-
class TestFaultLocationDetector < Test::Unit::TestCase
|
10
|
-
include TestUnitTestUtil
|
11
|
-
|
12
|
-
def setup
|
13
|
-
@fetcher = Test::Unit::CodeSnippetFetcher.new
|
14
|
-
end
|
15
|
-
|
16
|
-
private
|
17
|
-
def run_test_case(test_case)
|
18
|
-
suite = test_case.suite
|
19
|
-
result = Test::Unit::TestResult.new
|
20
|
-
suite.run(result) {}
|
21
|
-
result.faults[0]
|
22
|
-
end
|
23
|
-
|
24
|
-
def assert_detect(fault, target_line_number)
|
25
|
-
detector = Test::Unit::FaultLocationDetector.new(fault, @fetcher)
|
26
|
-
|
27
|
-
expected_backtrace_entries_until_detected = []
|
28
|
-
fault.location.each do |backtrace_entry|
|
29
|
-
expected_backtrace_entries_until_detected << backtrace_entry
|
30
|
-
_, line_number, = detector.split_backtrace_entry(backtrace_entry)
|
31
|
-
break if target_line_number == line_number
|
32
|
-
end
|
33
|
-
|
34
|
-
actual_backtrace_entries_until_detected = []
|
35
|
-
fault.location.each do |backtrace_entry|
|
36
|
-
actual_backtrace_entries_until_detected << backtrace_entry
|
37
|
-
break if detector.target?(backtrace_entry)
|
38
|
-
end
|
39
|
-
|
40
|
-
assert_equal(expected_backtrace_entries_until_detected,
|
41
|
-
actual_backtrace_entries_until_detected)
|
42
|
-
end
|
43
|
-
|
44
|
-
module AlwaysFailAssertion
|
45
|
-
private
|
46
|
-
def assert_always_failed
|
47
|
-
assert_true(false)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
class TestSourceLocation < self
|
52
|
-
setup
|
53
|
-
def setup_check_source_location
|
54
|
-
unless lambda {}.respond_to?(:source_location)
|
55
|
-
omit("Need Proc#source_location")
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
def test_detected
|
60
|
-
target_line_number = nil
|
61
|
-
test_case = Class.new(Test::Unit::TestCase) do
|
62
|
-
include AlwaysFailAssertion
|
63
|
-
|
64
|
-
test "failed" do
|
65
|
-
target_line_number = __LINE__; assert_always_failed
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
fault = run_test_case(test_case)
|
70
|
-
assert_detect(fault, target_line_number)
|
71
|
-
end
|
72
|
-
|
73
|
-
class TestOneLine < self
|
74
|
-
def test_brace
|
75
|
-
target_line_number = nil
|
76
|
-
test_case = Class.new(Test::Unit::TestCase) do
|
77
|
-
include AlwaysFailAssertion
|
78
|
-
|
79
|
-
test("failed") {target_line_number = __LINE__; assert_always_failed}
|
80
|
-
|
81
|
-
def other_method
|
82
|
-
# body
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
fault = run_test_case(test_case)
|
87
|
-
assert_detect(fault, target_line_number)
|
88
|
-
end
|
89
|
-
|
90
|
-
def test_do_end
|
91
|
-
target_line_number = nil
|
92
|
-
test_case = Class.new(Test::Unit::TestCase) do
|
93
|
-
include AlwaysFailAssertion
|
94
|
-
|
95
|
-
test "failed" do target_line_number = __LINE__; assert_always_failed; end
|
96
|
-
|
97
|
-
def other_method
|
98
|
-
# body
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
fault = run_test_case(test_case)
|
103
|
-
assert_detect(fault, target_line_number)
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
class TestMethodName < self
|
109
|
-
def test_detected
|
110
|
-
test_case = Class.new(Test::Unit::TestCase) do
|
111
|
-
include AlwaysFailAssertion
|
112
|
-
|
113
|
-
class << self
|
114
|
-
def target_line_number
|
115
|
-
@@target_line_number
|
116
|
-
end
|
117
|
-
|
118
|
-
def target_line_number=(line_number)
|
119
|
-
@@target_line_number = line_number
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
def test_failed
|
124
|
-
self.class.target_line_number = __LINE__; assert_always_failed
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
fault = run_test_case(test_case)
|
129
|
-
assert_detect(fault, test_case.target_line_number)
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
class TestInBlock < self
|
134
|
-
def test_in_block
|
135
|
-
test_case = Class.new(Test::Unit::TestCase) do
|
136
|
-
include AlwaysFailAssertion
|
137
|
-
|
138
|
-
class << self
|
139
|
-
def target_line_number
|
140
|
-
@@target_line_number
|
141
|
-
end
|
142
|
-
|
143
|
-
def target_line_number=(line_number)
|
144
|
-
@@target_line_number = line_number
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
def run_yield
|
149
|
-
yield
|
150
|
-
end
|
151
|
-
|
152
|
-
def test_failed
|
153
|
-
run_yield do
|
154
|
-
self.class.target_line_number = __LINE__; assert_always_failed
|
155
|
-
end
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
159
|
-
fault = run_test_case(test_case)
|
160
|
-
assert_detect(fault, test_case.target_line_number)
|
161
|
-
end
|
162
|
-
end
|
163
|
-
end
|
data/test/test-fixture.rb
DELETED
@@ -1,713 +0,0 @@
|
|
1
|
-
class TestUnitFixture < Test::Unit::TestCase
|
2
|
-
module EmptyModule
|
3
|
-
end
|
4
|
-
|
5
|
-
class TestSetup < self
|
6
|
-
def test_without_option
|
7
|
-
expected_setup_calls = [:setup,
|
8
|
-
:custom_setup_method0,
|
9
|
-
:custom_setup_callback0,
|
10
|
-
:custom_setup_method1,
|
11
|
-
:custom_setup_callback1,
|
12
|
-
:custom_setup_method3,
|
13
|
-
:custom_setup_callback3]
|
14
|
-
test_case = assert_setup(expected_setup_calls, [])
|
15
|
-
assert_inherited_setup(expected_setup_calls, test_case)
|
16
|
-
|
17
|
-
assert_inherited_setup([:setup], nil)
|
18
|
-
assert_called_fixtures(expected_setup_calls, test_case)
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_with_before_option
|
22
|
-
expected_setup_calls = [:custom_setup_callback3,
|
23
|
-
:custom_setup_method3,
|
24
|
-
:custom_setup_method0,
|
25
|
-
:custom_setup_callback0,
|
26
|
-
:custom_setup_method1,
|
27
|
-
:custom_setup_callback1,
|
28
|
-
:setup]
|
29
|
-
test_case = assert_setup(expected_setup_calls,
|
30
|
-
[[{:before => :append}],
|
31
|
-
[{:before => :append}],
|
32
|
-
[{:before => :prepend}],
|
33
|
-
[{:before => :prepend}]])
|
34
|
-
assert_inherited_setup(expected_setup_calls, test_case)
|
35
|
-
|
36
|
-
assert_inherited_setup([:setup], nil)
|
37
|
-
assert_called_fixtures(expected_setup_calls, test_case)
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_with_after_option
|
41
|
-
expected_setup_calls = [:setup,
|
42
|
-
:custom_setup_callback3,
|
43
|
-
:custom_setup_method3,
|
44
|
-
:custom_setup_method0,
|
45
|
-
:custom_setup_callback0,
|
46
|
-
:custom_setup_method1,
|
47
|
-
:custom_setup_callback1]
|
48
|
-
test_case = assert_setup(expected_setup_calls,
|
49
|
-
[[{:after => :append}],
|
50
|
-
[{:after => :append}],
|
51
|
-
[{:after => :prepend}],
|
52
|
-
[{:after => :prepend}]])
|
53
|
-
assert_inherited_setup(expected_setup_calls, test_case)
|
54
|
-
|
55
|
-
assert_inherited_setup([:setup], nil)
|
56
|
-
assert_called_fixtures(expected_setup_calls, test_case)
|
57
|
-
end
|
58
|
-
|
59
|
-
def test_with_invalid_option
|
60
|
-
assert_invalid_setup_option(:unknown => true)
|
61
|
-
assert_invalid_setup_option(:before => :unknown)
|
62
|
-
assert_invalid_setup_option(:after => :unknown)
|
63
|
-
end
|
64
|
-
|
65
|
-
def test_with_option_to_inherited
|
66
|
-
expected_setup_calls = [:setup]
|
67
|
-
test_case = assert_setup(expected_setup_calls, nil)
|
68
|
-
assert_inherited_setup([:setup,
|
69
|
-
:custom_setup_method0,
|
70
|
-
:custom_setup_callback0,
|
71
|
-
:custom_setup_method1,
|
72
|
-
:custom_setup_callback1,
|
73
|
-
:custom_setup_method3,
|
74
|
-
:custom_setup_callback3],
|
75
|
-
test_case,
|
76
|
-
[])
|
77
|
-
|
78
|
-
assert_inherited_setup([:setup], nil)
|
79
|
-
assert_called_fixtures(expected_setup_calls, test_case)
|
80
|
-
end
|
81
|
-
|
82
|
-
private
|
83
|
-
def assert_setup_customizable(expected, parent, options)
|
84
|
-
test_case = Class.new(parent || Test::Unit::TestCase) do
|
85
|
-
yield(self, :before) if block_given?
|
86
|
-
|
87
|
-
def called_ids
|
88
|
-
@called_ids ||= []
|
89
|
-
end
|
90
|
-
|
91
|
-
def called(id)
|
92
|
-
called_ids << id
|
93
|
-
end
|
94
|
-
|
95
|
-
def setup
|
96
|
-
called(:setup)
|
97
|
-
end
|
98
|
-
|
99
|
-
setup(*(options[0] || [])) if options
|
100
|
-
def custom_setup_method0
|
101
|
-
called(:custom_setup_method0)
|
102
|
-
end
|
103
|
-
|
104
|
-
if options
|
105
|
-
setup(*(options[0] || [])) do
|
106
|
-
called(:custom_setup_callback0)
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
def custom_setup_method1
|
111
|
-
called(:custom_setup_method1)
|
112
|
-
end
|
113
|
-
setup(*[:custom_setup_method1, *(options[1] || [])]) if options
|
114
|
-
|
115
|
-
if options
|
116
|
-
setup(*(options[1] || [])) do
|
117
|
-
called(:custom_setup_callback1)
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
setup(*(options[2] || [])) if options
|
122
|
-
def custom_setup_method2
|
123
|
-
called(:custom_setup_method2)
|
124
|
-
end
|
125
|
-
unregister_setup(:custom_setup_method2) if options
|
126
|
-
|
127
|
-
if options
|
128
|
-
callback = lambda do
|
129
|
-
called(:custom_setup_callback2)
|
130
|
-
end
|
131
|
-
setup(*(options[2] || []), &callback)
|
132
|
-
unregister_setup(callback)
|
133
|
-
end
|
134
|
-
|
135
|
-
setup(*(options[3] || [])) if options
|
136
|
-
def custom_setup_method3
|
137
|
-
called(:custom_setup_method3)
|
138
|
-
end
|
139
|
-
|
140
|
-
if options
|
141
|
-
setup(*(options[3] || [])) do
|
142
|
-
called(:custom_setup_callback3)
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
def test_nothing
|
147
|
-
end
|
148
|
-
|
149
|
-
yield(self, :after) if block_given?
|
150
|
-
end
|
151
|
-
|
152
|
-
assert_called_fixtures(expected, test_case)
|
153
|
-
test_case
|
154
|
-
end
|
155
|
-
|
156
|
-
def assert_setup(expected, options)
|
157
|
-
_test_case = assert_setup_customizable(expected, nil, options)
|
158
|
-
assert_setup_customizable(expected, nil, options) do |test_case, tag|
|
159
|
-
test_case.send(:include, EmptyModule) if tag == :before
|
160
|
-
end
|
161
|
-
_test_case
|
162
|
-
end
|
163
|
-
|
164
|
-
def assert_inherited_setup(expected, parent, options=nil)
|
165
|
-
_test_case = assert_setup_customizable(expected, parent, options)
|
166
|
-
assert_setup_customizable(expected, parent, options) do |test_case, tag|
|
167
|
-
test_case.send(:include, EmptyModule) if tag == :before
|
168
|
-
end
|
169
|
-
_test_case
|
170
|
-
end
|
171
|
-
|
172
|
-
def assert_invalid_setup_option(option)
|
173
|
-
assert_invalid_option(:setup, option)
|
174
|
-
end
|
175
|
-
end
|
176
|
-
|
177
|
-
class TestCleanup < self
|
178
|
-
def test_without_option
|
179
|
-
expected_cleanup_calls = [:custom_cleanup_callback3,
|
180
|
-
:custom_cleanup_method3,
|
181
|
-
:custom_cleanup_callback1,
|
182
|
-
:custom_cleanup_method1,
|
183
|
-
:custom_cleanup_callback0,
|
184
|
-
:custom_cleanup_method0,
|
185
|
-
:cleanup]
|
186
|
-
test_case = assert_cleanup(expected_cleanup_calls, [])
|
187
|
-
assert_inherited_cleanup(expected_cleanup_calls, test_case)
|
188
|
-
|
189
|
-
assert_inherited_cleanup([:cleanup], nil)
|
190
|
-
assert_called_fixtures(expected_cleanup_calls, test_case)
|
191
|
-
end
|
192
|
-
|
193
|
-
def test_with_before_option
|
194
|
-
expected_cleanup_calls = [:custom_cleanup_callback3,
|
195
|
-
:custom_cleanup_method3,
|
196
|
-
:custom_cleanup_method0,
|
197
|
-
:custom_cleanup_callback0,
|
198
|
-
:custom_cleanup_method1,
|
199
|
-
:custom_cleanup_callback1,
|
200
|
-
:cleanup]
|
201
|
-
test_case = assert_cleanup(expected_cleanup_calls,
|
202
|
-
[[{:before => :append}],
|
203
|
-
[{:before => :append}],
|
204
|
-
[{:before => :prepend}],
|
205
|
-
[{:before => :prepend}]])
|
206
|
-
assert_inherited_cleanup(expected_cleanup_calls, test_case)
|
207
|
-
|
208
|
-
assert_inherited_cleanup([:cleanup], nil)
|
209
|
-
assert_called_fixtures(expected_cleanup_calls, test_case)
|
210
|
-
end
|
211
|
-
|
212
|
-
def test_with_after_option
|
213
|
-
expected_cleanup_calls = [:cleanup,
|
214
|
-
:custom_cleanup_callback3,
|
215
|
-
:custom_cleanup_method3,
|
216
|
-
:custom_cleanup_method0,
|
217
|
-
:custom_cleanup_callback0,
|
218
|
-
:custom_cleanup_method1,
|
219
|
-
:custom_cleanup_callback1]
|
220
|
-
test_case = assert_cleanup(expected_cleanup_calls,
|
221
|
-
[[{:after => :append}],
|
222
|
-
[{:after => :append}],
|
223
|
-
[{:after => :prepend}],
|
224
|
-
[{:after => :prepend}]])
|
225
|
-
assert_inherited_cleanup(expected_cleanup_calls, test_case)
|
226
|
-
|
227
|
-
assert_inherited_cleanup([:cleanup], nil)
|
228
|
-
assert_called_fixtures(expected_cleanup_calls, test_case)
|
229
|
-
end
|
230
|
-
|
231
|
-
def test_with_invalid_option
|
232
|
-
assert_invalid_cleanup_option(:unknown => true)
|
233
|
-
assert_invalid_cleanup_option(:before => :unknown)
|
234
|
-
assert_invalid_cleanup_option(:after => :unknown)
|
235
|
-
end
|
236
|
-
|
237
|
-
def test_with_option_to_inherited
|
238
|
-
expected_cleanup_calls = [:cleanup]
|
239
|
-
test_case = assert_cleanup(expected_cleanup_calls, nil)
|
240
|
-
assert_inherited_cleanup([:custom_cleanup_callback3,
|
241
|
-
:custom_cleanup_method3,
|
242
|
-
:custom_cleanup_callback1,
|
243
|
-
:custom_cleanup_method1,
|
244
|
-
:custom_cleanup_callback0,
|
245
|
-
:custom_cleanup_method0,
|
246
|
-
:cleanup],
|
247
|
-
test_case, [])
|
248
|
-
|
249
|
-
assert_inherited_cleanup([:cleanup], nil)
|
250
|
-
assert_called_fixtures(expected_cleanup_calls, test_case)
|
251
|
-
end
|
252
|
-
|
253
|
-
def test_with_exception
|
254
|
-
test_case = Class.new(Test::Unit::TestCase) do
|
255
|
-
def called_ids
|
256
|
-
@called_ids ||= []
|
257
|
-
end
|
258
|
-
|
259
|
-
def called(id)
|
260
|
-
called_ids << id
|
261
|
-
end
|
262
|
-
|
263
|
-
def cleanup
|
264
|
-
called(:cleanup)
|
265
|
-
raise "cleanup"
|
266
|
-
end
|
267
|
-
|
268
|
-
cleanup
|
269
|
-
def custom_cleanup_method0
|
270
|
-
called(:custom_cleanup_method0)
|
271
|
-
raise "custom_cleanup_method0"
|
272
|
-
end
|
273
|
-
|
274
|
-
cleanup do
|
275
|
-
called(:custom_cleanup_callback0)
|
276
|
-
raise "custom_cleanup_callback0"
|
277
|
-
end
|
278
|
-
|
279
|
-
cleanup
|
280
|
-
def custom_cleanup_method1
|
281
|
-
called(:custom_cleanup_method1)
|
282
|
-
raise "custom_cleanup_method1"
|
283
|
-
end
|
284
|
-
|
285
|
-
cleanup do
|
286
|
-
called(:custom_cleanup_callback1)
|
287
|
-
raise "custom_cleanup_callback1"
|
288
|
-
end
|
289
|
-
|
290
|
-
def test_nothing
|
291
|
-
end
|
292
|
-
end
|
293
|
-
|
294
|
-
assert_called_fixtures([:custom_cleanup_callback1],
|
295
|
-
test_case)
|
296
|
-
end
|
297
|
-
|
298
|
-
private
|
299
|
-
def assert_cleanup_customizable(expected, parent, options)
|
300
|
-
test_case = Class.new(parent || Test::Unit::TestCase) do
|
301
|
-
yield(self, :before) if block_given?
|
302
|
-
|
303
|
-
def called_ids
|
304
|
-
@called_ids ||= []
|
305
|
-
end
|
306
|
-
|
307
|
-
def called(id)
|
308
|
-
called_ids << id
|
309
|
-
end
|
310
|
-
|
311
|
-
def cleanup
|
312
|
-
called(:cleanup)
|
313
|
-
end
|
314
|
-
|
315
|
-
cleanup(*(options[0] || [])) if options
|
316
|
-
def custom_cleanup_method0
|
317
|
-
called(:custom_cleanup_method0)
|
318
|
-
end
|
319
|
-
|
320
|
-
if options
|
321
|
-
cleanup(*(options[0] || [])) do
|
322
|
-
called(:custom_cleanup_callback0)
|
323
|
-
end
|
324
|
-
end
|
325
|
-
|
326
|
-
def custom_cleanup_method1
|
327
|
-
called(:custom_cleanup_method1)
|
328
|
-
end
|
329
|
-
cleanup(*[:custom_cleanup_method1, *(options[1] || [])]) if options
|
330
|
-
|
331
|
-
if options
|
332
|
-
cleanup(*(options[1] || [])) do
|
333
|
-
called(:custom_cleanup_callback1)
|
334
|
-
end
|
335
|
-
end
|
336
|
-
|
337
|
-
cleanup(*(options[2] || [])) if options
|
338
|
-
def custom_cleanup_method2
|
339
|
-
called(:custom_cleanup_method2)
|
340
|
-
end
|
341
|
-
unregister_cleanup(:custom_cleanup_method2) if options
|
342
|
-
|
343
|
-
if options
|
344
|
-
callback = lambda do
|
345
|
-
called(:custom_cleanup_callback2)
|
346
|
-
end
|
347
|
-
cleanup(*(options[2] || []), &callback)
|
348
|
-
unregister_cleanup(callback)
|
349
|
-
end
|
350
|
-
|
351
|
-
cleanup(*(options[3] || [])) if options
|
352
|
-
def custom_cleanup_method3
|
353
|
-
called(:custom_cleanup_method3)
|
354
|
-
end
|
355
|
-
|
356
|
-
if options
|
357
|
-
cleanup(*(options[3] || [])) do
|
358
|
-
called(:custom_cleanup_callback3)
|
359
|
-
end
|
360
|
-
end
|
361
|
-
|
362
|
-
def test_nothing
|
363
|
-
end
|
364
|
-
|
365
|
-
yield(self, :after) if block_given?
|
366
|
-
end
|
367
|
-
|
368
|
-
assert_called_fixtures(expected, test_case)
|
369
|
-
test_case
|
370
|
-
end
|
371
|
-
|
372
|
-
def assert_cleanup(expected, options)
|
373
|
-
assert_cleanup_customizable(expected, nil, options)
|
374
|
-
assert_cleanup_customizable(expected, nil, options) do |test_case, tag|
|
375
|
-
test_case.send(:include, EmptyModule) if tag == :before
|
376
|
-
end
|
377
|
-
end
|
378
|
-
|
379
|
-
def assert_inherited_cleanup(expected, parent, options=nil)
|
380
|
-
assert_cleanup_customizable(expected, parent, options)
|
381
|
-
assert_cleanup_customizable(expected, parent, options) do |test_case, tag|
|
382
|
-
test_case.send(:include, EmptyModule) if tag == :before
|
383
|
-
end
|
384
|
-
end
|
385
|
-
|
386
|
-
def assert_invalid_cleanup_option(option)
|
387
|
-
assert_invalid_option(:cleanup, option)
|
388
|
-
end
|
389
|
-
end
|
390
|
-
|
391
|
-
class TestTeardown < self
|
392
|
-
def test_without_option
|
393
|
-
expected_teardown_calls = [:custom_teardown_callback3,
|
394
|
-
:custom_teardown_method3,
|
395
|
-
:custom_teardown_callback1,
|
396
|
-
:custom_teardown_method1,
|
397
|
-
:custom_teardown_callback0,
|
398
|
-
:custom_teardown_method0,
|
399
|
-
:teardown]
|
400
|
-
test_case = assert_teardown(expected_teardown_calls, [])
|
401
|
-
assert_inherited_teardown(expected_teardown_calls, test_case)
|
402
|
-
|
403
|
-
assert_inherited_teardown([:teardown], nil)
|
404
|
-
assert_called_fixtures(expected_teardown_calls, test_case)
|
405
|
-
end
|
406
|
-
|
407
|
-
def test_with_before_option
|
408
|
-
expected_teardown_calls = [:custom_teardown_callback3,
|
409
|
-
:custom_teardown_method3,
|
410
|
-
:custom_teardown_method0,
|
411
|
-
:custom_teardown_callback0,
|
412
|
-
:custom_teardown_method1,
|
413
|
-
:custom_teardown_callback1,
|
414
|
-
:teardown]
|
415
|
-
test_case = assert_teardown(expected_teardown_calls,
|
416
|
-
[[{:before => :append}],
|
417
|
-
[{:before => :append}],
|
418
|
-
[{:before => :prepend}],
|
419
|
-
[{:before => :prepend}]])
|
420
|
-
assert_inherited_teardown(expected_teardown_calls, test_case)
|
421
|
-
|
422
|
-
assert_inherited_teardown([:teardown], nil)
|
423
|
-
assert_called_fixtures(expected_teardown_calls, test_case)
|
424
|
-
end
|
425
|
-
|
426
|
-
def test_with_after_option
|
427
|
-
expected_teardown_calls = [:teardown,
|
428
|
-
:custom_teardown_callback3,
|
429
|
-
:custom_teardown_method3,
|
430
|
-
:custom_teardown_method0,
|
431
|
-
:custom_teardown_callback0,
|
432
|
-
:custom_teardown_method1,
|
433
|
-
:custom_teardown_callback1]
|
434
|
-
test_case = assert_teardown(expected_teardown_calls,
|
435
|
-
[[{:after => :append}],
|
436
|
-
[{:after => :append}],
|
437
|
-
[{:after => :prepend}],
|
438
|
-
[{:after => :prepend}]])
|
439
|
-
assert_inherited_teardown(expected_teardown_calls, test_case)
|
440
|
-
|
441
|
-
assert_inherited_teardown([:teardown], nil)
|
442
|
-
assert_called_fixtures(expected_teardown_calls, test_case)
|
443
|
-
end
|
444
|
-
|
445
|
-
def test_with_invalid_option
|
446
|
-
assert_invalid_teardown_option(:unknown => true)
|
447
|
-
assert_invalid_teardown_option(:before => :unknown)
|
448
|
-
assert_invalid_teardown_option(:after => :unknown)
|
449
|
-
end
|
450
|
-
|
451
|
-
def test_with_option_to_inherited
|
452
|
-
expected_teardown_calls = [:teardown]
|
453
|
-
test_case = assert_teardown(expected_teardown_calls, nil)
|
454
|
-
assert_inherited_teardown([:custom_teardown_callback3,
|
455
|
-
:custom_teardown_method3,
|
456
|
-
:custom_teardown_callback1,
|
457
|
-
:custom_teardown_method1,
|
458
|
-
:custom_teardown_callback0,
|
459
|
-
:custom_teardown_method0,
|
460
|
-
:teardown],
|
461
|
-
test_case, [])
|
462
|
-
|
463
|
-
assert_inherited_teardown([:teardown], nil)
|
464
|
-
assert_called_fixtures(expected_teardown_calls, test_case)
|
465
|
-
end
|
466
|
-
|
467
|
-
def test_with_exception
|
468
|
-
test_case = Class.new(Test::Unit::TestCase) do
|
469
|
-
def called_ids
|
470
|
-
@called_ids ||= []
|
471
|
-
end
|
472
|
-
|
473
|
-
def called(id)
|
474
|
-
called_ids << id
|
475
|
-
end
|
476
|
-
|
477
|
-
def teardown
|
478
|
-
called(:teardown)
|
479
|
-
raise "teardown"
|
480
|
-
end
|
481
|
-
|
482
|
-
teardown
|
483
|
-
def custom_teardown_method0
|
484
|
-
called(:custom_teardown_method0)
|
485
|
-
raise "custom_teardown_method0"
|
486
|
-
end
|
487
|
-
|
488
|
-
teardown do
|
489
|
-
called(:custom_teardown_callback0)
|
490
|
-
raise "custom_teardown_callback0"
|
491
|
-
end
|
492
|
-
|
493
|
-
teardown
|
494
|
-
def custom_teardown_method1
|
495
|
-
called(:custom_teardown_method1)
|
496
|
-
raise "custom_teardown_method1"
|
497
|
-
end
|
498
|
-
|
499
|
-
teardown do
|
500
|
-
called(:custom_teardown_callback1)
|
501
|
-
raise "custom_teardown_callback1"
|
502
|
-
end
|
503
|
-
|
504
|
-
def test_nothing
|
505
|
-
end
|
506
|
-
end
|
507
|
-
|
508
|
-
assert_called_fixtures([:custom_teardown_callback1,
|
509
|
-
:custom_teardown_method1,
|
510
|
-
:custom_teardown_callback0,
|
511
|
-
:custom_teardown_method0,
|
512
|
-
:teardown],
|
513
|
-
test_case)
|
514
|
-
end
|
515
|
-
|
516
|
-
def test_nested
|
517
|
-
called = []
|
518
|
-
parent_test_case = Class.new(Test::Unit::TestCase) do
|
519
|
-
teardown do
|
520
|
-
called << :parent
|
521
|
-
end
|
522
|
-
end
|
523
|
-
|
524
|
-
child_test_case = Class.new(parent_test_case) do
|
525
|
-
teardown do
|
526
|
-
called << :child
|
527
|
-
end
|
528
|
-
|
529
|
-
def test_nothing
|
530
|
-
end
|
531
|
-
end
|
532
|
-
|
533
|
-
run_test_nothing(child_test_case)
|
534
|
-
assert_equal([:child, :parent],
|
535
|
-
called)
|
536
|
-
end
|
537
|
-
|
538
|
-
def test_setup_with_block
|
539
|
-
test_case = Class.new(Test::Unit::TestCase) do
|
540
|
-
def called_ids
|
541
|
-
@called_ids ||= []
|
542
|
-
end
|
543
|
-
|
544
|
-
def called(id)
|
545
|
-
called_ids << id
|
546
|
-
end
|
547
|
-
|
548
|
-
setup
|
549
|
-
def setup1
|
550
|
-
called(:setup1)
|
551
|
-
begin
|
552
|
-
yield
|
553
|
-
called(:setup1_after_yield)
|
554
|
-
ensure
|
555
|
-
called(:setup1_teardown)
|
556
|
-
end
|
557
|
-
end
|
558
|
-
|
559
|
-
setup
|
560
|
-
def setup2
|
561
|
-
called(:setup2)
|
562
|
-
begin
|
563
|
-
yield
|
564
|
-
called(:setup2_after_yield)
|
565
|
-
ensure
|
566
|
-
called(:setup2_teardown)
|
567
|
-
end
|
568
|
-
end
|
569
|
-
|
570
|
-
def teardown
|
571
|
-
called(:teardown)
|
572
|
-
end
|
573
|
-
|
574
|
-
def test_nothing
|
575
|
-
called(:test)
|
576
|
-
flunk
|
577
|
-
called(:test_after_failure)
|
578
|
-
end
|
579
|
-
end
|
580
|
-
|
581
|
-
assert_called_fixtures([
|
582
|
-
:setup1,
|
583
|
-
:setup2,
|
584
|
-
:test,
|
585
|
-
:setup2_teardown,
|
586
|
-
:setup1_teardown,
|
587
|
-
:teardown,
|
588
|
-
],
|
589
|
-
test_case)
|
590
|
-
end
|
591
|
-
|
592
|
-
private
|
593
|
-
def assert_teardown_customizable(expected, parent, options)
|
594
|
-
test_case = Class.new(parent || Test::Unit::TestCase) do
|
595
|
-
yield(self, :before) if block_given?
|
596
|
-
|
597
|
-
def called_ids
|
598
|
-
@called_ids ||= []
|
599
|
-
end
|
600
|
-
|
601
|
-
def called(id)
|
602
|
-
called_ids << id
|
603
|
-
end
|
604
|
-
|
605
|
-
def teardown
|
606
|
-
called(:teardown)
|
607
|
-
end
|
608
|
-
|
609
|
-
teardown(*(options[0] || [])) if options
|
610
|
-
def custom_teardown_method0
|
611
|
-
called(:custom_teardown_method0)
|
612
|
-
end
|
613
|
-
|
614
|
-
if options
|
615
|
-
teardown(*(options[0] || [])) do
|
616
|
-
called(:custom_teardown_callback0)
|
617
|
-
end
|
618
|
-
end
|
619
|
-
|
620
|
-
def custom_teardown_method1
|
621
|
-
called(:custom_teardown_method1)
|
622
|
-
end
|
623
|
-
teardown(*[:custom_teardown_method1, *(options[1] || [])]) if options
|
624
|
-
|
625
|
-
if options
|
626
|
-
teardown(*(options[1] || [])) do
|
627
|
-
called(:custom_teardown_callback1)
|
628
|
-
end
|
629
|
-
end
|
630
|
-
|
631
|
-
teardown(*(options[2] || [])) if options
|
632
|
-
def custom_teardown_method2
|
633
|
-
called(:custom_teardown_method2)
|
634
|
-
end
|
635
|
-
unregister_teardown(:custom_teardown_method2) if options
|
636
|
-
|
637
|
-
if options
|
638
|
-
callback = lambda do
|
639
|
-
called(:custom_teardown_callback2)
|
640
|
-
end
|
641
|
-
teardown(*(options[2] || []), &callback)
|
642
|
-
unregister_teardown(callback)
|
643
|
-
end
|
644
|
-
|
645
|
-
teardown(*(options[3] || [])) if options
|
646
|
-
def custom_teardown_method3
|
647
|
-
called(:custom_teardown_method3)
|
648
|
-
end
|
649
|
-
|
650
|
-
if options
|
651
|
-
teardown(*(options[3] || [])) do
|
652
|
-
called(:custom_teardown_callback3)
|
653
|
-
end
|
654
|
-
end
|
655
|
-
|
656
|
-
def test_nothing
|
657
|
-
end
|
658
|
-
|
659
|
-
yield(self, :after) if block_given?
|
660
|
-
end
|
661
|
-
|
662
|
-
assert_called_fixtures(expected, test_case)
|
663
|
-
test_case
|
664
|
-
end
|
665
|
-
|
666
|
-
def assert_teardown(expected, options)
|
667
|
-
assert_teardown_customizable(expected, nil, options)
|
668
|
-
assert_teardown_customizable(expected, nil, options) do |test_case, tag|
|
669
|
-
test_case.send(:include, EmptyModule) if tag == :before
|
670
|
-
end
|
671
|
-
end
|
672
|
-
|
673
|
-
def assert_inherited_teardown(expected, parent, options=nil)
|
674
|
-
assert_teardown_customizable(expected, parent, options)
|
675
|
-
assert_teardown_customizable(expected, parent, options) do |test_case, tag|
|
676
|
-
test_case.send(:include, EmptyModule) if tag == :before
|
677
|
-
end
|
678
|
-
end
|
679
|
-
|
680
|
-
def assert_invalid_teardown_option(option)
|
681
|
-
assert_invalid_option(:teardown, option)
|
682
|
-
end
|
683
|
-
end
|
684
|
-
|
685
|
-
private
|
686
|
-
def run_test_nothing(test_case)
|
687
|
-
test = test_case.new("test_nothing")
|
688
|
-
test.run(Test::Unit::TestResult.new) {}
|
689
|
-
test
|
690
|
-
end
|
691
|
-
|
692
|
-
def assert_called_fixtures(expected, test_case)
|
693
|
-
test = run_test_nothing(test_case)
|
694
|
-
assert_equal(expected, test.called_ids)
|
695
|
-
end
|
696
|
-
|
697
|
-
def assert_invalid_option(fixture_type, option)
|
698
|
-
exception = assert_raise(ArgumentError) do
|
699
|
-
Class.new(Test::Unit::TestCase) do
|
700
|
-
def test_nothing
|
701
|
-
end
|
702
|
-
|
703
|
-
send(fixture_type, option)
|
704
|
-
def fixture
|
705
|
-
end
|
706
|
-
end
|
707
|
-
end
|
708
|
-
assert_equal("must be {:before => :prepend}, {:before => :append}, " +
|
709
|
-
"{:after => :prepend} or {:after => :append}" +
|
710
|
-
": #{option.inspect}",
|
711
|
-
exception.message)
|
712
|
-
end
|
713
|
-
end
|