test-unit 3.4.4 → 3.4.8

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