test-unit 2.4.3 → 2.4.4

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.
@@ -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
- delta = normalized_expected_float * epsilon.to_f
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
@@ -6,12 +6,11 @@ module Test
6
6
  base.extend(ClassMethods)
7
7
 
8
8
  [:setup, :cleanup, :teardown].each do |fixture|
9
- observer = Proc.new do |test_case, _, _, value, method_name|
9
+ observer = lambda do |test_case, _, _, value, callback|
10
10
  if value.nil?
11
- test_case.send("unregister_#{fixture}_method", method_name)
11
+ test_case.send("unregister_#{fixture}_callback", callback)
12
12
  else
13
- test_case.send("register_#{fixture}_method", method_name,
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(*method_names)
28
- unregister_fixture(:setup, *method_names)
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(*method_names)
36
- unregister_fixture(:cleanup, *method_names)
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(*method_names)
44
- unregister_fixture(:teardown, *method_names)
42
+ def unregister_teardown(*method_names_or_callbacks)
43
+ unregister_fixture(:teardown, *method_names_or_callbacks)
45
44
  end
46
45
 
47
- def register_setup_method(method_name, options)
48
- register_fixture_method(:setup, method_name, options, :after, :append)
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 unregister_setup_method(method_name)
52
- unregister_fixture_method(:setup, method_name)
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 register_cleanup_method(method_name, options)
56
- register_fixture_method(:cleanup, method_name, options,
57
- :before, :prepend)
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 unregister_cleanup_method(method_name)
61
- unregister_fixture_method(:cleanup, method_name)
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 register_teardown_method(method_name, options)
65
- register_fixture_method(:teardown, method_name, options,
66
- :before, :prepend)
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 unregister_teardown_method(method_name)
70
- unregister_fixture_method(:teardown, method_name)
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 before_setup_methods
74
- collect_fixture_methods(:setup, :before)
73
+ def before_setup_callbacks
74
+ collect_fixture_callbacks(:setup, :before)
75
75
  end
76
76
 
77
- def after_setup_methods
78
- collect_fixture_methods(:setup, :after)
77
+ def after_setup_callbacks
78
+ collect_fixture_callbacks(:setup, :after)
79
79
  end
80
80
 
81
- def before_cleanup_methods
82
- collect_fixture_methods(:cleanup, :before)
81
+ def before_cleanup_callbacks
82
+ collect_fixture_callbacks(:cleanup, :before)
83
83
  end
84
84
 
85
- def after_cleanup_methods
86
- collect_fixture_methods(:cleanup, :after)
85
+ def after_cleanup_callbacks
86
+ collect_fixture_callbacks(:cleanup, :after)
87
87
  end
88
88
 
89
- def before_teardown_methods
90
- collect_fixture_methods(:teardown, :before)
89
+ def before_teardown_callbacks
90
+ collect_fixture_callbacks(:teardown, :before)
91
91
  end
92
92
 
93
- def after_teardown_methods
94
- collect_fixture_methods(:teardown, :after)
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
- attribute(fixture, options, *method_names)
101
+ callbacks = method_names
102
+ callbacks << callback if callback
103
+ attribute(fixture, options, *callbacks)
102
104
  end
103
105
 
104
- def unregister_fixture(fixture, *method_names)
105
- attribute(fixture, nil, *method_names)
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 add_fixture_method_name(how, variable_name, method_name)
118
- methods = instance_eval("#{variable_name} ||= []")
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
- methods = [method_name] | methods
123
+ callbacks = [method_name_or_callback] | callbacks
122
124
  else
123
- methods = methods | [method_name]
125
+ callbacks = callbacks | [method_name_or_callback]
124
126
  end
125
- instance_variable_set(variable_name, methods)
127
+ instance_variable_set(variable_name, callbacks)
126
128
  end
127
129
 
128
- def registered_methods_variable_name(fixture, order)
129
- "@#{order}_#{fixture}_methods"
130
+ def registered_callbacks_variable_name(fixture, order)
131
+ "@#{order}_#{fixture}_callbacks"
130
132
  end
131
133
 
132
- def unregistered_methods_variable_name(fixture)
133
- "@unregistered_#{fixture}_methods"
134
+ def unregistered_callbacks_variable_name(fixture)
135
+ "@unregistered_#{fixture}_callbacks"
134
136
  end
135
137
 
136
- def register_fixture_method(fixture, method_name, options,
137
- default_order, default_how)
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 = registered_methods_variable_name(fixture, order)
151
- add_fixture_method_name(how, variable_name, method_name)
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 unregister_fixture_method(fixture, method_name)
155
- variable_name = unregistered_methods_variable_name(fixture)
156
- add_fixture_method_name(:append, variable_name, method_name)
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 collect_fixture_methods(fixture, order)
160
- methods_variable = registered_methods_variable_name(fixture, order)
161
- unregistered_methods_variable =
162
- unregistered_methods_variable_name(fixture)
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
- methods = instance_eval("#{methods_variable} ||= []")
170
- unregistered_methods =
171
- instance_eval("#{unregistered_methods_variable} ||= []")
172
- (result | methods) - unregistered_methods
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}_methods"),
186
+ self.class.send("before_#{fixture}_callbacks"),
185
187
  fixture,
186
- self.class.send("after_#{fixture}_methods")
187
- ].flatten.each do |method_name|
188
- next unless respond_to?(method_name, true)
189
- if options[:handle_exception]
190
- begin
191
- send(method_name)
192
- rescue Exception
193
- raise unless handle_exception($!)
194
- end
195
- else
196
- send(method_name)
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
@@ -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-2011 Kouhei Sutou <tt><kou@clear-code.com></tt>
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
- nl
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
- nl
381
+ output_progress_in_detail_marker(fault)
382
+ @progress_row = 0
374
383
  end
375
384
 
376
385
  def output?(level)
@@ -1,5 +1,5 @@
1
1
  module Test
2
2
  module Unit
3
- VERSION = '2.4.3'
3
+ VERSION = '2.4.4'
4
4
  end
5
5
  end
@@ -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
- def test_setup_without_option
6
- expected_setup_calls = [:setup,
7
- :custom_setup_method0,
8
- :custom_setup_method1,
9
- :custom_setup_method3]
10
- test_case = assert_setup(expected_setup_calls, [])
11
- assert_inherited_setup(expected_setup_calls, test_case)
12
-
13
- assert_inherited_setup([:setup], nil)
14
- assert_called_fixtures(expected_setup_calls, test_case)
15
- end
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
- def test_setup_with_before_option
18
- expected_setup_calls = [:custom_setup_method3,
19
- :custom_setup_method0,
20
- :custom_setup_method1,
21
- :setup]
22
- test_case = assert_setup(expected_setup_calls,
23
- [[{:before => :append}],
24
- [{:before => :append}],
25
- [{:before => :prepend}],
26
- [{:before => :prepend}]])
27
- assert_inherited_setup(expected_setup_calls, test_case)
28
-
29
- assert_inherited_setup([:setup], nil)
30
- assert_called_fixtures(expected_setup_calls, test_case)
31
- end
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
- def test_setup_with_after_option
34
- expected_setup_calls = [:setup,
35
- :custom_setup_method3,
36
- :custom_setup_method0,
37
- :custom_setup_method1]
38
- test_case = assert_setup(expected_setup_calls,
39
- [[{:after => :append}],
40
- [{:after => :append}],
41
- [{:after => :prepend}],
42
- [{:after => :prepend}]])
43
- assert_inherited_setup(expected_setup_calls, test_case)
44
-
45
- assert_inherited_setup([:setup], nil)
46
- assert_called_fixtures(expected_setup_calls, test_case)
47
- end
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
- def test_setup_with_invalid_option
50
- assert_invalid_setup_option(:unknown => true)
51
- assert_invalid_setup_option(:before => :unknown)
52
- assert_invalid_setup_option(:after => :unknown)
53
- end
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
- def test_setup_with_option_to_inherited
56
- expected_setup_calls = [:setup]
57
- test_case = assert_setup(expected_setup_calls, nil)
58
- assert_inherited_setup([:setup,
59
- :custom_setup_method0,
60
- :custom_setup_method1,
61
- :custom_setup_method3],
62
- test_case,
63
- [])
64
-
65
- assert_inherited_setup([:setup], nil)
66
- assert_called_fixtures(expected_setup_calls, test_case)
67
- end
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
- def test_cleanup_without_option
70
- expected_cleanup_calls = [:custom_cleanup_method3,
71
- :custom_cleanup_method1,
72
- :custom_cleanup_method0,
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
- assert_inherited_cleanup([:cleanup], nil)
78
- assert_called_fixtures(expected_cleanup_calls, test_case)
79
- end
87
+ def called_ids
88
+ @called_ids ||= []
89
+ end
80
90
 
81
- def test_cleanup_with_before_option
82
- expected_cleanup_calls = [:custom_cleanup_method3,
83
- :custom_cleanup_method0,
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
- def test_cleanup_with_after_option
98
- expected_cleanup_calls = [:cleanup,
99
- :custom_cleanup_method3,
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
- def test_cleanup_with_invalid_option
114
- assert_invalid_cleanup_option(:unknown => true)
115
- assert_invalid_cleanup_option(:before => :unknown)
116
- assert_invalid_cleanup_option(:after => :unknown)
117
- end
99
+ setup(*(options[0] || [])) if options
100
+ def custom_setup_method0
101
+ called(:custom_setup_method0)
102
+ end
118
103
 
119
- def test_cleanup_with_option_to_inherited
120
- expected_cleanup_calls = [:cleanup]
121
- test_case = assert_cleanup(expected_cleanup_calls, nil)
122
- assert_inherited_cleanup([:custom_cleanup_method3,
123
- :custom_cleanup_method1,
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
- def test_cleanup_with_exception
133
- test_case = Class.new(Test::Unit::TestCase) do
134
- def called_ids
135
- @called_ids ||= []
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
- def called(id)
139
- called_ids << id
140
- end
115
+ if options
116
+ setup(*(options[1] || [])) do
117
+ called(:custom_setup_callback1)
118
+ end
119
+ end
141
120
 
142
- def cleanup
143
- called(:cleanup)
144
- raise "cleanup"
145
- end
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
- cleanup
148
- def custom_cleanup_method0
149
- called(:custom_cleanup_method0)
150
- raise "custom_cleanup_method0"
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
- cleanup
154
- def custom_cleanup_method1
155
- called(:custom_cleanup_method1)
156
- raise "custom_cleanup_method1"
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
- def test_nothing
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
- assert_called_fixtures([:custom_cleanup_method1],
164
- test_case)
172
+ def assert_invalid_setup_option(option)
173
+ assert_invalid_option(:setup, option)
174
+ end
165
175
  end
166
176
 
167
- def test_teardown_without_option
168
- expected_teardown_calls = [:custom_teardown_method3,
169
- :custom_teardown_method1,
170
- :custom_teardown_method0,
171
- :teardown]
172
- test_case = assert_teardown(expected_teardown_calls, [])
173
- assert_inherited_teardown(expected_teardown_calls, test_case)
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
- assert_inherited_teardown([:teardown], nil)
176
- assert_called_fixtures(expected_teardown_calls, test_case)
177
- end
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
- def test_teardown_with_before_option
180
- expected_teardown_calls = [:custom_teardown_method3,
181
- :custom_teardown_method0,
182
- :custom_teardown_method1,
183
- :teardown]
184
- test_case = assert_teardown(expected_teardown_calls,
185
- [[{:before => :append}],
186
- [{:before => :append}],
187
- [{:before => :prepend}],
188
- [{:before => :prepend}]])
189
- assert_inherited_teardown(expected_teardown_calls, test_case)
190
-
191
- assert_inherited_teardown([:teardown], nil)
192
- assert_called_fixtures(expected_teardown_calls, test_case)
193
- end
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
- def test_teardown_with_after_option
196
- expected_teardown_calls = [:teardown,
197
- :custom_teardown_method3,
198
- :custom_teardown_method0,
199
- :custom_teardown_method1]
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
- def test_teardown_with_invalid_option
212
- assert_invalid_teardown_option(:unknown => true)
213
- assert_invalid_teardown_option(:before => :unknown)
214
- assert_invalid_teardown_option(:after => :unknown)
215
- end
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
- def test_teardown_with_option_to_inherited
218
- expected_teardown_calls = [:teardown]
219
- test_case = assert_teardown(expected_teardown_calls, nil)
220
- assert_inherited_teardown([:custom_teardown_method3,
221
- :custom_teardown_method1,
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
- def test_teardown_with_exception
231
- test_case = Class.new(Test::Unit::TestCase) do
232
- def called_ids
233
- @called_ids ||= []
234
- end
259
+ def called(id)
260
+ called_ids << id
261
+ end
235
262
 
236
- def called(id)
237
- called_ids << id
238
- end
263
+ def cleanup
264
+ called(:cleanup)
265
+ raise "cleanup"
266
+ end
239
267
 
240
- def teardown
241
- called(:teardown)
242
- raise "teardown"
243
- end
268
+ cleanup
269
+ def custom_cleanup_method0
270
+ called(:custom_cleanup_method0)
271
+ raise "custom_cleanup_method0"
272
+ end
244
273
 
245
- teardown
246
- def custom_teardown_method0
247
- called(:custom_teardown_method0)
248
- raise "custom_teardown_method0"
249
- end
274
+ cleanup do
275
+ called(:custom_cleanup_callback0)
276
+ raise "custom_cleanup_callback0"
277
+ end
250
278
 
251
- teardown
252
- def custom_teardown_method1
253
- called(:custom_teardown_method1)
254
- raise "custom_teardown_method1"
255
- end
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
- def test_nothing
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
- assert_called_fixtures([:custom_teardown_method1,
262
- :custom_teardown_method0,
263
- :teardown],
264
- test_case)
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
- private
268
- def assert_called_fixtures(expected, test_case)
269
- test = test_case.new("test_nothing")
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
- def assert_setup_customizable(expected, parent, options)
275
- test_case = Class.new(parent || Test::Unit::TestCase) do
276
- yield(self, :before) if block_given?
307
+ def called(id)
308
+ called_ids << id
309
+ end
277
310
 
278
- def called_ids
279
- @called_ids ||= []
280
- end
311
+ def cleanup
312
+ called(:cleanup)
313
+ end
281
314
 
282
- def called(id)
283
- called_ids << id
284
- end
315
+ cleanup(*(options[0] || [])) if options
316
+ def custom_cleanup_method0
317
+ called(:custom_cleanup_method0)
318
+ end
285
319
 
286
- def setup
287
- called(:setup)
288
- end
320
+ if options
321
+ cleanup(*(options[0] || [])) do
322
+ called(:custom_cleanup_callback0)
323
+ end
324
+ end
289
325
 
290
- setup(*(options[0] || [])) if options
291
- def custom_setup_method0
292
- called(:custom_setup_method0)
293
- end
326
+ def custom_cleanup_method1
327
+ called(:custom_cleanup_method1)
328
+ end
329
+ cleanup(*[:custom_cleanup_method1, *(options[1] || [])]) if options
294
330
 
295
- def custom_setup_method1
296
- called(:custom_setup_method1)
297
- end
298
- setup(*[:custom_setup_method1, *(options[1] || [])]) if options
331
+ if options
332
+ cleanup(*(options[1] || [])) do
333
+ called(:custom_cleanup_callback1)
334
+ end
335
+ end
299
336
 
300
- setup(*(options[2] || [])) if options
301
- def custom_setup_method2
302
- called(:custom_setup_method2)
303
- end
304
- unregister_setup(:custom_setup_method2) if options
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
- setup(*(options[3] || [])) if options
307
- def custom_setup_method3
308
- called(:custom_setup_method3)
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
- def test_nothing
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
- yield(self, :after) if block_given?
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
- assert_called_fixtures(expected, test_case)
318
- test_case
386
+ def assert_invalid_cleanup_option(option)
387
+ assert_invalid_option(:cleanup, option)
388
+ end
319
389
  end
320
390
 
321
- def assert_setup(expected, options)
322
- _test_case = assert_setup_customizable(expected, nil, options)
323
- assert_setup_customizable(expected, nil, options) do |test_case, tag|
324
- test_case.send(:include, EmptyModule) if tag == :before
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
- def assert_inherited_setup(expected, parent, options=nil)
330
- _test_case = assert_setup_customizable(expected, parent, options)
331
- assert_setup_customizable(expected, parent, options) do |test_case, tag|
332
- test_case.send(:include, EmptyModule) if tag == :before
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
- def assert_cleanup_customizable(expected, parent, options)
338
- test_case = Class.new(parent || Test::Unit::TestCase) do
339
- yield(self, :before) if block_given?
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
- def called_ids
342
- @called_ids ||= []
343
- end
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
- def called(id)
346
- called_ids << id
347
- end
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
- def cleanup
350
- called(:cleanup)
351
- end
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
- cleanup(*(options[0] || [])) if options
354
- def custom_cleanup_method0
355
- called(:custom_cleanup_method0)
356
- end
473
+ def called(id)
474
+ called_ids << id
475
+ end
357
476
 
358
- def custom_cleanup_method1
359
- called(:custom_cleanup_method1)
360
- end
361
- cleanup(*[:custom_cleanup_method1, *(options[1] || [])]) if options
477
+ def teardown
478
+ called(:teardown)
479
+ raise "teardown"
480
+ end
362
481
 
363
- cleanup(*(options[2] || [])) if options
364
- def custom_cleanup_method2
365
- called(:custom_cleanup_method2)
366
- end
367
- unregister_cleanup(:custom_cleanup_method2) if options
482
+ teardown
483
+ def custom_teardown_method0
484
+ called(:custom_teardown_method0)
485
+ raise "custom_teardown_method0"
486
+ end
368
487
 
369
- cleanup(*(options[3] || [])) if options
370
- def custom_cleanup_method3
371
- called(:custom_cleanup_method3)
372
- end
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
- def test_nothing
504
+ def test_nothing
505
+ end
375
506
  end
376
507
 
377
- yield(self, :after) if block_given?
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
- assert_called_fixtures(expected, test_case)
381
- test_case
382
- end
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
- def assert_cleanup(expected, options)
385
- assert_cleanup_customizable(expected, nil, options)
386
- assert_cleanup_customizable(expected, nil, options) do |test_case, tag|
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
- def assert_inherited_cleanup(expected, parent, options=nil)
392
- assert_cleanup_customizable(expected, parent, options)
393
- assert_cleanup_customizable(expected, parent, options) do |test_case, tag|
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
- def assert_teardown_customizable(expected, parent, options)
399
- test_case = Class.new(parent || Test::Unit::TestCase) do
400
- yield(self, :before) if block_given?
529
+ def teardown
530
+ called(:teardown)
531
+ end
401
532
 
402
- def called_ids
403
- @called_ids ||= []
404
- end
533
+ teardown(*(options[0] || [])) if options
534
+ def custom_teardown_method0
535
+ called(:custom_teardown_method0)
536
+ end
405
537
 
406
- def called(id)
407
- called_ids << id
408
- end
538
+ if options
539
+ teardown(*(options[0] || [])) do
540
+ called(:custom_teardown_callback0)
541
+ end
542
+ end
409
543
 
410
- def teardown
411
- called(:teardown)
412
- end
544
+ def custom_teardown_method1
545
+ called(:custom_teardown_method1)
546
+ end
547
+ teardown(*[:custom_teardown_method1, *(options[1] || [])]) if options
413
548
 
414
- teardown(*(options[0] || [])) if options
415
- def custom_teardown_method0
416
- called(:custom_teardown_method0)
417
- end
549
+ if options
550
+ teardown(*(options[1] || [])) do
551
+ called(:custom_teardown_callback1)
552
+ end
553
+ end
418
554
 
419
- def custom_teardown_method1
420
- called(:custom_teardown_method1)
421
- end
422
- teardown(*[:custom_teardown_method1, *(options[1] || [])]) if options
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
- teardown(*(options[2] || [])) if options
425
- def custom_teardown_method2
426
- called(:custom_teardown_method2)
427
- end
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
- teardown(*(options[3] || [])) if options
431
- def custom_teardown_method3
432
- called(:custom_teardown_method3)
433
- end
574
+ if options
575
+ teardown(*(options[3] || [])) do
576
+ called(:custom_teardown_callback3)
577
+ end
578
+ end
434
579
 
435
- def test_nothing
580
+ def test_nothing
581
+ end
582
+
583
+ yield(self, :after) if block_given?
436
584
  end
437
585
 
438
- yield(self, :after) if block_given?
586
+ assert_called_fixtures(expected, test_case)
587
+ test_case
439
588
  end
440
589
 
441
- assert_called_fixtures(expected, test_case)
442
- test_case
443
- end
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
- def assert_teardown(expected, options)
446
- assert_teardown_customizable(expected, nil, options)
447
- assert_teardown_customizable(expected, nil, options) do |test_case, tag|
448
- test_case.send(:include, EmptyModule) if tag == :before
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
- def assert_inherited_teardown(expected, parent, options=nil)
453
- assert_teardown_customizable(expected, parent, options)
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