test-unit 3.2.5 → 3.4.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/BSDL +24 -0
- data/COPYING +41 -44
- data/README.md +8 -11
- data/Rakefile +0 -23
- data/doc/text/getting-started.md +1 -1
- data/doc/text/news.md +366 -0
- data/lib/test/unit/assertion-failed-error.rb +35 -0
- data/lib/test/unit/assertions.rb +312 -112
- data/lib/test/unit/attribute.rb +7 -2
- data/lib/test/unit/autorunner.rb +79 -31
- data/lib/test/unit/code-snippet-fetcher.rb +7 -7
- 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 +10 -13
- data/lib/test/unit/collector/objectspace.rb +1 -0
- data/lib/test/unit/collector.rb +31 -0
- data/lib/test/unit/color-scheme.rb +20 -2
- data/lib/test/unit/data-sets.rb +116 -0
- data/lib/test/unit/data.rb +121 -12
- data/lib/test/unit/diff.rb +2 -3
- data/lib/test/unit/fixture.rb +6 -0
- data/lib/test/unit/notification.rb +9 -7
- data/lib/test/unit/omission.rb +34 -31
- data/lib/test/unit/pending.rb +12 -11
- data/lib/test/unit/priority.rb +7 -3
- data/lib/test/unit/runner/console.rb +8 -0
- data/lib/test/unit/test-suite-creator.rb +22 -8
- data/lib/test/unit/testcase.rb +216 -146
- data/lib/test/unit/testsuite.rb +1 -1
- data/lib/test/unit/ui/console/testrunner.rb +92 -32
- data/lib/test/unit/util/memory-usage.rb +47 -0
- data/lib/test/unit/util/observable.rb +2 -2
- data/lib/test/unit/util/output.rb +5 -4
- data/lib/test/unit/util/procwrapper.rb +4 -4
- data/lib/test/unit/version.rb +1 -1
- data/lib/test/unit/warning.rb +3 -0
- data/lib/test/unit.rb +177 -161
- data/lib/test-unit.rb +2 -17
- metadata +13 -88
- data/GPL +0 -339
- data/LGPL +0 -502
- data/test/collector/test-descendant.rb +0 -182
- data/test/collector/test-load.rb +0 -442
- 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 -2180
- data/test/test-attribute-matcher.rb +0 -38
- data/test/test-attribute.rb +0 -123
- data/test/test-code-snippet.rb +0 -37
- data/test/test-color-scheme.rb +0 -82
- data/test/test-color.rb +0 -47
- data/test/test-data.rb +0 -303
- 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 -173
- data/test/test-test-case.rb +0 -1278
- 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 -31
- 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-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
|