test-unit 2.4.3 → 2.4.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/test/unit/assertions.rb +5 -1
- data/lib/test/unit/fixture.rb +95 -82
- data/lib/test/unit/testcase.rb +31 -1
- data/lib/test/unit/ui/console/testrunner.rb +11 -2
- data/lib/test/unit/version.rb +1 -1
- data/test/test-assertions.rb +6 -0
- data/test/test-fixture.rb +520 -375
- metadata +54 -77
data/lib/test/unit/assertions.rb
CHANGED
@@ -753,7 +753,11 @@ EOT
|
|
753
753
|
message)
|
754
754
|
assert_block(full_message) do
|
755
755
|
normalized_expected_float = expected_float.to_f
|
756
|
-
|
756
|
+
if normalized_expected_float.zero?
|
757
|
+
delta = epsilon.to_f ** 2
|
758
|
+
else
|
759
|
+
delta = normalized_expected_float * epsilon.to_f
|
760
|
+
end
|
757
761
|
(normalized_expected_float - actual_float.to_f).abs <= delta
|
758
762
|
end
|
759
763
|
end
|
data/lib/test/unit/fixture.rb
CHANGED
@@ -6,12 +6,11 @@ module Test
|
|
6
6
|
base.extend(ClassMethods)
|
7
7
|
|
8
8
|
[:setup, :cleanup, :teardown].each do |fixture|
|
9
|
-
observer =
|
9
|
+
observer = lambda do |test_case, _, _, value, callback|
|
10
10
|
if value.nil?
|
11
|
-
test_case.send("unregister_#{fixture}
|
11
|
+
test_case.send("unregister_#{fixture}_callback", callback)
|
12
12
|
else
|
13
|
-
test_case.send("register_#{fixture}
|
14
|
-
value)
|
13
|
+
test_case.send("register_#{fixture}_callback", callback, value)
|
15
14
|
end
|
16
15
|
end
|
17
16
|
base.register_attribute_observer(fixture, &observer)
|
@@ -20,89 +19,92 @@ module Test
|
|
20
19
|
end
|
21
20
|
|
22
21
|
module ClassMethods
|
23
|
-
def setup(*method_names)
|
24
|
-
register_fixture(:setup, *method_names)
|
22
|
+
def setup(*method_names, &callback)
|
23
|
+
register_fixture(:setup, *method_names, &callback)
|
25
24
|
end
|
26
25
|
|
27
|
-
def unregister_setup(*
|
28
|
-
unregister_fixture(:setup, *
|
26
|
+
def unregister_setup(*method_names_or_callbacks)
|
27
|
+
unregister_fixture(:setup, *method_names_or_callbacks)
|
29
28
|
end
|
30
29
|
|
31
|
-
def cleanup(*method_names)
|
32
|
-
register_fixture(:cleanup, *method_names)
|
30
|
+
def cleanup(*method_names, &callback)
|
31
|
+
register_fixture(:cleanup, *method_names, &callback)
|
33
32
|
end
|
34
33
|
|
35
|
-
def unregister_cleanup(*
|
36
|
-
unregister_fixture(:cleanup, *
|
34
|
+
def unregister_cleanup(*method_names_or_callbacks)
|
35
|
+
unregister_fixture(:cleanup, *method_names_or_callbacks)
|
37
36
|
end
|
38
37
|
|
39
|
-
def teardown(*method_names)
|
40
|
-
register_fixture(:teardown, *method_names)
|
38
|
+
def teardown(*method_names, &callback)
|
39
|
+
register_fixture(:teardown, *method_names, &callback)
|
41
40
|
end
|
42
41
|
|
43
|
-
def unregister_teardown(*
|
44
|
-
unregister_fixture(:teardown, *
|
42
|
+
def unregister_teardown(*method_names_or_callbacks)
|
43
|
+
unregister_fixture(:teardown, *method_names_or_callbacks)
|
45
44
|
end
|
46
45
|
|
47
|
-
def
|
48
|
-
|
46
|
+
def register_setup_callback(method_name_or_callback, options)
|
47
|
+
register_fixture_callback(:setup, method_name_or_callback,
|
48
|
+
options, :after, :append)
|
49
49
|
end
|
50
50
|
|
51
|
-
def
|
52
|
-
|
51
|
+
def unregister_setup_callback(method_name_or_callback)
|
52
|
+
unregister_fixture_callback(:setup, method_name_or_callback)
|
53
53
|
end
|
54
54
|
|
55
|
-
def
|
56
|
-
|
57
|
-
|
55
|
+
def register_cleanup_callback(method_name_or_callback, options)
|
56
|
+
register_fixture_callback(:cleanup, method_name_or_callback,
|
57
|
+
options, :before, :prepend)
|
58
58
|
end
|
59
59
|
|
60
|
-
def
|
61
|
-
|
60
|
+
def unregister_cleanup_callback(method_name_or_callback)
|
61
|
+
unregister_fixture_callback(:cleanup, method_name_or_callback)
|
62
62
|
end
|
63
63
|
|
64
|
-
def
|
65
|
-
|
66
|
-
|
64
|
+
def register_teardown_callback(method_name_or_callback, options)
|
65
|
+
register_fixture_callback(:teardown, method_name_or_callback,
|
66
|
+
options, :before, :prepend)
|
67
67
|
end
|
68
68
|
|
69
|
-
def
|
70
|
-
|
69
|
+
def unregister_teardown_callback(method_name_or_callback)
|
70
|
+
unregister_fixture_callback(:teardown, method_name_or_callback)
|
71
71
|
end
|
72
72
|
|
73
|
-
def
|
74
|
-
|
73
|
+
def before_setup_callbacks
|
74
|
+
collect_fixture_callbacks(:setup, :before)
|
75
75
|
end
|
76
76
|
|
77
|
-
def
|
78
|
-
|
77
|
+
def after_setup_callbacks
|
78
|
+
collect_fixture_callbacks(:setup, :after)
|
79
79
|
end
|
80
80
|
|
81
|
-
def
|
82
|
-
|
81
|
+
def before_cleanup_callbacks
|
82
|
+
collect_fixture_callbacks(:cleanup, :before)
|
83
83
|
end
|
84
84
|
|
85
|
-
def
|
86
|
-
|
85
|
+
def after_cleanup_callbacks
|
86
|
+
collect_fixture_callbacks(:cleanup, :after)
|
87
87
|
end
|
88
88
|
|
89
|
-
def
|
90
|
-
|
89
|
+
def before_teardown_callbacks
|
90
|
+
collect_fixture_callbacks(:teardown, :before)
|
91
91
|
end
|
92
92
|
|
93
|
-
def
|
94
|
-
|
93
|
+
def after_teardown_callbacks
|
94
|
+
collect_fixture_callbacks(:teardown, :after)
|
95
95
|
end
|
96
96
|
|
97
97
|
private
|
98
|
-
def register_fixture(fixture, *method_names)
|
98
|
+
def register_fixture(fixture, *method_names, &callback)
|
99
99
|
options = {}
|
100
100
|
options = method_names.pop if method_names.last.is_a?(Hash)
|
101
|
-
|
101
|
+
callbacks = method_names
|
102
|
+
callbacks << callback if callback
|
103
|
+
attribute(fixture, options, *callbacks)
|
102
104
|
end
|
103
105
|
|
104
|
-
def unregister_fixture(fixture, *
|
105
|
-
attribute(fixture, nil, *
|
106
|
+
def unregister_fixture(fixture, *method_names_or_callbacks)
|
107
|
+
attribute(fixture, nil, *method_names_or_callbacks)
|
106
108
|
end
|
107
109
|
|
108
110
|
def valid_register_fixture_options?(options)
|
@@ -114,27 +116,27 @@ module Test
|
|
114
116
|
[:prepend, :append].include?(options[key])
|
115
117
|
end
|
116
118
|
|
117
|
-
def
|
118
|
-
|
119
|
+
def add_fixture_callback(how, variable_name, method_name_or_callback)
|
120
|
+
callbacks = instance_eval("#{variable_name} ||= []")
|
119
121
|
|
120
122
|
if how == :prepend
|
121
|
-
|
123
|
+
callbacks = [method_name_or_callback] | callbacks
|
122
124
|
else
|
123
|
-
|
125
|
+
callbacks = callbacks | [method_name_or_callback]
|
124
126
|
end
|
125
|
-
instance_variable_set(variable_name,
|
127
|
+
instance_variable_set(variable_name, callbacks)
|
126
128
|
end
|
127
129
|
|
128
|
-
def
|
129
|
-
"@#{order}_#{fixture}
|
130
|
+
def registered_callbacks_variable_name(fixture, order)
|
131
|
+
"@#{order}_#{fixture}_callbacks"
|
130
132
|
end
|
131
133
|
|
132
|
-
def
|
133
|
-
"@unregistered_#{fixture}
|
134
|
+
def unregistered_callbacks_variable_name(fixture)
|
135
|
+
"@unregistered_#{fixture}_callbacks"
|
134
136
|
end
|
135
137
|
|
136
|
-
def
|
137
|
-
|
138
|
+
def register_fixture_callback(fixture, method_name_or_callback, options,
|
139
|
+
default_order, default_how)
|
138
140
|
unless valid_register_fixture_options?(options)
|
139
141
|
message = "must be {:before => :prepend}, " +
|
140
142
|
"{:before => :append}, {:after => :prepend} or " +
|
@@ -147,29 +149,29 @@ module Test
|
|
147
149
|
else
|
148
150
|
order, how = options.to_a.first
|
149
151
|
end
|
150
|
-
variable_name =
|
151
|
-
|
152
|
+
variable_name = registered_callbacks_variable_name(fixture, order)
|
153
|
+
add_fixture_callback(how, variable_name, method_name_or_callback)
|
152
154
|
end
|
153
155
|
|
154
|
-
def
|
155
|
-
variable_name =
|
156
|
-
|
156
|
+
def unregister_fixture_callback(fixture, method_name_or_callback)
|
157
|
+
variable_name = unregistered_callbacks_variable_name(fixture)
|
158
|
+
add_fixture_callback(:append, variable_name, method_name_or_callback)
|
157
159
|
end
|
158
160
|
|
159
|
-
def
|
160
|
-
|
161
|
-
|
162
|
-
|
161
|
+
def collect_fixture_callbacks(fixture, order)
|
162
|
+
callbacks_variable = registered_callbacks_variable_name(fixture, order)
|
163
|
+
unregistered_callbacks_variable =
|
164
|
+
unregistered_callbacks_variable_name(fixture)
|
163
165
|
|
164
166
|
base_index = ancestors.index(Fixture)
|
165
167
|
interested_ancestors = ancestors[0, base_index].reverse
|
166
168
|
interested_ancestors.inject([]) do |result, ancestor|
|
167
169
|
if ancestor.is_a?(Class)
|
168
170
|
ancestor.class_eval do
|
169
|
-
|
170
|
-
|
171
|
-
instance_eval("#{
|
172
|
-
(result |
|
171
|
+
callbacks = instance_eval("#{callbacks_variable} ||= []")
|
172
|
+
unregistered_callbacks =
|
173
|
+
instance_eval("#{unregistered_callbacks_variable} ||= []")
|
174
|
+
(result | callbacks) - unregistered_callbacks
|
173
175
|
end
|
174
176
|
else
|
175
177
|
result
|
@@ -181,21 +183,32 @@ module Test
|
|
181
183
|
private
|
182
184
|
def run_fixture(fixture, options={})
|
183
185
|
[
|
184
|
-
self.class.send("before_#{fixture}
|
186
|
+
self.class.send("before_#{fixture}_callbacks"),
|
185
187
|
fixture,
|
186
|
-
self.class.send("after_#{fixture}
|
187
|
-
].flatten.each do |
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
188
|
+
self.class.send("after_#{fixture}_callbacks")
|
189
|
+
].flatten.each do |method_name_or_callback|
|
190
|
+
run_fixture_callback(method_name_or_callback, options)
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
def run_fixture_callback(method_name_or_callback, options)
|
195
|
+
if method_name_or_callback.respond_to?(:call)
|
196
|
+
callback = lambda do
|
197
|
+
instance_eval(&method_name_or_callback)
|
198
|
+
end
|
199
|
+
else
|
200
|
+
return unless respond_to?(method_name_or_callback, true)
|
201
|
+
callback = lambda do
|
202
|
+
send(method_name_or_callback)
|
197
203
|
end
|
198
204
|
end
|
205
|
+
|
206
|
+
begin
|
207
|
+
callback.call
|
208
|
+
rescue Exception
|
209
|
+
raise unless options[:handle_exception]
|
210
|
+
raise unless handle_exception($!)
|
211
|
+
end
|
199
212
|
end
|
200
213
|
|
201
214
|
def run_setup
|
data/lib/test/unit/testcase.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
# Author:: Nathaniel Talbott.
|
4
4
|
# Copyright::
|
5
5
|
# * Copyright (c) 2000-2003 Nathaniel Talbott. All rights reserved.
|
6
|
-
# * Copyright (c) 2008-
|
6
|
+
# * Copyright (c) 2008-2012 Kouhei Sutou <tt><kou@clear-code.com></tt>
|
7
7
|
# License:: Ruby license.
|
8
8
|
|
9
9
|
require 'test/unit/attribute'
|
@@ -360,11 +360,19 @@ module Test
|
|
360
360
|
# ...
|
361
361
|
# end
|
362
362
|
#
|
363
|
+
# setup do
|
364
|
+
# ... # setup callback1
|
365
|
+
# end
|
366
|
+
#
|
363
367
|
# setup
|
364
368
|
# def my_setup2
|
365
369
|
# ...
|
366
370
|
# end
|
367
371
|
#
|
372
|
+
# setup do
|
373
|
+
# ... # setup callback2
|
374
|
+
# end
|
375
|
+
#
|
368
376
|
# def test_my_class
|
369
377
|
# ...
|
370
378
|
# end
|
@@ -373,7 +381,9 @@ module Test
|
|
373
381
|
# Here is a call order:
|
374
382
|
# * setup
|
375
383
|
# * my_setup1
|
384
|
+
# * setup callback1
|
376
385
|
# * my_setup2
|
386
|
+
# * setup callback2
|
377
387
|
# * test_my_class
|
378
388
|
def setup
|
379
389
|
end
|
@@ -395,11 +405,19 @@ module Test
|
|
395
405
|
# ...
|
396
406
|
# end
|
397
407
|
#
|
408
|
+
# cleanup do
|
409
|
+
# ... # cleanup callback1
|
410
|
+
# end
|
411
|
+
#
|
398
412
|
# cleanup
|
399
413
|
# def my_cleanup2
|
400
414
|
# ...
|
401
415
|
# end
|
402
416
|
#
|
417
|
+
# cleanup do
|
418
|
+
# ... # cleanup callback2
|
419
|
+
# end
|
420
|
+
#
|
403
421
|
# def test_my_class
|
404
422
|
# ...
|
405
423
|
# end
|
@@ -407,7 +425,9 @@ module Test
|
|
407
425
|
#
|
408
426
|
# Here is a call order:
|
409
427
|
# * test_my_class
|
428
|
+
# * cleanup callback2
|
410
429
|
# * my_cleanup2
|
430
|
+
# * cleanup callback1
|
411
431
|
# * my_cleanup1
|
412
432
|
# * cleanup
|
413
433
|
def cleanup
|
@@ -428,11 +448,19 @@ module Test
|
|
428
448
|
# ...
|
429
449
|
# end
|
430
450
|
#
|
451
|
+
# teardown do
|
452
|
+
# ... # teardown callback1
|
453
|
+
# end
|
454
|
+
#
|
431
455
|
# teardown
|
432
456
|
# def my_teardown2
|
433
457
|
# ...
|
434
458
|
# end
|
435
459
|
#
|
460
|
+
# teardown do
|
461
|
+
# ... # teardown callback2
|
462
|
+
# end
|
463
|
+
#
|
436
464
|
# def test_my_class
|
437
465
|
# ...
|
438
466
|
# end
|
@@ -440,7 +468,9 @@ module Test
|
|
440
468
|
#
|
441
469
|
# Here is a call order:
|
442
470
|
# * test_my_class
|
471
|
+
# * teardown callback2
|
443
472
|
# * my_teardown2
|
473
|
+
# * teardown callback1
|
444
474
|
# * my_teardown1
|
445
475
|
# * teardown
|
446
476
|
def teardown
|
@@ -361,16 +361,25 @@ module Test
|
|
361
361
|
end
|
362
362
|
end
|
363
363
|
|
364
|
+
def output_progress_in_detail_marker(fault)
|
365
|
+
if @progress_row_max > 0
|
366
|
+
output("=" * @progress_row_max, fault_color(fault))
|
367
|
+
else
|
368
|
+
nl
|
369
|
+
end
|
370
|
+
end
|
371
|
+
|
364
372
|
def output_progress_in_detail(fault)
|
365
373
|
return if @output_level == SILENT
|
366
374
|
nl
|
367
|
-
|
375
|
+
output_progress_in_detail_marker(fault)
|
368
376
|
if categorize_fault(fault) == :need_detail_faults
|
369
377
|
output_fault_in_detail(fault)
|
370
378
|
else
|
371
379
|
output_fault_in_short(fault)
|
372
380
|
end
|
373
|
-
|
381
|
+
output_progress_in_detail_marker(fault)
|
382
|
+
@progress_row = 0
|
374
383
|
end
|
375
384
|
|
376
385
|
def output?(level)
|
data/lib/test/unit/version.rb
CHANGED
data/test/test-assertions.rb
CHANGED
@@ -1542,6 +1542,12 @@ EOM
|
|
1542
1542
|
end
|
1543
1543
|
end
|
1544
1544
|
|
1545
|
+
def test_pass_zero_expected
|
1546
|
+
check_nothing_fails do
|
1547
|
+
assert_in_epsilon(0, 0.00000001)
|
1548
|
+
end
|
1549
|
+
end
|
1550
|
+
|
1545
1551
|
def test_fail_with_message
|
1546
1552
|
check_fails("message.\n" +
|
1547
1553
|
"<10000> -/+ (<10000> * <0.1>)[1000.0] " +
|
data/test/test-fixture.rb
CHANGED
@@ -2,460 +2,617 @@ class TestUnitFixture < Test::Unit::TestCase
|
|
2
2
|
module EmptyModule
|
3
3
|
end
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
16
20
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
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
|
32
39
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
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
|
48
58
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
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
|
54
64
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
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
|
68
81
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
:cleanup]
|
74
|
-
test_case = assert_cleanup(expected_cleanup_calls, [])
|
75
|
-
assert_inherited_cleanup(expected_cleanup_calls, test_case)
|
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?
|
76
86
|
|
77
|
-
|
78
|
-
|
79
|
-
|
87
|
+
def called_ids
|
88
|
+
@called_ids ||= []
|
89
|
+
end
|
80
90
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
:custom_cleanup_method1,
|
85
|
-
:cleanup]
|
86
|
-
test_case = assert_cleanup(expected_cleanup_calls,
|
87
|
-
[[{:before => :append}],
|
88
|
-
[{:before => :append}],
|
89
|
-
[{:before => :prepend}],
|
90
|
-
[{:before => :prepend}]])
|
91
|
-
assert_inherited_cleanup(expected_cleanup_calls, test_case)
|
92
|
-
|
93
|
-
assert_inherited_cleanup([:cleanup], nil)
|
94
|
-
assert_called_fixtures(expected_cleanup_calls, test_case)
|
95
|
-
end
|
91
|
+
def called(id)
|
92
|
+
called_ids << id
|
93
|
+
end
|
96
94
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
:custom_cleanup_method0,
|
101
|
-
:custom_cleanup_method1]
|
102
|
-
test_case = assert_cleanup(expected_cleanup_calls,
|
103
|
-
[[{:after => :append}],
|
104
|
-
[{:after => :append}],
|
105
|
-
[{:after => :prepend}],
|
106
|
-
[{:after => :prepend}]])
|
107
|
-
assert_inherited_cleanup(expected_cleanup_calls, test_case)
|
108
|
-
|
109
|
-
assert_inherited_cleanup([:cleanup], nil)
|
110
|
-
assert_called_fixtures(expected_cleanup_calls, test_case)
|
111
|
-
end
|
95
|
+
def setup
|
96
|
+
called(:setup)
|
97
|
+
end
|
112
98
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
end
|
99
|
+
setup(*(options[0] || [])) if options
|
100
|
+
def custom_setup_method0
|
101
|
+
called(:custom_setup_method0)
|
102
|
+
end
|
118
103
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
:custom_cleanup_method0,
|
125
|
-
:cleanup],
|
126
|
-
test_case, [])
|
127
|
-
|
128
|
-
assert_inherited_cleanup([:cleanup], nil)
|
129
|
-
assert_called_fixtures(expected_cleanup_calls, test_case)
|
130
|
-
end
|
104
|
+
if options
|
105
|
+
setup(*(options[0] || [])) do
|
106
|
+
called(:custom_setup_callback0)
|
107
|
+
end
|
108
|
+
end
|
131
109
|
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
end
|
110
|
+
def custom_setup_method1
|
111
|
+
called(:custom_setup_method1)
|
112
|
+
end
|
113
|
+
setup(*[:custom_setup_method1, *(options[1] || [])]) if options
|
137
114
|
|
138
|
-
|
139
|
-
|
140
|
-
|
115
|
+
if options
|
116
|
+
setup(*(options[1] || [])) do
|
117
|
+
called(:custom_setup_callback1)
|
118
|
+
end
|
119
|
+
end
|
141
120
|
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
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
|
146
134
|
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
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?
|
151
150
|
end
|
152
151
|
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
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
|
157
160
|
end
|
161
|
+
_test_case
|
162
|
+
end
|
158
163
|
|
159
|
-
|
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
|
160
168
|
end
|
169
|
+
_test_case
|
161
170
|
end
|
162
171
|
|
163
|
-
|
164
|
-
|
172
|
+
def assert_invalid_setup_option(option)
|
173
|
+
assert_invalid_option(:setup, option)
|
174
|
+
end
|
165
175
|
end
|
166
176
|
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
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
|
174
192
|
|
175
|
-
|
176
|
-
|
177
|
-
|
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
|
178
211
|
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
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
|
194
230
|
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
test_case = assert_teardown(expected_teardown_calls,
|
201
|
-
[[{:after => :append}],
|
202
|
-
[{:after => :append}],
|
203
|
-
[{:after => :prepend}],
|
204
|
-
[{:after => :prepend}]])
|
205
|
-
assert_inherited_teardown(expected_teardown_calls, test_case)
|
206
|
-
|
207
|
-
assert_inherited_teardown([:teardown], nil)
|
208
|
-
assert_called_fixtures(expected_teardown_calls, test_case)
|
209
|
-
end
|
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
|
210
236
|
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
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
|
216
252
|
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
:custom_teardown_method0,
|
223
|
-
:teardown],
|
224
|
-
test_case, [])
|
225
|
-
|
226
|
-
assert_inherited_teardown([:teardown], nil)
|
227
|
-
assert_called_fixtures(expected_teardown_calls, test_case)
|
228
|
-
end
|
253
|
+
def test_with_exception
|
254
|
+
test_case = Class.new(Test::Unit::TestCase) do
|
255
|
+
def called_ids
|
256
|
+
@called_ids ||= []
|
257
|
+
end
|
229
258
|
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
@called_ids ||= []
|
234
|
-
end
|
259
|
+
def called(id)
|
260
|
+
called_ids << id
|
261
|
+
end
|
235
262
|
|
236
|
-
|
237
|
-
|
238
|
-
|
263
|
+
def cleanup
|
264
|
+
called(:cleanup)
|
265
|
+
raise "cleanup"
|
266
|
+
end
|
239
267
|
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
268
|
+
cleanup
|
269
|
+
def custom_cleanup_method0
|
270
|
+
called(:custom_cleanup_method0)
|
271
|
+
raise "custom_cleanup_method0"
|
272
|
+
end
|
244
273
|
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
end
|
274
|
+
cleanup do
|
275
|
+
called(:custom_cleanup_callback0)
|
276
|
+
raise "custom_cleanup_callback0"
|
277
|
+
end
|
250
278
|
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
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
|
256
289
|
|
257
|
-
|
290
|
+
def test_nothing
|
291
|
+
end
|
258
292
|
end
|
293
|
+
|
294
|
+
assert_called_fixtures([:custom_cleanup_callback1],
|
295
|
+
test_case)
|
259
296
|
end
|
260
297
|
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
end
|
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?
|
266
302
|
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
test.run(Test::Unit::TestResult.new) {}
|
271
|
-
assert_equal(expected, test.called_ids)
|
272
|
-
end
|
303
|
+
def called_ids
|
304
|
+
@called_ids ||= []
|
305
|
+
end
|
273
306
|
|
274
|
-
|
275
|
-
|
276
|
-
|
307
|
+
def called(id)
|
308
|
+
called_ids << id
|
309
|
+
end
|
277
310
|
|
278
|
-
|
279
|
-
|
280
|
-
|
311
|
+
def cleanup
|
312
|
+
called(:cleanup)
|
313
|
+
end
|
281
314
|
|
282
|
-
|
283
|
-
|
284
|
-
|
315
|
+
cleanup(*(options[0] || [])) if options
|
316
|
+
def custom_cleanup_method0
|
317
|
+
called(:custom_cleanup_method0)
|
318
|
+
end
|
285
319
|
|
286
|
-
|
287
|
-
|
288
|
-
|
320
|
+
if options
|
321
|
+
cleanup(*(options[0] || [])) do
|
322
|
+
called(:custom_cleanup_callback0)
|
323
|
+
end
|
324
|
+
end
|
289
325
|
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
326
|
+
def custom_cleanup_method1
|
327
|
+
called(:custom_cleanup_method1)
|
328
|
+
end
|
329
|
+
cleanup(*[:custom_cleanup_method1, *(options[1] || [])]) if options
|
294
330
|
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
331
|
+
if options
|
332
|
+
cleanup(*(options[1] || [])) do
|
333
|
+
called(:custom_cleanup_callback1)
|
334
|
+
end
|
335
|
+
end
|
299
336
|
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
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
|
305
350
|
|
306
|
-
|
307
|
-
|
308
|
-
|
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?
|
309
366
|
end
|
310
367
|
|
311
|
-
|
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
|
312
376
|
end
|
377
|
+
end
|
313
378
|
|
314
|
-
|
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
|
315
384
|
end
|
316
385
|
|
317
|
-
|
318
|
-
|
386
|
+
def assert_invalid_cleanup_option(option)
|
387
|
+
assert_invalid_option(:cleanup, option)
|
388
|
+
end
|
319
389
|
end
|
320
390
|
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
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)
|
325
405
|
end
|
326
|
-
_test_case
|
327
|
-
end
|
328
406
|
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
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)
|
333
424
|
end
|
334
|
-
_test_case
|
335
|
-
end
|
336
425
|
|
337
|
-
|
338
|
-
|
339
|
-
|
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
|
340
444
|
|
341
|
-
|
342
|
-
|
343
|
-
|
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
|
344
450
|
|
345
|
-
|
346
|
-
|
347
|
-
|
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
|
348
466
|
|
349
|
-
|
350
|
-
|
351
|
-
|
467
|
+
def test_with_exception
|
468
|
+
test_case = Class.new(Test::Unit::TestCase) do
|
469
|
+
def called_ids
|
470
|
+
@called_ids ||= []
|
471
|
+
end
|
352
472
|
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
end
|
473
|
+
def called(id)
|
474
|
+
called_ids << id
|
475
|
+
end
|
357
476
|
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
477
|
+
def teardown
|
478
|
+
called(:teardown)
|
479
|
+
raise "teardown"
|
480
|
+
end
|
362
481
|
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
482
|
+
teardown
|
483
|
+
def custom_teardown_method0
|
484
|
+
called(:custom_teardown_method0)
|
485
|
+
raise "custom_teardown_method0"
|
486
|
+
end
|
368
487
|
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
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
|
373
503
|
|
374
|
-
|
504
|
+
def test_nothing
|
505
|
+
end
|
375
506
|
end
|
376
507
|
|
377
|
-
|
508
|
+
assert_called_fixtures([:custom_teardown_callback1,
|
509
|
+
:custom_teardown_method1,
|
510
|
+
:custom_teardown_callback0,
|
511
|
+
:custom_teardown_method0,
|
512
|
+
:teardown],
|
513
|
+
test_case)
|
378
514
|
end
|
379
515
|
|
380
|
-
|
381
|
-
|
382
|
-
|
516
|
+
private
|
517
|
+
def assert_teardown_customizable(expected, parent, options)
|
518
|
+
test_case = Class.new(parent || Test::Unit::TestCase) do
|
519
|
+
yield(self, :before) if block_given?
|
383
520
|
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
test_case.send(:include, EmptyModule) if tag == :before
|
388
|
-
end
|
389
|
-
end
|
521
|
+
def called_ids
|
522
|
+
@called_ids ||= []
|
523
|
+
end
|
390
524
|
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
test_case.send(:include, EmptyModule) if tag == :before
|
395
|
-
end
|
396
|
-
end
|
525
|
+
def called(id)
|
526
|
+
called_ids << id
|
527
|
+
end
|
397
528
|
|
398
|
-
|
399
|
-
|
400
|
-
|
529
|
+
def teardown
|
530
|
+
called(:teardown)
|
531
|
+
end
|
401
532
|
|
402
|
-
|
403
|
-
|
404
|
-
|
533
|
+
teardown(*(options[0] || [])) if options
|
534
|
+
def custom_teardown_method0
|
535
|
+
called(:custom_teardown_method0)
|
536
|
+
end
|
405
537
|
|
406
|
-
|
407
|
-
|
408
|
-
|
538
|
+
if options
|
539
|
+
teardown(*(options[0] || [])) do
|
540
|
+
called(:custom_teardown_callback0)
|
541
|
+
end
|
542
|
+
end
|
409
543
|
|
410
|
-
|
411
|
-
|
412
|
-
|
544
|
+
def custom_teardown_method1
|
545
|
+
called(:custom_teardown_method1)
|
546
|
+
end
|
547
|
+
teardown(*[:custom_teardown_method1, *(options[1] || [])]) if options
|
413
548
|
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
549
|
+
if options
|
550
|
+
teardown(*(options[1] || [])) do
|
551
|
+
called(:custom_teardown_callback1)
|
552
|
+
end
|
553
|
+
end
|
418
554
|
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
555
|
+
teardown(*(options[2] || [])) if options
|
556
|
+
def custom_teardown_method2
|
557
|
+
called(:custom_teardown_method2)
|
558
|
+
end
|
559
|
+
unregister_teardown(:custom_teardown_method2) if options
|
560
|
+
|
561
|
+
if options
|
562
|
+
callback = lambda do
|
563
|
+
called(:custom_teardown_callback2)
|
564
|
+
end
|
565
|
+
teardown(*(options[2] || []), &callback)
|
566
|
+
unregister_teardown(callback)
|
567
|
+
end
|
423
568
|
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
unregister_teardown(:custom_teardown_method2) if options
|
569
|
+
teardown(*(options[3] || [])) if options
|
570
|
+
def custom_teardown_method3
|
571
|
+
called(:custom_teardown_method3)
|
572
|
+
end
|
429
573
|
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
574
|
+
if options
|
575
|
+
teardown(*(options[3] || [])) do
|
576
|
+
called(:custom_teardown_callback3)
|
577
|
+
end
|
578
|
+
end
|
434
579
|
|
435
|
-
|
580
|
+
def test_nothing
|
581
|
+
end
|
582
|
+
|
583
|
+
yield(self, :after) if block_given?
|
436
584
|
end
|
437
585
|
|
438
|
-
|
586
|
+
assert_called_fixtures(expected, test_case)
|
587
|
+
test_case
|
439
588
|
end
|
440
589
|
|
441
|
-
|
442
|
-
|
443
|
-
|
590
|
+
def assert_teardown(expected, options)
|
591
|
+
assert_teardown_customizable(expected, nil, options)
|
592
|
+
assert_teardown_customizable(expected, nil, options) do |test_case, tag|
|
593
|
+
test_case.send(:include, EmptyModule) if tag == :before
|
594
|
+
end
|
595
|
+
end
|
444
596
|
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
597
|
+
def assert_inherited_teardown(expected, parent, options=nil)
|
598
|
+
assert_teardown_customizable(expected, parent, options)
|
599
|
+
assert_teardown_customizable(expected, parent, options) do |test_case, tag|
|
600
|
+
test_case.send(:include, EmptyModule) if tag == :before
|
601
|
+
end
|
449
602
|
end
|
450
|
-
end
|
451
603
|
|
452
|
-
|
453
|
-
|
454
|
-
assert_teardown_customizable(expected, parent, options) do |test_case, tag|
|
455
|
-
test_case.send(:include, EmptyModule) if tag == :before
|
604
|
+
def assert_invalid_teardown_option(option)
|
605
|
+
assert_invalid_option(:teardown, option)
|
456
606
|
end
|
457
607
|
end
|
458
608
|
|
609
|
+
private
|
610
|
+
def assert_called_fixtures(expected, test_case)
|
611
|
+
test = test_case.new("test_nothing")
|
612
|
+
test.run(Test::Unit::TestResult.new) {}
|
613
|
+
assert_equal(expected, test.called_ids)
|
614
|
+
end
|
615
|
+
|
459
616
|
def assert_invalid_option(fixture_type, option)
|
460
617
|
exception = assert_raise(ArgumentError) do
|
461
618
|
Class.new(Test::Unit::TestCase) do
|
@@ -472,16 +629,4 @@ class TestUnitFixture < Test::Unit::TestCase
|
|
472
629
|
": #{option.inspect}",
|
473
630
|
exception.message)
|
474
631
|
end
|
475
|
-
|
476
|
-
def assert_invalid_setup_option(option)
|
477
|
-
assert_invalid_option(:setup, option)
|
478
|
-
end
|
479
|
-
|
480
|
-
def assert_invalid_cleanup_option(option)
|
481
|
-
assert_invalid_option(:cleanup, option)
|
482
|
-
end
|
483
|
-
|
484
|
-
def assert_invalid_teardown_option(option)
|
485
|
-
assert_invalid_option(:teardown, option)
|
486
|
-
end
|
487
632
|
end
|