test-unit 3.3.1 → 3.3.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -31,9 +31,11 @@ module Test
31
31
  break if first_line.nil?
32
32
  encoding = detect_encoding(first_line) || Encoding::UTF_8
33
33
  first_line.force_encoding(encoding)
34
- file.set_encoding(encoding)
35
34
  lines << first_line
36
- lines.concat(file.readlines)
35
+ file.each_line do |line|
36
+ line.force_encoding(encoding)
37
+ lines << line
38
+ end
37
39
  end
38
40
  lines
39
41
  end
@@ -111,7 +111,7 @@ module Test
111
111
  return if @program_file == expanded_path.to_s
112
112
  add_load_path(expanded_path.dirname) do
113
113
  begin
114
- require(path.basename.to_s)
114
+ require(expanded_path.to_s)
115
115
  rescue LoadError
116
116
  @require_failed_infos << {:path => expanded_path, :exception => $!}
117
117
  end
@@ -131,8 +131,6 @@ module Test
131
131
  return yield if path.nil?
132
132
 
133
133
  path = path.to_s
134
- return yield if $LOAD_PATH.index(path)
135
-
136
134
  begin
137
135
  $LOAD_PATH.unshift(path)
138
136
  yield
@@ -187,7 +187,7 @@ module Test
187
187
  #
188
188
  # @param [String] file_name full path to test data file.
189
189
  # File format is automatically detected from filename extension.
190
- # @raise [ArgumentError] if +file_name+ is not supported file format.
190
+ # @raise [ArgumentError] if `file_name` is not supported file format.
191
191
  # @see Loader#load
192
192
  #
193
193
  # @example Load data from CSV file
@@ -211,7 +211,7 @@ module Test
211
211
  #
212
212
  # @param [String] file_name full path to test data file.
213
213
  # File format is automatically detected from filename extension.
214
- # @raise [ArgumentError] if +file_name+ is not supported file format.
214
+ # @raise [ArgumentError] if `file_name` is not supported file format.
215
215
  # @see #load_csv
216
216
  # @see #load_tsv
217
217
  # @api private
@@ -65,15 +65,17 @@ module Test
65
65
  # Notify some information.
66
66
  #
67
67
  # Example:
68
- # def test_notification
69
- # notify("I'm here!")
70
- # # Reached here
71
- # notify("Special!") if special_case?
72
- # # Reached here too
73
- # end
68
+ #
69
+ # def test_notification
70
+ # notify("I'm here!")
71
+ # # Reached here
72
+ # notify("Special!") if special_case?
73
+ # # Reached here too
74
+ # end
74
75
  #
75
76
  # options:
76
- # :backtrace override backtrace.
77
+ #
78
+ # :backtrace override backtrace.
77
79
  def notify(message, options={}, &block)
78
80
  backtrace = filter_backtrace(options[:backtrace] || caller)
79
81
  notification = Notification.new(name, backtrace, message,
@@ -65,17 +65,18 @@ module Test
65
65
  # Omit the test or part of the test.
66
66
  #
67
67
  # Example:
68
- # def test_omission
69
- # omit
70
- # # Not reached here
71
- # end
72
68
  #
73
- # def test_omission_with_here
74
- # omit do
75
- # # Not ran here
69
+ # def test_omission
70
+ # omit
71
+ # # Not reached here
72
+ # end
73
+ #
74
+ # def test_omission_with_here
75
+ # omit do
76
+ # # Not ran here
77
+ # end
78
+ # # Reached here
76
79
  # end
77
- # # Reached here
78
- # end
79
80
  def omit(message=nil, &block)
80
81
  message ||= "omitted."
81
82
  if block_given?
@@ -91,20 +92,21 @@ module Test
91
92
  # true.
92
93
  #
93
94
  # Example:
94
- # def test_omission
95
- # omit_if("".empty?)
96
- # # Not reached here
97
- # end
98
95
  #
99
- # def test_omission_with_here
100
- # omit_if(true) do
101
- # # Not ran here
96
+ # def test_omission
97
+ # omit_if("".empty?)
98
+ # # Not reached here
102
99
  # end
103
- # omit_if(false) do
104
- # # Reached here
100
+ #
101
+ # def test_omission_with_here
102
+ # omit_if(true) do
103
+ # # Not ran here
104
+ # end
105
+ # omit_if(false) do
106
+ # # Reached here
107
+ # end
108
+ # # Reached here too
105
109
  # end
106
- # # Reached here too
107
- # end
108
110
  def omit_if(condition, *args, &block)
109
111
  if condition
110
112
  omit(*args, &block)
@@ -117,20 +119,21 @@ module Test
117
119
  # not true.
118
120
  #
119
121
  # Example:
120
- # def test_omission
121
- # omit_unless("string".empty?)
122
- # # Not reached here
123
- # end
124
122
  #
125
- # def test_omission_with_here
126
- # omit_unless(true) do
127
- # # Reached here
123
+ # def test_omission
124
+ # omit_unless("string".empty?)
125
+ # # Not reached here
128
126
  # end
129
- # omit_unless(false) do
130
- # # Not ran here
127
+ #
128
+ # def test_omission_with_here
129
+ # omit_unless(true) do
130
+ # # Reached here
131
+ # end
132
+ # omit_unless(false) do
133
+ # # Not ran here
134
+ # end
135
+ # # Reached here too
131
136
  # end
132
- # # Reached here too
133
- # end
134
137
  def omit_unless(condition, *args, &block)
135
138
  if condition
136
139
  block.call if block
@@ -65,19 +65,20 @@ module Test
65
65
  # Marks the test or part of the test is pending.
66
66
  #
67
67
  # Example:
68
- # def test_pending
69
- # pend
70
- # # Not reached here
71
- # end
72
68
  #
73
- # def test_pending_with_here
74
- # pend do
75
- # # Ran here
76
- # # Fails if the block doesn't raise any error.
77
- # # Because it means the block is passed unexpectedly.
69
+ # def test_pending
70
+ # pend
71
+ # # Not reached here
72
+ # end
73
+ #
74
+ # def test_pending_with_here
75
+ # pend do
76
+ # # Ran here
77
+ # # Fails if the block doesn't raise any error.
78
+ # # Because it means the block is passed unexpectedly.
79
+ # end
80
+ # # Reached here
78
81
  # end
79
- # # Reached here
80
- # end
81
82
  def pend(message=nil, &block)
82
83
  message ||= "pended."
83
84
  if block_given?
@@ -148,15 +148,19 @@ module Test
148
148
  end
149
149
 
150
150
  def escape_class_name(class_name)
151
- class_name.gsub(/(?:[: \\\/])/, "_")
151
+ escape_name(class_name)
152
152
  end
153
153
 
154
154
  def escaped_method_name
155
- @test.method_name.to_s.gsub(/(?:[: ]|[!?=]$)/) do |matched|
155
+ escape_name(@test.method_name.to_s)
156
+ end
157
+
158
+ def escape_name(name)
159
+ name.gsub(/(?:[: \/!?=])/) do |matched|
156
160
  case matched
157
161
  when ":"
158
162
  "_colon_"
159
- when " "
163
+ when " ", "/"
160
164
  "_"
161
165
  when "!"
162
166
  ".destructive"
@@ -186,27 +186,29 @@ module Test
186
186
  # scope.
187
187
  #
188
188
  # Here is an example test case:
189
- # class TestMyClass < Test::Unit::TestCase
190
- # class << self
191
- # def startup
192
- # ...
189
+ #
190
+ # class TestMyClass < Test::Unit::TestCase
191
+ # class << self
192
+ # def startup
193
+ # ...
194
+ # end
193
195
  # end
194
- # end
195
196
  #
196
- # def setup
197
- # ...
198
- # end
197
+ # def setup
198
+ # ...
199
+ # end
199
200
  #
200
- # def test_my_class1
201
- # ...
202
- # end
201
+ # def test_my_class1
202
+ # ...
203
+ # end
203
204
  #
204
- # def test_my_class2
205
- # ...
205
+ # def test_my_class2
206
+ # ...
207
+ # end
206
208
  # end
207
- # end
208
209
  #
209
210
  # Here is a call order:
211
+ #
210
212
  # * startup
211
213
  # * setup
212
214
  # * test_my_class1 (or test_my_class2)
@@ -222,27 +224,29 @@ module Test
222
224
  # down fixture information used in test case scope.
223
225
  #
224
226
  # Here is an example test case:
225
- # class TestMyClass < Test::Unit::TestCase
226
- # class << self
227
- # def shutdown
228
- # ...
227
+ #
228
+ # class TestMyClass < Test::Unit::TestCase
229
+ # class << self
230
+ # def shutdown
231
+ # ...
232
+ # end
229
233
  # end
230
- # end
231
234
  #
232
- # def teardown
233
- # ...
234
- # end
235
+ # def teardown
236
+ # ...
237
+ # end
235
238
  #
236
- # def test_my_class1
237
- # ...
238
- # end
239
+ # def test_my_class1
240
+ # ...
241
+ # end
239
242
  #
240
- # def test_my_class2
241
- # ...
243
+ # def test_my_class2
244
+ # ...
245
+ # end
242
246
  # end
243
- # end
244
247
  #
245
248
  # Here is a call order:
249
+ #
246
250
  # * test_my_class1 (or test_my_class2)
247
251
  # * teardown
248
252
  # * test_my_class2 (or test_my_class1)
@@ -257,7 +261,7 @@ module Test
257
261
  @@test_orders = {}
258
262
 
259
263
  # Returns the current test order. This returns
260
- # +:alphabetic+ by default.
264
+ # `:alphabetic` by default.
261
265
  def test_order
262
266
  ancestors.each do |ancestor|
263
267
  order = @@test_orders[ancestor]
@@ -269,12 +273,15 @@ module Test
269
273
  # Sets the current test order.
270
274
  #
271
275
  # Here are the available _order_:
272
- # [:alphabetic]
273
- # Default. Tests are sorted in alphabetic order.
274
- # [:random]
275
- # Tests are sorted in random order.
276
- # [:defined]
277
- # Tests are sorted in defined order.
276
+ #
277
+ # :alphabetic
278
+ # : Default. Tests are sorted in alphabetic order.
279
+ #
280
+ # :random
281
+ # : Tests are sorted in random order.
282
+ #
283
+ # :defined
284
+ # : Tests are sorted in defined order.
278
285
  def test_order=(order)
279
286
  @@test_orders[self] = order
280
287
  end
@@ -285,22 +292,22 @@ module Test
285
292
  # In declarative syntax usage, the following two
286
293
  # test definitions are the almost same:
287
294
  #
288
- # description "register user"
289
- # def test_register_user
290
- # ...
291
- # end
295
+ # description "register user"
296
+ # def test_register_user
297
+ # ...
298
+ # end
292
299
  #
293
- # test "register user" do
294
- # ...
295
- # end
300
+ # test "register user" do
301
+ # ...
302
+ # end
296
303
  #
297
304
  # In test method mark usage, the "my_test_method" is
298
305
  # treated as a test method:
299
306
  #
300
- # test
301
- # def my_test_method
302
- # assert_equal("call me", ...)
303
- # end
307
+ # test
308
+ # def my_test_method
309
+ # assert_equal("call me", ...)
310
+ # end
304
311
  def test(*test_description_or_targets, &block)
305
312
  if block_given?
306
313
  test_description = test_description_or_targets.first
@@ -334,10 +341,10 @@ module Test
334
341
  # normal user" description with "test_register"
335
342
  # test.
336
343
  #
337
- # description "register a normal user"
338
- # def test_register
339
- # ...
340
- # end
344
+ # description "register a normal user"
345
+ # def test_register
346
+ # ...
347
+ # end
341
348
  def description(value, target=nil)
342
349
  targets = [target].compact
343
350
  attribute(:description, value, {}, *targets)
@@ -349,20 +356,22 @@ module Test
349
356
  # the same in meaning:
350
357
  #
351
358
  # Standard:
352
- # class TestParent < Test::Unit::TestCase
353
- # class TestChild < self
354
- # def test_in_child
359
+ #
360
+ # class TestParent < Test::Unit::TestCase
361
+ # class TestChild < self
362
+ # def test_in_child
363
+ # end
355
364
  # end
356
365
  # end
357
- # end
358
366
  #
359
367
  # Syntax sugar:
360
- # class TestParent < Test::Unit::TestCase
361
- # sub_test_case("TestChild") do
362
- # def test_in_child
368
+ #
369
+ # class TestParent < Test::Unit::TestCase
370
+ # sub_test_case("TestChild") do
371
+ # def test_in_child
372
+ # end
363
373
  # end
364
374
  # end
365
- # end
366
375
  #
367
376
  # The difference of them are the following:
368
377
  #
@@ -559,35 +568,37 @@ module Test
559
568
  #
560
569
  # You can add additional setup tasks by the following
561
570
  # code:
562
- # class TestMyClass < Test::Unit::TestCase
563
- # def setup
564
- # ...
565
- # end
566
571
  #
567
- # setup
568
- # def my_setup1
569
- # ...
570
- # end
572
+ # class TestMyClass < Test::Unit::TestCase
573
+ # def setup
574
+ # ...
575
+ # end
571
576
  #
572
- # setup do
573
- # ... # setup callback1
574
- # end
577
+ # setup
578
+ # def my_setup1
579
+ # ...
580
+ # end
575
581
  #
576
- # setup
577
- # def my_setup2
578
- # ...
579
- # end
582
+ # setup do
583
+ # ... # setup callback1
584
+ # end
580
585
  #
581
- # setup do
582
- # ... # setup callback2
583
- # end
586
+ # setup
587
+ # def my_setup2
588
+ # ...
589
+ # end
590
+ #
591
+ # setup do
592
+ # ... # setup callback2
593
+ # end
584
594
  #
585
- # def test_my_class
586
- # ...
595
+ # def test_my_class
596
+ # ...
597
+ # end
587
598
  # end
588
- # end
589
599
  #
590
600
  # Here is a call order:
601
+ #
591
602
  # * setup
592
603
  # * my_setup1
593
604
  # * setup callback1
@@ -604,35 +615,37 @@ module Test
604
615
  #
605
616
  # You can add additional cleanup tasks by the following
606
617
  # code:
607
- # class TestMyClass < Test::Unit::TestCase
608
- # def cleanup
609
- # ...
610
- # end
611
618
  #
612
- # cleanup
613
- # def my_cleanup1
614
- # ...
615
- # end
619
+ # class TestMyClass < Test::Unit::TestCase
620
+ # def cleanup
621
+ # ...
622
+ # end
616
623
  #
617
- # cleanup do
618
- # ... # cleanup callback1
619
- # end
624
+ # cleanup
625
+ # def my_cleanup1
626
+ # ...
627
+ # end
620
628
  #
621
- # cleanup
622
- # def my_cleanup2
623
- # ...
624
- # end
629
+ # cleanup do
630
+ # ... # cleanup callback1
631
+ # end
625
632
  #
626
- # cleanup do
627
- # ... # cleanup callback2
628
- # end
633
+ # cleanup
634
+ # def my_cleanup2
635
+ # ...
636
+ # end
629
637
  #
630
- # def test_my_class
631
- # ...
638
+ # cleanup do
639
+ # ... # cleanup callback2
640
+ # end
641
+ #
642
+ # def test_my_class
643
+ # ...
644
+ # end
632
645
  # end
633
- # end
634
646
  #
635
647
  # Here is a call order:
648
+ #
636
649
  # * test_my_class
637
650
  # * cleanup callback2
638
651
  # * my_cleanup2
@@ -647,35 +660,37 @@ module Test
647
660
  #
648
661
  # You can add additional teardown tasks by the following
649
662
  # code:
650
- # class TestMyClass < Test::Unit::TestCase
651
- # def teardown
652
- # ...
653
- # end
654
663
  #
655
- # teardown
656
- # def my_teardown1
657
- # ...
658
- # end
664
+ # class TestMyClass < Test::Unit::TestCase
665
+ # def teardown
666
+ # ...
667
+ # end
659
668
  #
660
- # teardown do
661
- # ... # teardown callback1
662
- # end
669
+ # teardown
670
+ # def my_teardown1
671
+ # ...
672
+ # end
663
673
  #
664
- # teardown
665
- # def my_teardown2
666
- # ...
667
- # end
674
+ # teardown do
675
+ # ... # teardown callback1
676
+ # end
668
677
  #
669
- # teardown do
670
- # ... # teardown callback2
671
- # end
678
+ # teardown
679
+ # def my_teardown2
680
+ # ...
681
+ # end
682
+ #
683
+ # teardown do
684
+ # ... # teardown callback2
685
+ # end
672
686
  #
673
- # def test_my_class
674
- # ...
687
+ # def test_my_class
688
+ # ...
689
+ # end
675
690
  # end
676
- # end
677
691
  #
678
692
  # Here is a call order:
693
+ #
679
694
  # * test_my_class
680
695
  # * teardown callback2
681
696
  # * my_teardown2
@@ -695,13 +710,13 @@ module Test
695
710
 
696
711
  # Returns a label of test data for the test. If the
697
712
  # test isn't associated with any test data, it returns
698
- # +nil+.
713
+ # `nil`.
699
714
  def data_label
700
715
  @internal_data.test_data_label
701
716
  end
702
717
 
703
718
  # Returns test data for the test. If the test isn't associated
704
- # with any test data, it returns +nil+.
719
+ # with any test data, it returns `nil`.
705
720
  def data
706
721
  @internal_data.test_data
707
722
  end