test-unit 3.1.5 → 3.6.1

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.
Files changed (87) hide show
  1. checksums.yaml +5 -5
  2. data/BSDL +24 -0
  3. data/COPYING +41 -41
  4. data/README.md +24 -17
  5. data/Rakefile +21 -24
  6. data/doc/text/getting-started.md +246 -0
  7. data/doc/text/news.md +797 -56
  8. data/lib/test/unit/assertion-failed-error.rb +35 -0
  9. data/lib/test/unit/assertions.rb +542 -220
  10. data/lib/test/unit/attribute.rb +78 -4
  11. data/lib/test/unit/auto-runner-loader.rb +17 -0
  12. data/lib/test/unit/autorunner.rb +175 -78
  13. data/lib/test/unit/code-snippet-fetcher.rb +7 -7
  14. data/lib/test/unit/collector/descendant.rb +1 -0
  15. data/lib/test/unit/collector/dir.rb +4 -2
  16. data/lib/test/unit/collector/load.rb +25 -15
  17. data/lib/test/unit/collector/objectspace.rb +1 -0
  18. data/lib/test/unit/collector.rb +31 -0
  19. data/lib/test/unit/color-scheme.rb +29 -2
  20. data/lib/test/unit/data-sets.rb +127 -0
  21. data/lib/test/unit/data.rb +121 -12
  22. data/lib/test/unit/diff.rb +10 -11
  23. data/lib/test/unit/fixture.rb +77 -27
  24. data/lib/test/unit/notification.rb +9 -7
  25. data/lib/test/unit/omission.rb +34 -31
  26. data/lib/test/unit/pending.rb +12 -11
  27. data/lib/test/unit/priority.rb +7 -5
  28. data/lib/test/unit/runner/console.rb +20 -1
  29. data/lib/test/unit/test-suite-creator.rb +30 -9
  30. data/lib/test/unit/testcase.rb +349 -196
  31. data/lib/test/unit/testresult.rb +7 -0
  32. data/lib/test/unit/testsuite.rb +1 -1
  33. data/lib/test/unit/ui/console/testrunner.rb +171 -60
  34. data/lib/test/unit/ui/emacs/testrunner.rb +5 -5
  35. data/lib/test/unit/ui/testrunnermediator.rb +9 -7
  36. data/lib/test/unit/util/backtracefilter.rb +17 -5
  37. data/lib/test/unit/util/memory-usage.rb +47 -0
  38. data/lib/test/unit/util/observable.rb +2 -2
  39. data/lib/test/unit/util/output.rb +5 -4
  40. data/lib/test/unit/util/procwrapper.rb +4 -4
  41. data/lib/test/unit/version.rb +1 -1
  42. data/lib/test/unit/warning.rb +3 -0
  43. data/lib/test/unit.rb +177 -161
  44. data/lib/test-unit.rb +2 -17
  45. metadata +20 -94
  46. data/GPL +0 -339
  47. data/LGPL +0 -502
  48. data/test/collector/test-descendant.rb +0 -178
  49. data/test/collector/test-load.rb +0 -442
  50. data/test/collector/test_dir.rb +0 -406
  51. data/test/collector/test_objectspace.rb +0 -100
  52. data/test/fixtures/header-label.csv +0 -3
  53. data/test/fixtures/header-label.tsv +0 -3
  54. data/test/fixtures/header.csv +0 -3
  55. data/test/fixtures/header.tsv +0 -3
  56. data/test/fixtures/no-header.csv +0 -2
  57. data/test/fixtures/no-header.tsv +0 -2
  58. data/test/fixtures/plus.csv +0 -3
  59. data/test/run-test.rb +0 -22
  60. data/test/test-assertions.rb +0 -2157
  61. data/test/test-attribute-matcher.rb +0 -38
  62. data/test/test-attribute.rb +0 -123
  63. data/test/test-code-snippet.rb +0 -37
  64. data/test/test-color-scheme.rb +0 -82
  65. data/test/test-color.rb +0 -47
  66. data/test/test-data.rb +0 -281
  67. data/test/test-diff.rb +0 -518
  68. data/test/test-emacs-runner.rb +0 -60
  69. data/test/test-error.rb +0 -26
  70. data/test/test-failure.rb +0 -33
  71. data/test/test-fault-location-detector.rb +0 -163
  72. data/test/test-fixture.rb +0 -659
  73. data/test/test-notification.rb +0 -33
  74. data/test/test-omission.rb +0 -81
  75. data/test/test-pending.rb +0 -70
  76. data/test/test-priority.rb +0 -173
  77. data/test/test-test-case.rb +0 -1171
  78. data/test/test-test-result.rb +0 -113
  79. data/test/test-test-suite-creator.rb +0 -97
  80. data/test/test-test-suite.rb +0 -150
  81. data/test/testunit-test-util.rb +0 -31
  82. data/test/ui/test_testrunmediator.rb +0 -20
  83. data/test/util/test-method-owner-finder.rb +0 -38
  84. data/test/util/test-output.rb +0 -11
  85. data/test/util/test_backtracefilter.rb +0 -41
  86. data/test/util/test_observable.rb +0 -102
  87. data/test/util/test_procwrapper.rb +0 -36
@@ -1,2157 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- #
3
- # Author:: Nathaniel Talbott.
4
- # Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved.
5
- # Copyright (c) 2009-2014 Kouhei Sutou. All rights reserved.
6
- # License:: Ruby license.
7
-
8
- require 'test/unit'
9
- require "testunit-test-util"
10
-
11
- module Test
12
- module Unit
13
- module AssertionCheckable
14
- include TestUnitTestUtil
15
-
16
- private
17
- def check(value, message="")
18
- add_assertion
19
- raise AssertionFailedError.new(message) unless value
20
- end
21
-
22
- def check_assertions(expect_fail, options={})
23
- expected_message = options[:expected_message]
24
- actual_message_normalizer = options[:actual_message_normalizer]
25
- return_value_expected = options[:return_value_expected]
26
- @actual_assertion_count = 0
27
- failed = true
28
- actual_message = nil
29
- @catch_assertions = true
30
- return_value = nil
31
- begin
32
- return_value = yield
33
- failed = false
34
- rescue AssertionFailedError => error
35
- actual_message = error.message
36
- end
37
- @catch_assertions = false
38
-
39
- if expect_fail
40
- message = "Should have failed, but didn't"
41
- else
42
- message = "Should not have failed, but did with message\n" +
43
- "<#{actual_message}>"
44
- end
45
- check(expect_fail == failed, message)
46
-
47
- message = "Should have made one assertion but made\n" +
48
- "<#{@actual_assertion_count}>"
49
- check(1 == @actual_assertion_count, message)
50
-
51
- if expect_fail
52
- if actual_message_normalizer
53
- actual_message = actual_message_normalizer.call(actual_message)
54
- end
55
- case expected_message
56
- when String
57
- check(expected_message == actual_message,
58
- "Should have the correct message.\n" +
59
- "<#{expected_message.inspect}> expected but was\n" +
60
- "<#{actual_message.inspect}>")
61
- when Regexp
62
- check(expected_message =~ actual_message,
63
- "The message should match correctly.\n" +
64
- "</#{expected_message.source}/> expected to match\n" +
65
- "<#{actual_message.inspect}>")
66
- else
67
- check(false,
68
- "Incorrect expected message type in assert_nothing_failed")
69
- end
70
- else
71
- if return_value_expected
72
- check(!return_value.nil?, "Should return a value")
73
- else
74
- check(return_value.nil?,
75
- "Should not return a value but returned <#{return_value}>")
76
- end
77
- end
78
-
79
- return_value
80
- end
81
-
82
- def check_nothing_fails(return_value_expected=false, &proc)
83
- check_assertions(false,
84
- {:expected_message => nil,
85
- :return_value_expected => return_value_expected},
86
- &proc)
87
- end
88
-
89
- def check_fail(expected_message, options={}, &proc)
90
- check_assertions(true,
91
- options.merge(:expected_message => expected_message),
92
- &proc)
93
- end
94
-
95
- def check_fail_exception(expected_message, options={}, &proc)
96
- normalizer = lambda do |actual_message|
97
- actual_message.gsub(/(^[^:\n]+:\d+:.+\n?)+\z/, "")
98
- end
99
- check_assertions(true,
100
- options.merge(:expected_message => expected_message,
101
- :actual_message_normalizer => normalizer),
102
- &proc)
103
- end
104
-
105
- def inspect_tag(tag)
106
- tag.inspect
107
- end
108
-
109
- def add_failure(message, location=caller, options=nil)
110
- unless @catch_assertions
111
- super
112
- end
113
- end
114
-
115
- def add_assertion
116
- if @catch_assertions
117
- @actual_assertion_count += 1
118
- else
119
- super
120
- end
121
- end
122
- end
123
-
124
- class TestAssertions < TestCase
125
- include AssertionCheckable
126
-
127
- class TestAssertBlock < self
128
- def test_pass_without_message
129
- check_nothing_fails {
130
- assert_block {true}
131
- }
132
- end
133
-
134
- def test_pass_with_message
135
- check_nothing_fails {
136
- assert_block("successful assert_block") {true}
137
- }
138
- end
139
-
140
- def test_failure_without_message
141
- check_fail("assert_block failed.") {
142
- assert_block {false}
143
- }
144
- end
145
-
146
- def test_failure_with_message
147
- check_fail("failed assert_block") {
148
- assert_block("failed assert_block") {false}
149
- }
150
- end
151
- end
152
-
153
- class TestAssertEqual < self
154
- class TestSuccess < self
155
- def test_without_message
156
- check_nothing_fails {
157
- assert_equal("string1", "string1")
158
- }
159
- end
160
-
161
- def test_with_message
162
- check_nothing_fails {
163
- assert_equal("string1", "string1", "successful assert_equal")
164
- }
165
- end
166
- end
167
-
168
- class TestFailure < self
169
- def test_without_message
170
- message = <<-EOM.chomp
171
- <"string1"> expected but was
172
- <"string2">.
173
-
174
- diff:
175
- - string1
176
- ? ^
177
- + string2
178
- ? ^
179
- EOM
180
- check_fail(message) {
181
- assert_equal("string1", "string2")
182
- }
183
- end
184
-
185
- def test_with_message
186
- message = <<-EOM.chomp
187
- failed assert_equal.
188
- <"string1"> expected but was
189
- <"string2">.
190
-
191
- diff:
192
- - string1
193
- ? ^
194
- + string2
195
- ? ^
196
- EOM
197
- check_fail(message) {
198
- assert_equal("string1", "string2", "failed assert_equal")
199
- }
200
- end
201
-
202
- def test_with_message_proc
203
- message = <<-EOM.chomp
204
- failed assert_equal.
205
- <"string1"> expected but was
206
- <"string2">.
207
-
208
- diff:
209
- - string1
210
- ? ^
211
- + string2
212
- ? ^
213
- EOM
214
- check_fail(message) do
215
- assert_equal("string1", "string2", lambda {"failed assert_equal"})
216
- end
217
- end
218
- end
219
-
220
- class TestSystemMessage < self
221
- def test_different_type
222
- message = <<-EOM.chomp
223
- <"111111"> expected but was
224
- <111111>.
225
-
226
- diff:
227
- - "111111"
228
- ? - -
229
- + 111111
230
- EOM
231
- check_fail(message) do
232
- assert_equal("111111", 111111)
233
- end
234
- end
235
-
236
- def test_long_line
237
- expected = ["0123456789",
238
- "1123456789",
239
- "2123456789",
240
- "3123456789",
241
- "4123456789",
242
- "5123456789",
243
- "6123456789",
244
- "7123456789",
245
- "8123456789"].join
246
- actual = ["0000000000",
247
- "1123456789",
248
- "2123456789",
249
- "3123456789",
250
- "4123456789",
251
- "5123456789",
252
- "6123456789",
253
- "7123456789",
254
- "8123456789"].join
255
- message = <<-EOM.chomp
256
- <"#{expected}"> expected but was
257
- <"#{actual}">.
258
-
259
- diff:
260
- - #{expected}
261
- ? ^^^^^^^^^
262
- + #{actual}
263
- ? ^^^^^^^^^
264
-
265
- folded diff:
266
- - 012345678911234567892123456789312345678941234567895123456789612345678971234567
267
- ? ^^^^^^^^^
268
- + 000000000011234567892123456789312345678941234567895123456789612345678971234567
269
- ? ^^^^^^^^^
270
- 898123456789
271
- EOM
272
- check_fail(message) do
273
- assert_equal(expected, actual)
274
- end
275
- end
276
-
277
- def test_too_small_difference
278
- message = <<-EOM.chomp
279
- <1> expected but was
280
- <2>.
281
- EOM
282
- check_fail(message) do
283
- assert_equal(1, 2)
284
- end
285
- end
286
-
287
- def test_same_inspected_objects
288
- now = Time.now
289
- now_without_usec = Time.at(now.to_i)
290
- message = <<-EOM.chomp
291
- <#{now.inspect}> expected but was
292
- <#{now.inspect}>.
293
- EOM
294
- check_fail(message) do
295
- assert_equal(now, now_without_usec)
296
- end
297
- end
298
-
299
- def test_multi_lines_result
300
- message = <<-EOM.chomp
301
- <#{"a\nb".inspect}> expected but was
302
- <#{"x".inspect}>.
303
-
304
- diff:
305
- + x
306
- - a
307
- - b
308
- EOM
309
- check_fail(message) do
310
- assert_equal("a\nb", "x")
311
- end
312
- end
313
-
314
- def test_large_string
315
- message = <<-EOM.chomp
316
- <#{("a\n" + "x" * 997).inspect}> expected but was
317
- <#{"x".inspect}>.
318
-
319
- diff:
320
- + x
321
- - a
322
- - #{"x" * 997}
323
-
324
- folded diff:
325
- + x
326
- - a
327
- #{(["- " + ("x" * 78)] * 12).join("\n")}
328
- - #{"x" * 61}
329
- EOM
330
- check_fail(message) do
331
- assert_equal("a\n" + "x" * 997, "x")
332
- end
333
-
334
- message = <<-EOM.chomp
335
- <#{("a\n" + "x" * 998).inspect}> expected but was
336
- <#{"x".inspect}>.
337
- EOM
338
- check_fail(message) do
339
- assert_equal("a\n" + "x" * 998, "x")
340
- end
341
- end
342
-
343
- def test_max_diff_target_string_size
344
- key = "TEST_UNIT_MAX_DIFF_TARGET_STRING_SIZE"
345
- before_value = ENV[key]
346
- ENV[key] = "100"
347
- begin
348
- message = <<-EOM.chomp
349
- <#{("a\n" + "x" * 97).inspect}> expected but was
350
- <#{"x".inspect}>.
351
-
352
- diff:
353
- + x
354
- - a
355
- - #{"x" * 97}
356
-
357
- folded diff:
358
- + x
359
- - a
360
- #{(["- " + ("x" * 78)]).join("\n")}
361
- - #{"x" * 19}
362
- EOM
363
- check_fail(message) do
364
- assert_equal("a\n" + "x" * 97, "x")
365
- end
366
-
367
- message = <<-EOM.chomp
368
- <#{("a\n" + "x" * 98).inspect}> expected but was
369
- <#{"x".inspect}>.
370
- EOM
371
- check_fail(message) do
372
- assert_equal("a\n" + "x" * 98, "x")
373
- end
374
- ensure
375
- ENV[key] = before_value
376
- end
377
- end
378
-
379
- def test_different_encoding
380
- utf8_string = "こんにちは"
381
- unless utf8_string.respond_to?(:force_encoding)
382
- omit("encoding test is for Ruby >= 1.9")
383
- end
384
- ascii_8bit_string = utf8_string.dup.force_encoding("ascii-8bit")
385
- message = <<-EOM.chomp
386
- <#{utf8_string.inspect}>("UTF-8") expected but was
387
- <#{ascii_8bit_string.inspect}>("ASCII-8BIT").
388
- EOM
389
- check_fail(message) do
390
- assert_equal(utf8_string, ascii_8bit_string)
391
- end
392
- end
393
-
394
- def test_different_hash
395
- designers = {
396
- "Ruby" => "Matz",
397
- "Lisp" => "John McCarthy",
398
- }
399
- categories = {
400
- "LL" => ["Ruby", "Python"],
401
- "Heavy" => ["C", "C++"],
402
- }
403
- message = <<-EOM.chomp
404
- <{"Lisp"=>"John McCarthy", "Ruby"=>"Matz"}> expected but was
405
- <{"Heavy"=>["C", "C++"], "LL"=>["Ruby", "Python"]}>.
406
- EOM
407
- check_fail(message) do
408
- assert_equal(designers, categories)
409
- end
410
- end
411
-
412
- def test_recursive_hash
413
- alice = {"name" => "Alice"}
414
- bob = {"name" => "Bob"}
415
- alice["followers"] = [bob]
416
- bob["followers"] = [alice]
417
- message = <<-EOM.chomp
418
- <{"followers"=>[{"followers"=>[{...}], "name"=>"Bob"}], "name"=>"Alice"}> expected but was
419
- <{"followers"=>[{"followers"=>[{...}], "name"=>"Alice"}], "name"=>"Bob"}>.
420
-
421
- diff:
422
- - {"followers"=>[{"followers"=>[{...}], "name"=>"Bob"}], "name"=>"Alice"}
423
- ? -----------------
424
- + {"followers"=>[{"followers"=>[{...}], "name"=>"Alice"}], "name"=>"Bob"}
425
- ? +++++++++++++++++
426
- EOM
427
- check_fail(message) do
428
- assert_equal(alice, bob)
429
- end
430
- end
431
-
432
- def test_numeric
433
- numeric_family_class = Class.new(Numeric) do
434
- def inspect
435
- "inspect is called"
436
- end
437
-
438
- def to_s
439
- "to_s is called"
440
- end
441
- end
442
- numeric = numeric_family_class.new
443
-
444
- message = <<-MESSAGE.chomp
445
- <to_s is called> expected but was
446
- <"must be failed">.
447
- MESSAGE
448
- check_fail(message) do
449
- assert_equal(numeric, "must be failed")
450
- end
451
- end
452
- end
453
- end
454
-
455
- def test_assert_raise_success
456
- return_value = nil
457
- check_nothing_fails(true) do
458
- return_value = assert_raise(RuntimeError) do
459
- raise "Error"
460
- end
461
- end
462
- check(return_value.kind_of?(Exception),
463
- "Should have returned the exception " +
464
- "from a successful assert_raise")
465
- check(return_value.message == "Error",
466
- "Should have returned the correct exception " +
467
- "from a successful assert_raise")
468
-
469
- check_nothing_fails(true) do
470
- assert_raise(ArgumentError, "successful assert_raise") do
471
- raise ArgumentError.new("Error")
472
- end
473
- end
474
-
475
- check_nothing_fails(true) do
476
- assert_raise(RuntimeError) do
477
- raise "Error"
478
- end
479
- end
480
-
481
- check_nothing_fails(true) do
482
- assert_raise(RuntimeError, "successful assert_raise") do
483
- raise "Error"
484
- end
485
- end
486
-
487
- check_nothing_fails(true) do
488
- assert_raise do
489
- raise Exception, "Any exception"
490
- end
491
- end
492
- end
493
-
494
- def test_assert_raise_fail
495
- check_fail("<RuntimeError> exception expected but none was thrown.") do
496
- assert_raise(RuntimeError) do
497
- 1 + 1
498
- end
499
- end
500
-
501
- message = <<-EOM.chomp
502
- failed assert_raise.
503
- <ArgumentError> exception expected but was
504
- <RuntimeError(<Error>)>.
505
- EOM
506
- check_fail_exception(message) do
507
- assert_raise(ArgumentError, "failed assert_raise") do
508
- raise "Error"
509
- end
510
- end
511
-
512
- message = <<-EOM
513
- Should expect a class of exception, Object.
514
- <false> is not true.
515
- EOM
516
- check_fail(message.chomp) do
517
- assert_nothing_raised(Object) do
518
- 1 + 1
519
- end
520
- end
521
- end
522
-
523
- def test_assert_raise_module
524
- exceptions = [ArgumentError, TypeError]
525
- modules = [Math, Comparable]
526
- rescues = exceptions + modules
527
-
528
- exceptions.each do |exc|
529
- return_value = nil
530
- check_nothing_fails(true) do
531
- return_value = assert_raise(*rescues) do
532
- raise exc, "Error"
533
- end
534
- end
535
- check(return_value.instance_of?(exc),
536
- "Should have returned #{exc} but was #{return_value.class}")
537
- check(return_value.message == "Error",
538
- "Should have returned the correct exception " +
539
- "from a successful assert_raise")
540
- end
541
-
542
- modules.each do |mod|
543
- return_value = nil
544
- check_nothing_fails(true) do
545
- return_value = assert_raise(*rescues) do
546
- raise Exception.new("Error").extend(mod)
547
- end
548
- end
549
- check(mod === return_value,
550
- "Should have returned #{mod}")
551
- check(return_value.message == "Error",
552
- "Should have returned the correct exception " +
553
- "from a successful assert_raise")
554
- end
555
-
556
- check_fail("<[ArgumentError, TypeError, Math, Comparable]> exception " +
557
- "expected but none was thrown.") do
558
- assert_raise(*rescues) do
559
- 1 + 1
560
- end
561
- end
562
-
563
- message = <<-EOM.chomp
564
- failed assert_raise.
565
- <[ArgumentError, TypeError]> exception expected but was
566
- <RuntimeError(<Error>)>.
567
- EOM
568
- check_fail_exception(message) do
569
- assert_raise(ArgumentError, TypeError, "failed assert_raise") do
570
- raise "Error"
571
- end
572
- end
573
- end
574
-
575
- def test_assert_raise_instance
576
- return_value = nil
577
- check_nothing_fails(true) do
578
- return_value = assert_raise(RuntimeError.new("Error")) do
579
- raise "Error"
580
- end
581
- end
582
- check(return_value.kind_of?(Exception),
583
- "Should have returned the exception " +
584
- "from a successful assert_raise")
585
- check(return_value.message == "Error",
586
- "Should have returned the correct exception " +
587
- "from a successful assert_raise")
588
-
589
- message = <<-EOM.chomp
590
- <RuntimeError(<XXX>)> exception expected but was
591
- <RuntimeError(<Error>)>.
592
-
593
- diff:
594
- - RuntimeError(<XXX>)
595
- ? ^^^
596
- + RuntimeError(<Error>)
597
- ? ^^^^^
598
- EOM
599
- check_fail_exception(message) do
600
- return_value = assert_raise(RuntimeError.new("XXX")) do
601
- raise "Error"
602
- end
603
- end
604
-
605
- different_error_class = Class.new(StandardError)
606
- message = <<-EOM.chomp
607
- <#{different_error_class.inspect}(<Error>)> exception expected but was
608
- <RuntimeError(<Error>)>.
609
- EOM
610
- check_fail_exception(message) do
611
- assert_raise(different_error_class.new("Error")) do
612
- raise "Error"
613
- end
614
- end
615
-
616
- different_error = different_error_class.new("Error")
617
- def different_error.inspect
618
- "DifferentError: \"Error\""
619
- end
620
- message = <<-EOM.chomp
621
- <DifferentError: "Error"> exception expected but was
622
- <RuntimeError(<Error>)>.
623
- EOM
624
- check_fail_exception(message) do
625
- assert_raise(different_error) do
626
- raise "Error"
627
- end
628
- end
629
-
630
- check_nothing_fails(true) do
631
- assert_raise(different_error_class.new("Error"),
632
- RuntimeError.new("Error"),
633
- RuntimeError.new("XXX")) do
634
- raise "Error"
635
- end
636
- end
637
- end
638
-
639
- def test_assert_instance_of
640
- check_nothing_fails {
641
- assert_instance_of(String, "string")
642
- }
643
- check_nothing_fails {
644
- assert_instance_of(String, "string", "successful assert_instance_of")
645
- }
646
- check_nothing_fails {
647
- assert_instance_of(String, "string", "successful assert_instance_of")
648
- }
649
- check_fail(%Q{<"string"> expected to be instance_of?\n<Hash> but was\n<String>.}) {
650
- assert_instance_of(Hash, "string")
651
- }
652
- check_fail(%Q{failed assert_instance_of.\n<"string"> expected to be instance_of?\n<Hash> but was\n<String>.}) {
653
- assert_instance_of(Hash, "string", "failed assert_instance_of")
654
- }
655
-
656
- check_nothing_fails do
657
- assert_instance_of([Fixnum, NilClass], 100)
658
- end
659
- check_fail(%Q{<"string"> expected to be instance_of?\n[<Fixnum>, <NilClass>] but was\n<String>.}) do
660
- assert_instance_of([Fixnum, NilClass], "string")
661
- end
662
- check_fail(%Q{<100> expected to be instance_of?\n[<Numeric>, <NilClass>] but was\n<Fixnum>.}) do
663
- assert_instance_of([Numeric, NilClass], 100)
664
- end
665
- end
666
-
667
- def test_assert_not_instance_of
668
- check_nothing_fails {
669
- assert_not_instance_of(NilClass, "string")
670
- }
671
- check_nothing_fails {
672
- assert_not_instance_of(NilClass, "string", "successful assert_instance_of")
673
- }
674
- check_fail(%Q{<"string"> expected to not be instance_of?\n<String> but was.}) {
675
- assert_not_instance_of(String, "string")
676
- }
677
- check_fail(%Q{failed assert.\n<"string"> expected to not be instance_of?\n<String> but was.}) {
678
- assert_not_instance_of(String, "string", "failed assert")
679
- }
680
-
681
- check_nothing_fails do
682
- assert_not_instance_of([Numeric, NilClass], 100)
683
- end
684
- check_fail(%Q{<100> expected to not be instance_of?\n[<Fixnum>, <NilClass>] but was.}) do
685
- assert_not_instance_of([Fixnum, NilClass], 100)
686
- end
687
- check_fail(%Q{<"str"> expected to not be instance_of?\n[<Numeric>, <String>] but was.}) do
688
- assert_not_instance_of([Numeric, String], 'str')
689
- end
690
- end
691
-
692
- def test_assert_nil
693
- check_nothing_fails {
694
- assert_nil(nil)
695
- }
696
- check_nothing_fails {
697
- assert_nil(nil, "successful assert_nil")
698
- }
699
- check_nothing_fails {
700
- assert_nil(nil, "successful assert_nil")
701
- }
702
- check_fail(%Q{<"string"> expected to be nil.}) {
703
- assert_nil("string")
704
- }
705
- check_fail(%Q{failed assert_nil.\n<"string"> expected to be nil.}) {
706
- assert_nil("string", "failed assert_nil")
707
- }
708
- end
709
-
710
- def test_assert_not_nil
711
- check_nothing_fails{assert_not_nil(false)}
712
- check_nothing_fails{assert_not_nil(false, "message")}
713
- check_fail("<nil> expected to not be nil."){assert_not_nil(nil)}
714
- check_fail("message.\n<nil> expected to not be nil.") {assert_not_nil(nil, "message")}
715
- end
716
-
717
- def test_assert_kind_of
718
- check_nothing_fails {
719
- assert_kind_of(Module, Array)
720
- }
721
- check_nothing_fails {
722
- assert_kind_of(Object, "string", "successful assert_kind_of")
723
- }
724
- check_nothing_fails {
725
- assert_kind_of(String, "string", "successful assert_kind_of")
726
- }
727
- check_nothing_fails {
728
- assert_kind_of(Comparable, 1)
729
- }
730
- check_fail(%Q{<"string"> expected to be kind_of?\n<Class> but was\n<String>.}) {
731
- assert_kind_of(Class, "string")
732
- }
733
- check_fail(%Q{failed assert_kind_of.\n<"string"> expected to be kind_of?\n<Class> but was\n<String>.}) {
734
- assert_kind_of(Class, "string", "failed assert_kind_of")
735
- }
736
-
737
- check_nothing_fails do
738
- assert_kind_of([Fixnum, NilClass], 100)
739
- end
740
- check_fail(%Q{<"string"> expected to be kind_of?\n[<Fixnum>, <NilClass>] but was\n<String>.}) do
741
- assert_kind_of([Fixnum, NilClass], "string")
742
- end
743
- end
744
-
745
- def test_assert_not_kind_of
746
- check_nothing_fails {
747
- assert_not_kind_of(Class, 42)
748
- }
749
- check_nothing_fails {
750
- assert_not_kind_of(Symbol, "string", "successful assert_not_kind_of")
751
- }
752
- check_nothing_fails {
753
- assert_not_kind_of(Integer, 1.1)
754
- }
755
- check_fail(%Q{<1> expected to not be kind_of?\n<Integer> but was.}) {
756
- assert_not_kind_of(Integer, 1)
757
- }
758
- check_fail(%Q{failed assert_not_kind_of.\n<"string"> expected to not be kind_of?\n<String> but was.}) {
759
- assert_not_kind_of(String, "string", "failed assert_not_kind_of")
760
- }
761
-
762
- check_nothing_fails do
763
- assert_not_kind_of([String, NilClass], 100)
764
- end
765
- check_fail(%Q{<100> expected to not be kind_of?\n[<Fixnum>, <NilClass>] but was.}) do
766
- assert_not_kind_of([Fixnum, NilClass], 100)
767
- end
768
- end
769
-
770
- def test_assert_match
771
- check_nothing_fails {
772
- assert_match(/strin./, "string")
773
- }
774
- check_nothing_fails {
775
- assert_match("strin", "string")
776
- }
777
- check_nothing_fails {
778
- assert_match(/strin./, "string", "successful assert_match")
779
- }
780
- check_nothing_fails {
781
- assert_match(/strin./, "string", "successful assert_match")
782
- }
783
- check_fail(%Q{</slin./> expected to be =~\n<"string">.}) {
784
- assert_match(/slin./, "string")
785
- }
786
- check_fail(%Q{</strin\\./> expected to be =~\n<"string">.}) {
787
- assert_match("strin.", "string")
788
- }
789
- check_fail(%Q{failed assert_match.\n</slin./> expected to be =~\n<"string">.}) {
790
- assert_match(/slin./, "string", "failed assert_match")
791
- }
792
- end
793
-
794
- def test_assert_same
795
- thing = "thing"
796
- check_nothing_fails {
797
- assert_same(thing, thing)
798
- }
799
- check_nothing_fails {
800
- assert_same(thing, thing, "successful assert_same")
801
- }
802
- check_nothing_fails {
803
- assert_same(thing, thing, "successful assert_same")
804
- }
805
- thing2 = "thing"
806
- check_fail(%Q{<"thing">\nwith id <#{thing.__id__}> expected to be equal? to\n<"thing">\nwith id <#{thing2.__id__}>.}) {
807
- assert_same(thing, thing2)
808
- }
809
- check_fail(%Q{failed assert_same.\n<"thing">\nwith id <#{thing.__id__}> expected to be equal? to\n<"thing">\nwith id <#{thing2.__id__}>.}) {
810
- assert_same(thing, thing2, "failed assert_same")
811
- }
812
- end
813
-
814
- def test_assert_nothing_raised
815
- check_nothing_fails {
816
- assert_nothing_raised {
817
- 1 + 1
818
- }
819
- }
820
- check_nothing_fails {
821
- assert_nothing_raised("successful assert_nothing_raised") {
822
- 1 + 1
823
- }
824
- }
825
- check_nothing_fails {
826
- assert_nothing_raised("successful assert_nothing_raised") {
827
- 1 + 1
828
- }
829
- }
830
- check_nothing_fails {
831
- begin
832
- assert_nothing_raised(RuntimeError, StandardError, Comparable, "successful assert_nothing_raised") {
833
- raise ZeroDivisionError.new("ArgumentError")
834
- }
835
- rescue ZeroDivisionError
836
- end
837
- }
838
- check_fail("Should expect a class of exception, Object.\n<false> is not true.") {
839
- assert_nothing_raised(Object) {
840
- 1 + 1
841
- }
842
- }
843
- expected_message = <<-EOM.chomp
844
- Exception raised:
845
- RuntimeError(<Error>)
846
- EOM
847
- check_fail_exception(expected_message) {
848
- assert_nothing_raised {
849
- raise "Error"
850
- }
851
- }
852
- expected_message = <<-EOM.chomp
853
- failed assert_nothing_raised.
854
- Exception raised:
855
- RuntimeError(<Error>)
856
- EOM
857
- check_fail_exception(expected_message) {
858
- assert_nothing_raised("failed assert_nothing_raised") {
859
- raise "Error"
860
- }
861
- }
862
- expected_message = <<-EOM.chomp
863
- Exception raised:
864
- RuntimeError(<Error>)
865
- EOM
866
- check_fail_exception(expected_message) {
867
- assert_nothing_raised(StandardError, RuntimeError) {
868
- raise "Error"
869
- }
870
- }
871
- check_fail("Failure.") do
872
- assert_nothing_raised do
873
- flunk("Failure")
874
- end
875
- end
876
- end
877
-
878
- def test_flunk
879
- check_fail("Flunked.") {
880
- flunk
881
- }
882
- check_fail("flunk message.") {
883
- flunk("flunk message")
884
- }
885
- end
886
-
887
- def test_assert_not_same
888
- thing = "thing"
889
- thing2 = "thing"
890
- check_nothing_fails {
891
- assert_not_same(thing, thing2)
892
- }
893
- check_nothing_fails {
894
- assert_not_same(thing, thing2, "message")
895
- }
896
- check_fail(%Q{<"thing">\nwith id <#{thing.__id__}> expected to not be equal? to\n<"thing">\nwith id <#{thing.__id__}>.}) {
897
- assert_not_same(thing, thing)
898
- }
899
- check_fail(%Q{message.\n<"thing">\nwith id <#{thing.__id__}> expected to not be equal? to\n<"thing">\nwith id <#{thing.__id__}>.}) {
900
- assert_not_same(thing, thing, "message")
901
- }
902
- end
903
-
904
- def test_assert_not_equal
905
- check_nothing_fails {
906
- assert_not_equal("string1", "string2")
907
- }
908
- check_nothing_fails {
909
- assert_not_equal("string1", "string2", "message")
910
- }
911
- check_fail(%Q{<"string"> expected to be != to\n<"string">.}) {
912
- assert_not_equal("string", "string")
913
- }
914
- check_fail(%Q{message.\n<"string"> expected to be != to\n<"string">.}) {
915
- assert_not_equal("string", "string", "message")
916
- }
917
- end
918
-
919
- def test_assert_not_match_pass
920
- check_nothing_fails do
921
- assert_not_match(/sling/, "string")
922
- end
923
- end
924
-
925
- def test_assert_not_match_pass_with_message
926
- check_nothing_fails do
927
- assert_not_match(/sling/, "string", "message")
928
- end
929
- end
930
-
931
- def test_assert_not_match_fail_not_regexp
932
- check_fail("<REGEXP> in assert_not_match(<REGEXP>, ...) " +
933
- "should be a Regexp.\n" +
934
- "<\"asdf\"> expected to be instance_of?\n" +
935
- "<Regexp> but was\n" +
936
- "<String>.") do
937
- assert_not_match("asdf", "asdf")
938
- end
939
- end
940
-
941
- def test_assert_not_match_fail_match
942
- check_fail("</string/> expected to not match\n" +
943
- "<\"string\">.") do
944
- assert_not_match(/string/, "string")
945
- end
946
- end
947
-
948
- def test_assert_not_match_fail_match_with_message
949
- check_fail("message.\n" +
950
- "</string/> expected to not match\n" +
951
- "<\"string\">.") do
952
- assert_not_match(/string/, "string", "message")
953
- end
954
- end
955
-
956
- def test_assert_no_match
957
- check_nothing_fails{assert_no_match(/sling/, "string")}
958
- check_nothing_fails{assert_no_match(/sling/, "string", "message")}
959
- check_fail(%Q{The first argument to assert_no_match should be a Regexp.\n<"asdf"> expected to be instance_of?\n<Regexp> but was\n<String>.}) do
960
- assert_no_match("asdf", "asdf")
961
- end
962
- check_fail(%Q{</string/> expected to not match\n<"string">.}) do
963
- assert_no_match(/string/, "string")
964
- end
965
- check_fail(%Q{message.\n</string/> expected to not match\n<"string">.}) do
966
- assert_no_match(/string/, "string", "message")
967
- end
968
- end
969
-
970
- def test_assert_throw
971
- check_nothing_fails do
972
- assert_throw(:thing, "message") do
973
- throw :thing
974
- end
975
- end
976
-
977
- tag = :thing2
978
- check_fail("message.\n" +
979
- "<:thing> expected to be thrown but\n" +
980
- "<#{inspect_tag(tag)}> was thrown.") do
981
- assert_throw(:thing, "message") do
982
- throw :thing2
983
- end
984
- end
985
- check_fail("message.\n" +
986
- "<:thing> should have been thrown.") do
987
- assert_throw(:thing, "message") do
988
- 1 + 1
989
- end
990
- end
991
- end
992
-
993
- def test_assert_nothing_thrown
994
- check_nothing_fails do
995
- assert_nothing_thrown("message") do
996
- 1 + 1
997
- end
998
- end
999
-
1000
- tag = :thing
1001
- inspected = inspect_tag(tag)
1002
- check_fail("message.\n" +
1003
- "<#{inspected}> was thrown when nothing was expected.") do
1004
- assert_nothing_thrown("message") do
1005
- throw tag
1006
- end
1007
- end
1008
- end
1009
-
1010
- def test_assert_operator
1011
- check_nothing_fails {
1012
- assert_operator("thing", :==, "thing", "message")
1013
- }
1014
- check_fail(%Q{<0.15>\ngiven as the operator for #assert_operator must be a Symbol or #respond_to?(:to_str).}) do
1015
- assert_operator("thing", 0.15, "thing")
1016
- end
1017
- check_fail(%Q{message.\n<"thing1"> expected to be\n==\n<"thing2">.}) {
1018
- assert_operator("thing1", :==, "thing2", "message")
1019
- }
1020
- end
1021
-
1022
- def test_assert_not_operator
1023
- check_nothing_fails {
1024
- assert_not_operator("thing", :==, "Thing", "message")
1025
- }
1026
- check_fail(%Q{<42>\ngiven as the operator for #assert_not_operator must be a Symbol or #respond_to?(:to_str).}) do
1027
- assert_not_operator("thing", 42, "message")
1028
- end
1029
- check_fail(%Q{message.\n<0> expected to not be\n==\n<0.0>.}) {
1030
- assert_not_operator(0, :==, 0.0, "message")
1031
- }
1032
- end
1033
-
1034
- def test_assert_respond_to
1035
- check_nothing_fails {
1036
- assert_respond_to("thing", :to_s, "message")
1037
- }
1038
- check_nothing_fails {
1039
- assert_respond_to("thing", "to_s", "message")
1040
- }
1041
- check_fail("<0.15>.kind_of?(Symbol) or\n" +
1042
- "<0.15>.respond_to?(:to_str) expected") {
1043
- assert_respond_to("thing", 0.15)
1044
- }
1045
- check_fail("message.\n" +
1046
- "<:symbol>.respond_to?(:nonexistence) expected\n" +
1047
- "(Class: <Symbol>)") {
1048
- assert_respond_to(:symbol, :nonexistence, "message")
1049
- }
1050
- end
1051
-
1052
- def test_assert_not_respond_to_pass_symbol
1053
- check_nothing_fails do
1054
- assert_not_respond_to("thing", :nonexistent, "message")
1055
- end
1056
- end
1057
-
1058
- def test_assert_not_respond_to_pass_string
1059
- check_nothing_fails do
1060
- assert_not_respond_to("thing", :nonexistent, "message")
1061
- end
1062
- end
1063
-
1064
- def test_assert_not_respond_to_fail_number
1065
- check_fail("<0.15>.kind_of?(Symbol) or\n" +
1066
- "<0.15>.respond_to?(:to_str) expected") do
1067
- assert_respond_to("thing", 0.15)
1068
- end
1069
- end
1070
-
1071
- def tset_assert_not_respond_to_fail_existence
1072
- check_fail("message.\n" +
1073
- "!<:symbol>.respond_to?(:to_s) expected\n" +
1074
- "(Class: <Symbol>)") do
1075
- assert_respond_to(:symbol, :to_s, "message")
1076
- end
1077
- end
1078
-
1079
- def test_assert_send
1080
- object = Object.new
1081
- class << object
1082
- private
1083
- def return_argument(argument, bogus)
1084
- return argument
1085
- end
1086
- end
1087
- check_nothing_fails do
1088
- assert_send([object, :return_argument, true, "bogus"], "message")
1089
- end
1090
-
1091
- inspected_object = AssertionMessage.convert(object)
1092
- expected_message = <<-EOM
1093
- message.
1094
- <#{inspected_object}> expected to respond to
1095
- <return_argument(*[false, "bogus"])> with a true value but was
1096
- <false>.
1097
- EOM
1098
- check_fail(expected_message.chomp) do
1099
- assert_send([object, :return_argument, false, "bogus"], "message")
1100
- end
1101
- end
1102
-
1103
- def test_condition_invariant
1104
- object = Object.new
1105
- def object.inspect
1106
- @changed = true
1107
- end
1108
- def object.==(other)
1109
- @changed ||= false
1110
- return (!@changed)
1111
- end
1112
- check_nothing_fails do
1113
- assert_equal(object, object, "message")
1114
- end
1115
- end
1116
-
1117
- def test_assert_boolean
1118
- check_nothing_fails do
1119
- assert_boolean(true)
1120
- end
1121
- check_nothing_fails do
1122
- assert_boolean(false)
1123
- end
1124
-
1125
- check_fail("<true> or <false> expected but was\n<1>") do
1126
- assert_boolean(1)
1127
- end
1128
-
1129
- check_fail("<true> or <false> expected but was\n<nil>") do
1130
- assert_boolean(nil)
1131
- end
1132
-
1133
- check_fail("message.\n<true> or <false> expected but was\n<\"XXX\">") do
1134
- assert_boolean("XXX", "message")
1135
- end
1136
- end
1137
-
1138
- def test_assert_true
1139
- check_nothing_fails do
1140
- assert_true(true)
1141
- end
1142
-
1143
- check_fail("<true> expected but was\n<false>") do
1144
- assert_true(false)
1145
- end
1146
-
1147
- check_fail("<true> expected but was\n<1>") do
1148
- assert_true(1)
1149
- end
1150
-
1151
- check_fail("message.\n<true> expected but was\n<nil>") do
1152
- assert_true(nil, "message")
1153
- end
1154
- end
1155
-
1156
- def test_assert_false
1157
- check_nothing_fails do
1158
- assert_false(false)
1159
- end
1160
-
1161
- check_fail("<false> expected but was\n<true>") do
1162
- assert_false(true)
1163
- end
1164
-
1165
- check_fail("<false> expected but was\n<nil>") do
1166
- assert_false(nil)
1167
- end
1168
-
1169
- check_fail("message.\n<false> expected but was\n<:false>") do
1170
- assert_false(:false, "message")
1171
- end
1172
- end
1173
-
1174
- def test_assert_compare
1175
- check_nothing_fails do
1176
- assert_compare(1.4, "<", 10.0)
1177
- end
1178
-
1179
- check_nothing_fails do
1180
- assert_compare(2, "<=", 2)
1181
- end
1182
-
1183
- check_nothing_fails do
1184
- assert_compare(14, ">=", 10.0)
1185
- end
1186
-
1187
- check_nothing_fails do
1188
- assert_compare(14, ">", 13.9)
1189
- end
1190
-
1191
- expected_message = <<-EOM
1192
- <15> < <10> should be true
1193
- <15> expected less than
1194
- <10>.
1195
- EOM
1196
- check_fail(expected_message.chomp) do
1197
- assert_compare(15, "<", 10)
1198
- end
1199
-
1200
- expected_message = <<-EOM
1201
- <15> <= <10> should be true
1202
- <15> expected less than or equal to
1203
- <10>.
1204
- EOM
1205
- check_fail(expected_message.chomp) do
1206
- assert_compare(15, "<=", 10)
1207
- end
1208
-
1209
- expected_message = <<-EOM
1210
- <10> > <15> should be true
1211
- <10> expected greater than
1212
- <15>.
1213
- EOM
1214
- check_fail(expected_message.chomp) do
1215
- assert_compare(10, ">", 15)
1216
- end
1217
-
1218
- expected_message = <<-EOM
1219
- <10> >= <15> should be true
1220
- <10> expected greater than or equal to
1221
- <15>.
1222
- EOM
1223
- check_fail(expected_message.chomp) do
1224
- assert_compare(10, ">=", 15)
1225
- end
1226
- end
1227
-
1228
- def test_assert_fail_assertion
1229
- check_nothing_fails do
1230
- assert_fail_assertion do
1231
- flunk
1232
- end
1233
- end
1234
-
1235
- check_fail("Failed assertion was expected.") do
1236
- assert_fail_assertion do
1237
- end
1238
- end
1239
- end
1240
-
1241
- def test_assert_raise_message
1242
- check_nothing_fails do
1243
- assert_raise_message("Raise!") do
1244
- raise "Raise!"
1245
- end
1246
- end
1247
-
1248
- check_nothing_fails do
1249
- assert_raise_message("Raise!") do
1250
- raise Exception, "Raise!"
1251
- end
1252
- end
1253
-
1254
- check_nothing_fails do
1255
- assert_raise_message(/raise/i) do
1256
- raise "Raise!"
1257
- end
1258
- end
1259
-
1260
- expected_message = <<-EOM
1261
- <"Expected message"> exception message expected but was
1262
- <"Actual message">.
1263
- EOM
1264
- check_fail(expected_message.chomp) do
1265
- assert_raise_message("Expected message") do
1266
- raise "Actual message"
1267
- end
1268
- end
1269
-
1270
- expected_message = <<-EOM
1271
- <"Expected message"> exception message expected but none was thrown.
1272
- EOM
1273
- check_fail(expected_message.chomp) do
1274
- assert_raise_message("Expected message") do
1275
- end
1276
- end
1277
- end
1278
-
1279
- def test_assert_raise_kind_of
1280
- check_nothing_fails(true) do
1281
- assert_raise_kind_of(SystemCallError) do
1282
- raise Errno::EACCES
1283
- end
1284
- end
1285
-
1286
- expected_message = <<-EOM.chomp
1287
- <SystemCallError> family exception expected but was
1288
- <RuntimeError(<XXX>)>.
1289
- EOM
1290
- check_fail_exception(expected_message) do
1291
- assert_raise_kind_of(SystemCallError) do
1292
- raise RuntimeError, "XXX"
1293
- end
1294
- end
1295
- end
1296
-
1297
- def test_assert_const_defined
1298
- check_nothing_fails do
1299
- assert_const_defined(Test, :Unit)
1300
- end
1301
-
1302
- check_nothing_fails do
1303
- assert_const_defined(Test, "Unit")
1304
- end
1305
-
1306
- check_fail("<Test>.const_defined?(<:Nonexistence>) expected.") do
1307
- assert_const_defined(Test, :Nonexistence)
1308
- end
1309
- end
1310
-
1311
- def test_assert_not_const_defined
1312
- check_nothing_fails do
1313
- assert_not_const_defined(Test, :Nonexistence)
1314
- end
1315
-
1316
- check_fail("!<Test>.const_defined?(<:Unit>) expected.") do
1317
- assert_not_const_defined(Test, :Unit)
1318
- end
1319
-
1320
- check_fail("!<Test>.const_defined?(<\"Unit\">) expected.") do
1321
- assert_not_const_defined(Test, "Unit")
1322
- end
1323
- end
1324
-
1325
- def test_assert_predicate
1326
- check_nothing_fails do
1327
- assert_predicate([], :empty?)
1328
- end
1329
-
1330
- check_fail("<[1]>.empty? is true value expected but was\n<false>") do
1331
- assert_predicate([1], :empty?)
1332
- end
1333
-
1334
- check_fail("<[1]>.respond_to?(:nonexistent?) expected\n" +
1335
- "(Class: <Array>)") do
1336
- assert_predicate([1], :nonexistent?)
1337
- end
1338
- end
1339
-
1340
- def test_assert_not_predicate
1341
- check_nothing_fails do
1342
- assert_not_predicate([1], :empty?)
1343
- end
1344
-
1345
- check_fail("<[]>.empty? is false value expected but was\n<true>") do
1346
- assert_not_predicate([], :empty?)
1347
- end
1348
-
1349
- check_fail("<[]>.respond_to?(:nonexistent?) expected\n" +
1350
- "(Class: <Array>)") do
1351
- assert_not_predicate([], :nonexistent?)
1352
- end
1353
- end
1354
-
1355
- def test_assert_alias_method
1356
- object = Object.new
1357
- class << object
1358
- def original_method
1359
- end
1360
- alias_method :alias_method, :original_method
1361
-
1362
- def other
1363
- end
1364
- end
1365
-
1366
- check_nothing_fails do
1367
- assert_alias_method(object, :alias_method, :original_method)
1368
- end
1369
-
1370
- check_nothing_fails do
1371
- assert_alias_method(object, :original_method, :alias_method)
1372
- end
1373
-
1374
- check_fail("<#{object.method(:other).inspect}> is alias of\n" +
1375
- "<#{object.method(:original_method).inspect}> expected") do
1376
- assert_alias_method(object, :other, :original_method)
1377
- end
1378
-
1379
- inspected_object = AssertionMessage.convert(object)
1380
- check_fail("<#{inspected_object}>.nonexistent doesn't exist\n" +
1381
- "(Class: <Object>)") do
1382
- assert_alias_method(object, :nonexistent, :original_method)
1383
- end
1384
-
1385
- check_fail("<#{inspected_object}>.nonexistent doesn't exist\n" +
1386
- "(Class: <Object>)") do
1387
- assert_alias_method(object, :alias_method, :nonexistent)
1388
- end
1389
- end
1390
-
1391
- def test_assert_path_exist
1392
- check_nothing_fails do
1393
- assert_path_exist(__FILE__)
1394
- end
1395
-
1396
- nonexistent_file = __FILE__ + ".nonexistent"
1397
- check_fail("<#{nonexistent_file.inspect}> expected to exist") do
1398
- assert_path_exist(nonexistent_file)
1399
- end
1400
- end
1401
-
1402
- def test_assert_path_not_exist
1403
- nonexistent_file = __FILE__ + ".nonexistent"
1404
- check_nothing_fails do
1405
- assert_path_not_exist(nonexistent_file)
1406
- end
1407
-
1408
- check_fail("<#{__FILE__.inspect}> expected to not exist") do
1409
- assert_path_not_exist(__FILE__)
1410
- end
1411
- end
1412
- end
1413
-
1414
- class TestAssert < TestCase
1415
- include AssertionCheckable
1416
-
1417
- def test_pass
1418
- check_nothing_fails do
1419
- assert(true)
1420
- end
1421
- end
1422
-
1423
- def test_pass_neither_false_or_nil
1424
- check_nothing_fails do
1425
- assert("a")
1426
- end
1427
- end
1428
-
1429
- def test_pass_with_message
1430
- check_nothing_fails do
1431
- assert(true, "successful assert")
1432
- end
1433
- end
1434
-
1435
- def test_pass_block
1436
- check_nothing_fails do
1437
- assert do
1438
- true
1439
- end
1440
- end
1441
- end
1442
-
1443
- def test_fail_nil
1444
- check_fail("<nil> is not true.") do
1445
- assert(nil)
1446
- end
1447
- end
1448
-
1449
- def test_fail_false
1450
- check_fail("<false> is not true.") do
1451
- assert(false)
1452
- end
1453
- end
1454
-
1455
- def test_fail_false_with_message
1456
- check_fail("failed assert.\n" +
1457
- "<false> is not true.") do
1458
- assert(false, "failed assert")
1459
- end
1460
- end
1461
-
1462
- def test_fail_with_assertion_message
1463
- check_fail("user message.\n" +
1464
- "placeholder <:in> message") do
1465
- assert(false, build_message("user message",
1466
- "placeholder <?> message",
1467
- :in))
1468
- end
1469
- end
1470
-
1471
- def test_fail_block
1472
- check_fail(//) do
1473
- assert do
1474
- 0.odd?
1475
- end
1476
- end
1477
- end
1478
-
1479
- def test_error_invalid_message_true
1480
- check_fail("assertion message must be String, Proc or " +
1481
- "Test::Unit::Assertions::AssertionMessage: " +
1482
- "<true>(<TrueClass>)") do
1483
- begin
1484
- assert(true, true)
1485
- rescue ArgumentError
1486
- raise AssertionFailedError, $!.message
1487
- end
1488
- end
1489
- end
1490
-
1491
- def test_error_wrong_number_of_arguments
1492
- check_fail("wrong number of arguments (0 for 1..2)") do
1493
- begin
1494
- assert
1495
- rescue ArgumentError
1496
- raise AssertionFailedError, $!.message
1497
- end
1498
- end
1499
- end
1500
-
1501
- class TestBlock < self
1502
- def test_with_message
1503
- if defined?(PowerAssert)
1504
- system_message = <<-MESSAGE
1505
- 1 == 2
1506
- MESSAGE
1507
- else
1508
- system_message = "<false> is not true."
1509
- end
1510
- check_fail("user message.\n#{system_message}") do
1511
- assert("user message") do
1512
- 1 == 2
1513
- end
1514
- end
1515
- end
1516
- end
1517
- end
1518
-
1519
- class TestRefute < TestCase
1520
- include AssertionCheckable
1521
-
1522
- class TestPass < self
1523
- def test_nil
1524
- check_nothing_fails do
1525
- refute(nil)
1526
- end
1527
- end
1528
-
1529
- def test_false
1530
- check_nothing_fails do
1531
- refute(false)
1532
- end
1533
- end
1534
-
1535
- def test_with_message
1536
- check_nothing_fails do
1537
- refute(nil, "successful refute")
1538
- end
1539
- end
1540
- end
1541
-
1542
- class TestFailure < self
1543
- def test_true
1544
- check_fail("<true> is neither nil or false.") do
1545
- refute(true)
1546
- end
1547
- end
1548
-
1549
- def test_with_message
1550
- check_fail("failed refute.\n" +
1551
- "<true> is neither nil or false.") do
1552
- refute(true, "failed refute")
1553
- end
1554
- end
1555
-
1556
- def test_fail_with_assertion_message
1557
- check_fail("user message.\n" +
1558
- "placeholder <:in> message") do
1559
- refute(true, build_message("user message",
1560
- "placeholder <?> message",
1561
- :in))
1562
- end
1563
- end
1564
-
1565
- def test_error_invalid_message_true
1566
- check_fail("assertion message must be String, Proc or " +
1567
- "Test::Unit::Assertions::AssertionMessage: " +
1568
- "<false>(<FalseClass>)") do
1569
- begin
1570
- refute(true, false)
1571
- rescue ArgumentError
1572
- raise AssertionFailedError, $!.message
1573
- end
1574
- end
1575
- end
1576
- end
1577
- end
1578
-
1579
- class TestAssertInDelta < TestCase
1580
- include AssertionCheckable
1581
-
1582
- def test_pass
1583
- check_nothing_fails do
1584
- assert_in_delta(1.4, 1.4, 0)
1585
- end
1586
- end
1587
-
1588
- def test_pass_without_delta
1589
- check_nothing_fails do
1590
- assert_in_delta(1.401, 1.402)
1591
- end
1592
- end
1593
-
1594
- def test_pass_with_message
1595
- check_nothing_fails do
1596
- assert_in_delta(0.5, 0.4, 0.1, "message")
1597
- end
1598
- end
1599
-
1600
- def test_pass_float_like_object
1601
- check_nothing_fails do
1602
- float_thing = Object.new
1603
- def float_thing.to_f
1604
- 0.2
1605
- end
1606
- assert_in_delta(0.1, float_thing, 0.1)
1607
- end
1608
- end
1609
-
1610
- def test_pass_string_expected
1611
- check_nothing_fails do
1612
- assert_in_delta("0.5", 0.4, 0.1)
1613
- end
1614
- end
1615
-
1616
- def test_fail_with_message
1617
- check_fail("message.\n" +
1618
- "<0.5> -/+ <0.05> expected to include\n" +
1619
- "<0.4>.\n" +
1620
- "\n" +
1621
- "Relation:\n" +
1622
- "<<0.4> < <0.5>-<0.05>[0.45] <= <0.5>+<0.05>[0.55]>") do
1623
- assert_in_delta(0.5, 0.4, 0.05, "message")
1624
- end
1625
- end
1626
-
1627
- def test_fail_because_not_float_like_object
1628
- object = Object.new
1629
- inspected_object = AssertionMessage.convert(object)
1630
- check_fail("The arguments must respond to to_f; " +
1631
- "the first float did not.\n" +
1632
- "<#{inspected_object}>.respond_to?(:to_f) expected\n" +
1633
- "(Class: <Object>)") do
1634
- assert_in_delta(object, 0.4, 0.1)
1635
- end
1636
- end
1637
-
1638
- def test_fail_because_negaitve_delta
1639
- check_fail("The delta should not be negative.\n" +
1640
- "<-0.1> expected to be\n>=\n<0.0>.") do
1641
- assert_in_delta(0.5, 0.4, -0.1, "message")
1642
- end
1643
- end
1644
-
1645
- def test_fail_without_delta
1646
- check_fail("<1.402> -/+ <0.001> expected to include\n" +
1647
- "<1.404>.\n" +
1648
- "\n" +
1649
- "Relation:\n" +
1650
- "<" +
1651
- "<1.402>-<0.001>[#{1.402 - 0.001}] <= " +
1652
- "<1.402>+<0.001>[#{1.402 + 0.001}] < " +
1653
- "<1.404>" +
1654
- ">") do
1655
- assert_in_delta(1.402, 1.404)
1656
- end
1657
- end
1658
- end
1659
-
1660
- class TestAssertNotInDelta < Test::Unit::TestCase
1661
- include AssertionCheckable
1662
-
1663
- def test_pass
1664
- check_nothing_fails do
1665
- assert_not_in_delta(1.42, 1.44, 0.01)
1666
- end
1667
- end
1668
-
1669
- def test_pass_without_delta
1670
- check_nothing_fails do
1671
- assert_not_in_delta(1.402, 1.404)
1672
- end
1673
- end
1674
-
1675
- def test_pass_with_message
1676
- check_nothing_fails do
1677
- assert_not_in_delta(0.5, 0.4, 0.09, "message")
1678
- end
1679
- end
1680
-
1681
- def test_pass_float_like_object
1682
- check_nothing_fails do
1683
- float_thing = Object.new
1684
- def float_thing.to_f
1685
- 0.2
1686
- end
1687
- assert_not_in_delta(0.1, float_thing, 0.09)
1688
- end
1689
- end
1690
-
1691
- def test_pass_string_epxected
1692
- check_nothing_fails do
1693
- assert_not_in_delta("0.5", 0.4, 0.09)
1694
- end
1695
- end
1696
-
1697
- def test_fail
1698
- check_fail("<1.4> -/+ <0.11> expected to not include\n" +
1699
- "<1.5>.\n" +
1700
- "\n" +
1701
- "Relation:\n" +
1702
- "<" +
1703
- "<1.4>-<0.11>[#{1.4 - 0.11}] <= " +
1704
- "<1.5> <= " +
1705
- "<1.4>+<0.11>[#{1.4 + 0.11}]" +
1706
- ">") do
1707
- assert_not_in_delta(1.4, 1.5, 0.11)
1708
- end
1709
- end
1710
-
1711
- def test_fail_without_delta
1712
- check_fail("<1.402> -/+ <0.001> expected to not include\n" +
1713
- "<1.4021>.\n" +
1714
- "\n" +
1715
- "Relation:\n" +
1716
- "<" +
1717
- "<1.402>-<0.001>[#{1.402 - 0.001}] <= " +
1718
- "<1.4021> <= " +
1719
- "<1.402>+<0.001>[#{1.402 + 0.001}]" +
1720
- ">") do
1721
- assert_not_in_delta(1.402, 1.4021)
1722
- end
1723
- end
1724
-
1725
- def test_fail_with_message
1726
- check_fail("message.\n" +
1727
- "<0.5> -/+ <0.11> expected to not include\n" +
1728
- "<0.4>.\n" +
1729
- "\n" +
1730
- "Relation:\n" +
1731
- "<" +
1732
- "<0.5>-<0.11>[0.39] <= " +
1733
- "<0.4> <= " +
1734
- "<0.5>+<0.11>[0.61]" +
1735
- ">") do
1736
- assert_not_in_delta(0.5, 0.4, 0.11, "message")
1737
- end
1738
- end
1739
-
1740
- def test_fail_because_not_float_like_object
1741
- object = Object.new
1742
- inspected_object = AssertionMessage.convert(object)
1743
- check_fail("The arguments must respond to to_f; " +
1744
- "the first float did not.\n" +
1745
- "<#{inspected_object}>.respond_to?(:to_f) expected\n" +
1746
- "(Class: <Object>)") do
1747
- assert_not_in_delta(object, 0.4, 0.1)
1748
- end
1749
- end
1750
-
1751
- def test_fail_because_negaitve_delta
1752
- check_fail("The delta should not be negative.\n" +
1753
- "<-0.11> expected to be\n>=\n<0.0>.") do
1754
- assert_not_in_delta(0.5, 0.4, -0.11, "message")
1755
- end
1756
- end
1757
- end
1758
-
1759
- class TestAssertInEpsilon < TestCase
1760
- include AssertionCheckable
1761
-
1762
- def test_pass
1763
- check_nothing_fails do
1764
- assert_in_epsilon(10000, 9000, 0.1)
1765
- end
1766
- end
1767
-
1768
- def test_pass_without_epsilon
1769
- check_nothing_fails do
1770
- assert_in_epsilon(10000, 9991)
1771
- end
1772
- end
1773
-
1774
- def test_pass_with_message
1775
- check_nothing_fails do
1776
- assert_in_epsilon(10000, 9000, 0.1, "message")
1777
- end
1778
- end
1779
-
1780
- def test_pass_float_like_object
1781
- check_nothing_fails do
1782
- float_thing = Object.new
1783
- def float_thing.to_f
1784
- 9000.0
1785
- end
1786
- assert_in_epsilon(10000, float_thing, 0.1)
1787
- end
1788
- end
1789
-
1790
- def test_pass_string_expected
1791
- check_nothing_fails do
1792
- assert_in_epsilon("10000", 9000, 0.1)
1793
- end
1794
- end
1795
-
1796
- def test_pass_zero_expected
1797
- check_nothing_fails do
1798
- assert_in_epsilon(0, 0.00000001)
1799
- end
1800
- end
1801
-
1802
- def test_pass_minus_expected
1803
- check_nothing_fails do
1804
- assert_in_epsilon(-1, -1)
1805
- end
1806
- end
1807
-
1808
- def test_fail_with_message
1809
- check_fail("message.\n" +
1810
- "<10000> -/+ (<10000> * <0.1>)[1000.0] " +
1811
- "expected to include\n" +
1812
- "<8999>.\n" +
1813
- "\n" +
1814
- "Relation:\n" +
1815
- "<" +
1816
- "<8999> < " +
1817
- "<10000>-(<10000>*<0.1>)[9000.0] <= " +
1818
- "<10000>+(<10000>*<0.1>)[11000.0]" +
1819
- ">") do
1820
- assert_in_epsilon(10000, 8999, 0.1, "message")
1821
- end
1822
- end
1823
-
1824
- def test_fail_because_not_float_like_object
1825
- object = Object.new
1826
- inspected_object = AssertionMessage.convert(object)
1827
- check_fail("The arguments must respond to to_f; " +
1828
- "the first float did not.\n" +
1829
- "<#{inspected_object}>.respond_to?(:to_f) expected\n" +
1830
- "(Class: <Object>)") do
1831
- assert_in_epsilon(object, 9000, 0.1)
1832
- end
1833
- end
1834
-
1835
- def test_fail_because_negaitve_epsilon
1836
- check_fail("The epsilon should not be negative.\n" +
1837
- "<-0.1> expected to be\n>=\n<0.0>.") do
1838
- assert_in_epsilon(10000, 9000, -0.1, "message")
1839
- end
1840
- end
1841
-
1842
- def test_fail_without_epsilon
1843
- check_fail("<10000> -/+ (<10000> * <0.001>)[10.0] " +
1844
- "expected to include\n" +
1845
- "<10011>.\n" +
1846
- "\n" +
1847
- "Relation:\n" +
1848
- "<" +
1849
- "<10000>-(<10000>*<0.001>)[9990.0] <= " +
1850
- "<10000>+(<10000>*<0.001>)[10010.0] < " +
1851
- "<10011>" +
1852
- ">") do
1853
- assert_in_epsilon(10000, 10011)
1854
- end
1855
- end
1856
- end
1857
-
1858
- class TestAssertNotInEpsilon < Test::Unit::TestCase
1859
- include AssertionCheckable
1860
-
1861
- def test_pass
1862
- check_nothing_fails do
1863
- assert_not_in_epsilon(10000, 8999, 0.1)
1864
- end
1865
- end
1866
-
1867
- def test_pass_without_epsilon
1868
- check_nothing_fails do
1869
- assert_not_in_epsilon(10000, 9989)
1870
- end
1871
- end
1872
-
1873
- def test_pass_with_message
1874
- check_nothing_fails do
1875
- assert_not_in_epsilon(10000, 8999, 0.1, "message")
1876
- end
1877
- end
1878
-
1879
- def test_pass_float_like_object
1880
- check_nothing_fails do
1881
- float_thing = Object.new
1882
- def float_thing.to_f
1883
- 8999.0
1884
- end
1885
- assert_not_in_epsilon(10000, float_thing, 0.1)
1886
- end
1887
- end
1888
-
1889
- def test_pass_string_epxected
1890
- check_nothing_fails do
1891
- assert_not_in_epsilon("10000", 8999, 0.1)
1892
- end
1893
- end
1894
-
1895
- def test_fail
1896
- check_fail("<10000> -/+ (<10000> * <0.1>)[1000.0] " +
1897
- "expected to not include\n" +
1898
- "<9000>.\n" +
1899
- "\n" +
1900
- "Relation:\n" +
1901
- "<" +
1902
- "<10000>-(<10000>*<0.1>)[9000.0] <= " +
1903
- "<9000> <= " +
1904
- "<10000>+(<10000>*<0.1>)[11000.0]" +
1905
- ">") do
1906
- assert_not_in_epsilon(10000, 9000, 0.1)
1907
- end
1908
- end
1909
-
1910
- def test_fail_without_epsilon
1911
- check_fail("<10000> -/+ (<10000> * <0.001>)[10.0] " +
1912
- "expected to not include\n" +
1913
- "<9990>.\n" +
1914
- "\n" +
1915
- "Relation:\n" +
1916
- "<" +
1917
- "<10000>-(<10000>*<0.001>)[9990.0] <= " +
1918
- "<9990> <= " +
1919
- "<10000>+(<10000>*<0.001>)[10010.0]" +
1920
- ">") do
1921
- assert_not_in_epsilon(10000, 9990)
1922
- end
1923
- end
1924
-
1925
- def test_fail_with_message
1926
- check_fail("message.\n" +
1927
- "<10000> -/+ (<10000> * <0.1>)[1000.0] " +
1928
- "expected to not include\n" +
1929
- "<9000>.\n" +
1930
- "\n" +
1931
- "Relation:\n" +
1932
- "<" +
1933
- "<10000>-(<10000>*<0.1>)[9000.0] <= " +
1934
- "<9000> <= " +
1935
- "<10000>+(<10000>*<0.1>)[11000.0]" +
1936
- ">") do
1937
- assert_not_in_epsilon(10000, 9000, 0.1, "message")
1938
- end
1939
- end
1940
-
1941
- def test_fail_because_not_float_like_object
1942
- object = Object.new
1943
- inspected_object = AssertionMessage.convert(object)
1944
- check_fail("The arguments must respond to to_f; " +
1945
- "the first float did not.\n" +
1946
- "<#{inspected_object}>.respond_to?(:to_f) expected\n" +
1947
- "(Class: <Object>)") do
1948
- assert_not_in_epsilon(object, 9000, 0.1)
1949
- end
1950
- end
1951
-
1952
- def test_fail_because_negaitve_epsilon
1953
- check_fail("The epsilon should not be negative.\n" +
1954
- "<-0.1> expected to be\n>=\n<0.0>.") do
1955
- assert_not_in_epsilon(10000, 9000, -0.1, "message")
1956
- end
1957
- end
1958
- end
1959
-
1960
- class TestAssertInclude < Test::Unit::TestCase
1961
- include AssertionCheckable
1962
-
1963
- def test_pass
1964
- check_nothing_fails do
1965
- assert_include([1, 2, 3], 1)
1966
- end
1967
- end
1968
-
1969
- def test_pass_with_message
1970
- check_nothing_fails do
1971
- assert_include([1, 2, 3], 1, "message")
1972
- end
1973
- end
1974
-
1975
- def test_fail
1976
- check_fail("<[1, 2, 3]> expected to include\n" +
1977
- "<4>.") do
1978
- assert_include([1, 2, 3], 4)
1979
- end
1980
- end
1981
-
1982
- def test_fail_with_message
1983
- check_fail("message.\n" +
1984
- "<[1, 2, 3]> expected to include\n" +
1985
- "<4>.") do
1986
- assert_include([1, 2, 3], 4, "message")
1987
- end
1988
- end
1989
-
1990
- def test_fail_because_not_collection_like_object
1991
- object = Object.new
1992
- inspected_object = AssertionMessage.convert(object)
1993
- check_fail("The collection must respond to :include?.\n" +
1994
- "<#{inspected_object}>.respond_to?(:include?) expected\n" +
1995
- "(Class: <Object>)") do
1996
- assert_include(object, 1)
1997
- end
1998
- end
1999
- end
2000
-
2001
- class TestAssertNotInclude < Test::Unit::TestCase
2002
- include AssertionCheckable
2003
-
2004
- def test_pass
2005
- check_nothing_fails do
2006
- assert_not_include([1, 2, 3], 5)
2007
- end
2008
- end
2009
-
2010
- def test_pass_with_message
2011
- check_nothing_fails do
2012
- assert_not_include([1, 2, 3], 5, "message")
2013
- end
2014
- end
2015
-
2016
- def test_fail
2017
- check_fail("<[1, 2, 3]> expected to not include\n" +
2018
- "<2>.") do
2019
- assert_not_include([1, 2, 3], 2)
2020
- end
2021
- end
2022
-
2023
- def test_fail_with_message
2024
- check_fail("message.\n" +
2025
- "<[1, 2, 3]> expected to not include\n" +
2026
- "<2>.") do
2027
- assert_not_include([1, 2, 3], 2, "message")
2028
- end
2029
- end
2030
-
2031
- def test_fail_because_not_collection_like_object
2032
- object = Object.new
2033
- inspected_object = AssertionMessage.convert(object)
2034
- check_fail("The collection must respond to :include?.\n" +
2035
- "<#{inspected_object}>.respond_to?(:include?) expected\n" +
2036
- "(Class: <Object>)") do
2037
- assert_not_include(object, 1)
2038
- end
2039
- end
2040
- end
2041
-
2042
- class TestAssertEmpty < Test::Unit::TestCase
2043
- include AssertionCheckable
2044
-
2045
- def test_pass
2046
- check_nothing_fails do
2047
- assert_empty([])
2048
- end
2049
- end
2050
-
2051
- def test_pass_with_message
2052
- check_nothing_fails do
2053
- assert_empty([], "message")
2054
- end
2055
- end
2056
-
2057
- def test_fail
2058
- check_fail("<[1]> expected to be empty.") do
2059
- assert_empty([1])
2060
- end
2061
- end
2062
-
2063
- def test_fail_with_message
2064
- check_fail("message.\n" +
2065
- "<[1]> expected to be empty.") do
2066
- assert_empty([1], "message")
2067
- end
2068
- end
2069
-
2070
- def test_fail_because_no_empty_method
2071
- object = Object.new
2072
- inspected_object = AssertionMessage.convert(object)
2073
- check_fail("The object must respond to :empty?.\n" +
2074
- "<#{inspected_object}>.respond_to?(:empty?) expected\n" +
2075
- "(Class: <Object>)") do
2076
- assert_empty(object)
2077
- end
2078
- end
2079
- end
2080
-
2081
- class TestAssertNotEmpty < Test::Unit::TestCase
2082
- include AssertionCheckable
2083
-
2084
- def test_pass
2085
- check_nothing_fails do
2086
- assert_not_empty([1])
2087
- end
2088
- end
2089
-
2090
- def test_pass_with_message
2091
- check_nothing_fails do
2092
- assert_not_empty([1], "message")
2093
- end
2094
- end
2095
-
2096
- def test_fail
2097
- check_fail("<[]> expected to not be empty.") do
2098
- assert_not_empty([])
2099
- end
2100
- end
2101
-
2102
- def test_fail_with_message
2103
- check_fail("message.\n" +
2104
- "<[]> expected to not be empty.") do
2105
- assert_not_empty([], "message")
2106
- end
2107
- end
2108
-
2109
- def test_fail_because_no_empty_method
2110
- object = Object.new
2111
- inspected_object = AssertionMessage.convert(object)
2112
- check_fail("The object must respond to :empty?.\n" +
2113
- "<#{inspected_object}>.respond_to?(:empty?) expected\n" +
2114
- "(Class: <Object>)") do
2115
- assert_not_empty(object)
2116
- end
2117
- end
2118
- end
2119
-
2120
- class TestAssertNotSend < Test::Unit::TestCase
2121
- include AssertionCheckable
2122
-
2123
- def test_pass
2124
- check_nothing_fails do
2125
- assert_not_send([[1, 2], :member?, 4], "message")
2126
- end
2127
- end
2128
-
2129
- def test_fail
2130
- expected_message = <<-EOM
2131
- message.
2132
- <[1, 2]> expected to respond to
2133
- <member?(*[2])> with not a true value but was
2134
- <true>.
2135
- EOM
2136
- check_fail(expected_message.chomp) do
2137
- assert_not_send([[1, 2], :member?, 2], "message")
2138
- end
2139
- end
2140
- end
2141
-
2142
- class TestTemplate < Test::Unit::TestCase
2143
- def test_incompatible_encoding_by_diff
2144
- need_encoding
2145
- assert_raise(AssertionFailedError) do
2146
- assert_equal("UTF-8の日本語\n" * 3,
2147
- ("Shift_JISの日本語\n" * 3).force_encoding("ASCII-8BIT"))
2148
- end
2149
- end
2150
-
2151
- private
2152
- def need_encoding
2153
- omit("need Encoding") unless Object.const_defined?(:Encoding)
2154
- end
2155
- end
2156
- end
2157
- end