File: test-assertions.rb

package info (click to toggle)
ruby-test-unit 3.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 928 kB
  • ctags: 1,759
  • sloc: ruby: 12,818; makefile: 6
file content (2132 lines) | stat: -rw-r--r-- 61,455 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
# -*- coding: utf-8 -*-
#
# Author:: Nathaniel Talbott.
# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved.
#             Copyright (c) 2009-2014 Kouhei Sutou. All rights reserved.
# License:: Ruby license.

require 'test/unit'
require "testunit-test-util"

module Test
  module Unit
    module AssertionCheckable
      include TestUnitTestUtil

      private
      def check(value, message="")
        add_assertion
        raise AssertionFailedError.new(message) unless value
      end

      def check_assertions(expect_fail, options={})
        expected_message = options[:expected_message]
        actual_message_normalizer = options[:actual_message_normalizer]
        return_value_expected = options[:return_value_expected]
        @actual_assertion_count = 0
        failed = true
        actual_message = nil
        @catch_assertions = true
        return_value = nil
        begin
          return_value = yield
          failed = false
        rescue AssertionFailedError => error
          actual_message = error.message
        end
        @catch_assertions = false

        if expect_fail
          message = "Should have failed, but didn't"
        else
          message = "Should not have failed, but did with message\n" +
            "<#{actual_message}>"
        end
        check(expect_fail == failed, message)

        message = "Should have made one assertion but made\n" +
          "<#{@actual_assertion_count}>"
        check(1 == @actual_assertion_count, message)

        if expect_fail
          if actual_message_normalizer
            actual_message = actual_message_normalizer.call(actual_message)
          end
          case expected_message
          when String
            check(expected_message == actual_message,
                  "Should have the correct message.\n" +
                  "<#{expected_message.inspect}> expected but was\n" +
                  "<#{actual_message.inspect}>")
          when Regexp
            check(expected_message =~ actual_message,
                  "The message should match correctly.\n" +
                  "</#{expected_message.source}/> expected to match\n" +
                  "<#{actual_message.inspect}>")
          else
            check(false,
                  "Incorrect expected message type in assert_nothing_failed")
          end
        else
          if return_value_expected
            check(!return_value.nil?, "Should return a value")
          else
            check(return_value.nil?,
                  "Should not return a value but returned <#{return_value}>")
          end
        end

        return_value
      end

      def check_nothing_fails(return_value_expected=false, &proc)
        check_assertions(false,
                         {:expected_message => nil,
                          :return_value_expected => return_value_expected},
                         &proc)
      end

      def check_fail(expected_message, options={}, &proc)
        check_assertions(true,
                         options.merge(:expected_message => expected_message),
                         &proc)
      end

      def check_fail_exception(expected_message, options={}, &proc)
        normalizer = lambda do |actual_message|
          actual_message.gsub(/(^[^:\n]+:\d+:.+\n?)+\z/, "")
        end
        check_assertions(true,
                         options.merge(:expected_message => expected_message,
                                       :actual_message_normalizer => normalizer),
                         &proc)
      end

      def inspect_tag(tag)
        tag.inspect
      end

      def add_failure(message, location=caller, options=nil)
        unless @catch_assertions
          super
        end
      end

      def add_assertion
        if @catch_assertions
          @actual_assertion_count += 1
        else
          super
        end
      end
    end

    class TestAssertions < TestCase
      include AssertionCheckable

      def test_assert_block
        check_nothing_fails {
          assert_block {true}
        }
        check_nothing_fails {
          assert_block("successful assert_block") {true}
        }
        check_nothing_fails {
          assert_block("successful assert_block") {true}
        }
        check_fail("assert_block failed.") {
          assert_block {false}
        }
        check_fail("failed assert_block") {
          assert_block("failed assert_block") {false}
        }
      end

      class TestAssertEqual < self
        class TestSuccess < self
          def test_without_message
            check_nothing_fails {
              assert_equal("string1", "string1")
            }
          end

          def test_with_message
            check_nothing_fails {
              assert_equal("string1", "string1", "successful assert_equal")
            }
          end
        end

        class TestFailure < self
          def test_without_message
            message = <<-EOM.chomp
<"string1"> expected but was
<"string2">.

diff:
- string1
?       ^
+ string2
?       ^
EOM
            check_fail(message) {
              assert_equal("string1", "string2")
            }
          end

          def test_with_message
            message = <<-EOM.chomp
failed assert_equal.
<"string1"> expected but was
<"string2">.

diff:
- string1
?       ^
+ string2
?       ^
EOM
           check_fail(message) {
             assert_equal("string1", "string2", "failed assert_equal")
            }
          end
        end

        class TestSystemMessage < self
          def test_different_type
            message = <<-EOM.chomp
<"111111"> expected but was
<111111>.

diff:
- "111111"
? -      -
+ 111111
EOM
            check_fail(message) do
              assert_equal("111111", 111111)
            end
          end

          def test_long_line
            expected = ["0123456789",
                        "1123456789",
                        "2123456789",
                        "3123456789",
                        "4123456789",
                        "5123456789",
                        "6123456789",
                        "7123456789",
                        "8123456789"].join
            actual =   ["0000000000",
                        "1123456789",
                        "2123456789",
                        "3123456789",
                        "4123456789",
                        "5123456789",
                        "6123456789",
                        "7123456789",
                        "8123456789"].join
            message = <<-EOM.chomp
<"#{expected}"> expected but was
<"#{actual}">.

diff:
- #{expected}
?  ^^^^^^^^^
+ #{actual}
?  ^^^^^^^^^

folded diff:
- 012345678911234567892123456789312345678941234567895123456789612345678971234567
?  ^^^^^^^^^
+ 000000000011234567892123456789312345678941234567895123456789612345678971234567
?  ^^^^^^^^^
  898123456789
EOM
            check_fail(message) do
              assert_equal(expected, actual)
            end
          end

          def test_too_small_difference
            message = <<-EOM.chomp
<1> expected but was
<2>.
EOM
            check_fail(message) do
              assert_equal(1, 2)
            end
          end

          def test_same_inspected_objects
            now = Time.now
            now_without_usec = Time.at(now.to_i)
            message = <<-EOM.chomp
<#{now.inspect}> expected but was
<#{now.inspect}>.
EOM
            check_fail(message) do
              assert_equal(now, now_without_usec)
            end
          end

          def test_multi_lines_result
            message = <<-EOM.chomp
<#{"a\nb".inspect}> expected but was
<#{"x".inspect}>.

diff:
+ x
- a
- b
EOM
            check_fail(message) do
              assert_equal("a\nb", "x")
            end
          end

          def test_large_string
            message = <<-EOM.chomp
<#{("a\n" + "x" * 997).inspect}> expected but was
<#{"x".inspect}>.

diff:
+ x
- a
- #{"x" * 997}

folded diff:
+ x
- a
#{(["- " + ("x" * 78)] * 12).join("\n")}
- #{"x" * 61}
EOM
            check_fail(message) do
              assert_equal("a\n" + "x" * 997, "x")
            end

            message = <<-EOM.chomp
<#{("a\n" + "x" * 998).inspect}> expected but was
<#{"x".inspect}>.
EOM
            check_fail(message) do
              assert_equal("a\n" + "x" * 998, "x")
            end
          end

          def test_max_diff_target_string_size
            key = "TEST_UNIT_MAX_DIFF_TARGET_STRING_SIZE"
            before_value = ENV[key]
            ENV[key] = "100"
            begin
              message = <<-EOM.chomp
<#{("a\n" + "x" * 97).inspect}> expected but was
<#{"x".inspect}>.

diff:
+ x
- a
- #{"x" * 97}

folded diff:
+ x
- a
#{(["- " + ("x" * 78)]).join("\n")}
- #{"x" * 19}
EOM
              check_fail(message) do
                assert_equal("a\n" + "x" * 97, "x")
              end

              message = <<-EOM.chomp
<#{("a\n" + "x" * 98).inspect}> expected but was
<#{"x".inspect}>.
EOM
              check_fail(message) do
                assert_equal("a\n" + "x" * 98, "x")
              end
            ensure
              ENV[key] = before_value
            end
          end

          def test_different_encoding
            utf8_string = "こんにちは"
            unless utf8_string.respond_to?(:force_encoding)
              omit("encoding test is for Ruby >= 1.9")
            end
            ascii_8bit_string = utf8_string.dup.force_encoding("ascii-8bit")
            message = <<-EOM.chomp
<#{utf8_string.inspect}>("UTF-8") expected but was
<#{ascii_8bit_string.inspect}>("ASCII-8BIT").
EOM
            check_fail(message) do
              assert_equal(utf8_string, ascii_8bit_string)
            end
          end

          def test_different_hash
            designers = {
              "Ruby" => "Matz",
              "Lisp" => "John McCarthy",
            }
            categories = {
              "LL" => ["Ruby", "Python"],
              "Heavy" => ["C", "C++"],
            }
            message = <<-EOM.chomp
<{"Lisp"=>"John McCarthy", "Ruby"=>"Matz"}> expected but was
<{"Heavy"=>["C", "C++"], "LL"=>["Ruby", "Python"]}>.
EOM
            check_fail(message) do
              assert_equal(designers, categories)
            end
          end

          def test_recursive_hash
            alice = {"name" => "Alice"}
            bob = {"name" => "Bob"}
            alice["followers"] = [bob]
            bob["followers"] = [alice]
            message = <<-EOM.chomp
<{"followers"=>[{"followers"=>[{...}], "name"=>"Bob"}], "name"=>"Alice"}> expected but was
<{"followers"=>[{"followers"=>[{...}], "name"=>"Alice"}], "name"=>"Bob"}>.

diff:
- {"followers"=>[{"followers"=>[{...}], "name"=>"Bob"}], "name"=>"Alice"}
?                                       -----------------
+ {"followers"=>[{"followers"=>[{...}], "name"=>"Alice"}], "name"=>"Bob"}
?                                                       +++++++++++++++++
EOM
            check_fail(message) do
              assert_equal(alice, bob)
            end
          end

          def test_numeric
            numeric_family_class = Class.new(Numeric) do
              def inspect
                "inspect is called"
              end

              def to_s
                "to_s is called"
              end
            end
            numeric = numeric_family_class.new

            message = <<-MESSAGE.chomp
<to_s is called> expected but was
<"must be failed">.
            MESSAGE
            check_fail(message) do
              assert_equal(numeric, "must be failed")
            end
          end
        end
      end

      def test_assert_raise_success
        return_value = nil
        check_nothing_fails(true) do
          return_value = assert_raise(RuntimeError) do
            raise "Error"
          end
        end
        check(return_value.kind_of?(Exception),
              "Should have returned the exception " +
              "from a successful assert_raise")
        check(return_value.message == "Error",
              "Should have returned the correct exception " +
              "from a successful assert_raise")

        check_nothing_fails(true) do
          assert_raise(ArgumentError, "successful assert_raise") do
            raise ArgumentError.new("Error")
          end
        end

        check_nothing_fails(true) do
          assert_raise(RuntimeError) do
            raise "Error"
          end
        end

        check_nothing_fails(true) do
          assert_raise(RuntimeError, "successful assert_raise") do
            raise "Error"
          end
        end

        check_nothing_fails(true) do
          assert_raise do
            raise Exception, "Any exception"
          end
        end
      end

      def test_assert_raise_fail
        check_fail("<RuntimeError> exception expected but none was thrown.") do
          assert_raise(RuntimeError) do
            1 + 1
          end
        end

        message = <<-EOM.chomp
failed assert_raise.
<ArgumentError> exception expected but was
<RuntimeError(<Error>)>.
EOM
        check_fail_exception(message) do
          assert_raise(ArgumentError, "failed assert_raise") do
            raise "Error"
          end
        end

        message = <<-EOM
Should expect a class of exception, Object.
<false> is not true.
EOM
        check_fail(message.chomp) do
          assert_nothing_raised(Object) do
            1 + 1
          end
        end
      end

      def test_assert_raise_module
        exceptions = [ArgumentError, TypeError]
        modules = [Math, Comparable]
        rescues = exceptions + modules

        exceptions.each do |exc|
          return_value = nil
          check_nothing_fails(true) do
            return_value = assert_raise(*rescues) do
              raise exc, "Error"
            end
          end
          check(return_value.instance_of?(exc),
                "Should have returned #{exc} but was #{return_value.class}")
          check(return_value.message == "Error",
                "Should have returned the correct exception " +
                "from a successful assert_raise")
        end

        modules.each do |mod|
          return_value = nil
          check_nothing_fails(true) do
            return_value = assert_raise(*rescues) do
              raise Exception.new("Error").extend(mod)
            end
          end
          check(mod === return_value,
                "Should have returned #{mod}")
          check(return_value.message == "Error",
                "Should have returned the correct exception " +
                "from a successful assert_raise")
        end

        check_fail("<[ArgumentError, TypeError, Math, Comparable]> exception " +
                    "expected but none was thrown.") do
          assert_raise(*rescues) do
            1 + 1
          end
        end

        message = <<-EOM.chomp
failed assert_raise.
<[ArgumentError, TypeError]> exception expected but was
<RuntimeError(<Error>)>.
EOM
        check_fail_exception(message) do
          assert_raise(ArgumentError, TypeError, "failed assert_raise") do
            raise "Error"
          end
        end
      end

      def test_assert_raise_instance
        return_value = nil
        check_nothing_fails(true) do
          return_value = assert_raise(RuntimeError.new("Error")) do
            raise "Error"
          end
        end
        check(return_value.kind_of?(Exception),
              "Should have returned the exception " +
              "from a successful assert_raise")
        check(return_value.message == "Error",
              "Should have returned the correct exception " +
              "from a successful assert_raise")

        message = <<-EOM.chomp
<RuntimeError(<XXX>)> exception expected but was
<RuntimeError(<Error>)>.

diff:
- RuntimeError(<XXX>)
?               ^^^
+ RuntimeError(<Error>)
?               ^^^^^
EOM
        check_fail_exception(message) do
          return_value = assert_raise(RuntimeError.new("XXX")) do
            raise "Error"
          end
        end

        different_error_class = Class.new(StandardError)
        message = <<-EOM.chomp
<#{different_error_class.inspect}(<Error>)> exception expected but was
<RuntimeError(<Error>)>.
EOM
        check_fail_exception(message) do
          assert_raise(different_error_class.new("Error")) do
            raise "Error"
          end
        end

        different_error = different_error_class.new("Error")
        def different_error.inspect
          "DifferentError: \"Error\""
        end
        message = <<-EOM.chomp
<DifferentError: "Error"> exception expected but was
<RuntimeError(<Error>)>.
EOM
        check_fail_exception(message) do
          assert_raise(different_error) do
            raise "Error"
          end
        end

        check_nothing_fails(true) do
          assert_raise(different_error_class.new("Error"),
                       RuntimeError.new("Error"),
                       RuntimeError.new("XXX")) do
            raise "Error"
          end
        end
      end

      def test_assert_instance_of
        check_nothing_fails {
          assert_instance_of(String, "string")
        }
        check_nothing_fails {
          assert_instance_of(String, "string", "successful assert_instance_of")
        }
        check_nothing_fails {
          assert_instance_of(String, "string", "successful assert_instance_of")
        }
        check_fail(%Q{<"string"> expected to be instance_of?\n<Hash> but was\n<String>.}) {
          assert_instance_of(Hash, "string")
        }
        check_fail(%Q{failed assert_instance_of.\n<"string"> expected to be instance_of?\n<Hash> but was\n<String>.}) {
          assert_instance_of(Hash, "string", "failed assert_instance_of")
        }

        check_nothing_fails do
          assert_instance_of([Fixnum, NilClass], 100)
        end
        check_fail(%Q{<"string"> expected to be instance_of?\n[<Fixnum>, <NilClass>] but was\n<String>.}) do
          assert_instance_of([Fixnum, NilClass], "string")
        end
        check_fail(%Q{<100> expected to be instance_of?\n[<Numeric>, <NilClass>] but was\n<Fixnum>.}) do
          assert_instance_of([Numeric, NilClass], 100)
        end
      end

      def test_assert_not_instance_of
        check_nothing_fails {
          assert_not_instance_of(NilClass, "string")
        }
        check_nothing_fails {
          assert_not_instance_of(NilClass, "string", "successful assert_instance_of")
        }
        check_fail(%Q{<"string"> expected to not be instance_of?\n<String> but was.}) {
          assert_not_instance_of(String, "string")
        }
        check_fail(%Q{failed assert.\n<"string"> expected to not be instance_of?\n<String> but was.}) {
          assert_not_instance_of(String, "string", "failed assert")
        }

        check_nothing_fails do
          assert_not_instance_of([Numeric, NilClass], 100)
        end
        check_fail(%Q{<100> expected to not be instance_of?\n[<Fixnum>, <NilClass>] but was.}) do
          assert_not_instance_of([Fixnum, NilClass], 100)
        end
        check_fail(%Q{<"str"> expected to not be instance_of?\n[<Numeric>, <String>] but was.}) do
          assert_not_instance_of([Numeric, String], 'str')
        end
      end

      def test_assert_nil
        check_nothing_fails {
          assert_nil(nil)
        }
        check_nothing_fails {
          assert_nil(nil, "successful assert_nil")
        }
        check_nothing_fails {
          assert_nil(nil, "successful assert_nil")
        }
        check_fail(%Q{<"string"> expected to be nil.}) {
          assert_nil("string")
        }
        check_fail(%Q{failed assert_nil.\n<"string"> expected to be nil.}) {
          assert_nil("string", "failed assert_nil")
        }
      end

      def test_assert_not_nil
        check_nothing_fails{assert_not_nil(false)}
        check_nothing_fails{assert_not_nil(false, "message")}
        check_fail("<nil> expected to not be nil."){assert_not_nil(nil)}
        check_fail("message.\n<nil> expected to not be nil.") {assert_not_nil(nil, "message")}
      end

      def test_assert_kind_of
        check_nothing_fails {
          assert_kind_of(Module, Array)
        }
        check_nothing_fails {
          assert_kind_of(Object, "string", "successful assert_kind_of")
        }
        check_nothing_fails {
          assert_kind_of(String, "string", "successful assert_kind_of")
        }
        check_nothing_fails {
          assert_kind_of(Comparable, 1)
        }
        check_fail(%Q{<"string"> expected to be kind_of?\n<Class> but was\n<String>.}) {
          assert_kind_of(Class, "string")
        }
        check_fail(%Q{failed assert_kind_of.\n<"string"> expected to be kind_of?\n<Class> but was\n<String>.}) {
          assert_kind_of(Class, "string", "failed assert_kind_of")
        }

        check_nothing_fails do
          assert_kind_of([Fixnum, NilClass], 100)
        end
        check_fail(%Q{<"string"> expected to be kind_of?\n[<Fixnum>, <NilClass>] but was\n<String>.}) do
          assert_kind_of([Fixnum, NilClass], "string")
        end
      end

      def test_assert_not_kind_of
        check_nothing_fails {
          assert_not_kind_of(Class, 42)
        }
        check_nothing_fails {
          assert_not_kind_of(Symbol, "string", "successful assert_not_kind_of")
        }
        check_nothing_fails {
          assert_not_kind_of(Integer, 1.1)
        }
        check_fail(%Q{<1> expected to not be kind_of?\n<Integer> but was.}) {
          assert_not_kind_of(Integer, 1)
        }
        check_fail(%Q{failed assert_not_kind_of.\n<"string"> expected to not be kind_of?\n<String> but was.}) {
          assert_not_kind_of(String, "string", "failed assert_not_kind_of")
        }

        check_nothing_fails do
          assert_not_kind_of([String, NilClass], 100)
        end
        check_fail(%Q{<100> expected to not be kind_of?\n[<Fixnum>, <NilClass>] but was.}) do
          assert_not_kind_of([Fixnum, NilClass], 100)
        end
      end

      def test_assert_match
        check_nothing_fails {
          assert_match(/strin./, "string")
        }
        check_nothing_fails {
          assert_match("strin", "string")
        }
        check_nothing_fails {
          assert_match(/strin./, "string", "successful assert_match")
        }
        check_nothing_fails {
          assert_match(/strin./, "string", "successful assert_match")
        }
        check_fail(%Q{<"string"> expected to be =~\n</slin./>.}) {
          assert_match(/slin./, "string")
        }
        check_fail(%Q{<"string"> expected to be =~\n</strin\\./>.}) {
          assert_match("strin.", "string")
        }
        check_fail(%Q{failed assert_match.\n<"string"> expected to be =~\n</slin./>.}) {
          assert_match(/slin./, "string", "failed assert_match")
        }
      end

      def test_assert_same
        thing = "thing"
        check_nothing_fails {
          assert_same(thing, thing)
        }
        check_nothing_fails {
          assert_same(thing, thing, "successful assert_same")
        }
        check_nothing_fails {
          assert_same(thing, thing, "successful assert_same")
        }
        thing2 = "thing"
        check_fail(%Q{<"thing">\nwith id <#{thing.__id__}> expected to be equal? to\n<"thing">\nwith id <#{thing2.__id__}>.}) {
          assert_same(thing, thing2)
        }
        check_fail(%Q{failed assert_same.\n<"thing">\nwith id <#{thing.__id__}> expected to be equal? to\n<"thing">\nwith id <#{thing2.__id__}>.}) {
          assert_same(thing, thing2, "failed assert_same")
        }
      end

      def test_assert_nothing_raised
        check_nothing_fails {
          assert_nothing_raised {
            1 + 1
          }
        }
        check_nothing_fails {
          assert_nothing_raised("successful assert_nothing_raised") {
            1 + 1
          }
        }
        check_nothing_fails {
          assert_nothing_raised("successful assert_nothing_raised") {
            1 + 1
          }
        }
        check_nothing_fails {
          begin
            assert_nothing_raised(RuntimeError, StandardError, Comparable, "successful assert_nothing_raised") {
              raise ZeroDivisionError.new("ArgumentError")
            }
          rescue ZeroDivisionError
          end
        }
        check_fail("Should expect a class of exception, Object.\n<false> is not true.") {
          assert_nothing_raised(Object) {
            1 + 1
          }
        }
        expected_message = <<-EOM.chomp
Exception raised:
RuntimeError(<Error>)
EOM
        check_fail_exception(expected_message) {
          assert_nothing_raised {
            raise "Error"
          }
        }
        expected_message = <<-EOM.chomp
failed assert_nothing_raised.
Exception raised:
RuntimeError(<Error>)
EOM
        check_fail_exception(expected_message) {
          assert_nothing_raised("failed assert_nothing_raised") {
            raise "Error"
          }
        }
        expected_message = <<-EOM.chomp
Exception raised:
RuntimeError(<Error>)
EOM
        check_fail_exception(expected_message) {
          assert_nothing_raised(StandardError, RuntimeError) {
            raise "Error"
          }
        }
        check_fail("Failure.") do
          assert_nothing_raised do
            flunk("Failure")
          end
        end
      end

      def test_flunk
        check_fail("Flunked.") {
          flunk
        }
        check_fail("flunk message.") {
          flunk("flunk message")
        }
      end

      def test_assert_not_same
        thing = "thing"
        thing2 = "thing"
        check_nothing_fails {
          assert_not_same(thing, thing2)
        }
        check_nothing_fails {
          assert_not_same(thing, thing2, "message")
        }
        check_fail(%Q{<"thing">\nwith id <#{thing.__id__}> expected to not be equal? to\n<"thing">\nwith id <#{thing.__id__}>.}) {
          assert_not_same(thing, thing)
        }
        check_fail(%Q{message.\n<"thing">\nwith id <#{thing.__id__}> expected to not be equal? to\n<"thing">\nwith id <#{thing.__id__}>.}) {
          assert_not_same(thing, thing, "message")
        }
      end

      def test_assert_not_equal
        check_nothing_fails {
          assert_not_equal("string1", "string2")
        }
        check_nothing_fails {
          assert_not_equal("string1", "string2", "message")
        }
        check_fail(%Q{<"string"> expected to be != to\n<"string">.}) {
          assert_not_equal("string", "string")
        }
        check_fail(%Q{message.\n<"string"> expected to be != to\n<"string">.}) {
          assert_not_equal("string", "string", "message")
        }
      end

      def test_assert_not_match_pass
        check_nothing_fails do
          assert_not_match(/sling/, "string")
        end
      end

      def test_assert_not_match_pass_with_message
        check_nothing_fails do
          assert_not_match(/sling/, "string", "message")
        end
      end

      def test_assert_not_match_fail_not_regexp
        check_fail("<REGEXP> in assert_not_match(<REGEXP>, ...) " +
                    "should be a Regexp.\n" +
                    "<\"asdf\"> expected to be instance_of?\n" +
                    "<Regexp> but was\n" +
                    "<String>.") do
          assert_not_match("asdf", "asdf")
        end
      end

      def test_assert_not_match_fail_match
        check_fail("</string/> expected to not match\n" +
                    "<\"string\">.") do
          assert_not_match(/string/, "string")
        end
      end

      def test_assert_not_match_fail_match_with_message
        check_fail("message.\n" +
                    "</string/> expected to not match\n" +
                    "<\"string\">.") do
          assert_not_match(/string/, "string", "message")
        end
      end

      def test_assert_no_match
        check_nothing_fails{assert_no_match(/sling/, "string")}
        check_nothing_fails{assert_no_match(/sling/, "string", "message")}
        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
          assert_no_match("asdf", "asdf")
        end
        check_fail(%Q{</string/> expected to not match\n<"string">.}) do
          assert_no_match(/string/, "string")
        end
        check_fail(%Q{message.\n</string/> expected to not match\n<"string">.}) do
          assert_no_match(/string/, "string", "message")
        end
      end

      def test_assert_throw
        check_nothing_fails do
          assert_throw(:thing, "message") do
            throw :thing
          end
        end

        tag = :thing2
        check_fail("message.\n" +
                    "<:thing> expected to be thrown but\n" +
                    "<#{inspect_tag(tag)}> was thrown.") do
          assert_throw(:thing, "message") do
            throw :thing2
          end
        end
        check_fail("message.\n" +
                    "<:thing> should have been thrown.") do
          assert_throw(:thing, "message") do
            1 + 1
          end
        end
      end

      def test_assert_nothing_thrown
        check_nothing_fails do
          assert_nothing_thrown("message") do
            1 + 1
          end
        end

        tag = :thing
        inspected = inspect_tag(tag)
        check_fail("message.\n" +
                    "<#{inspected}> was thrown when nothing was expected.") do
          assert_nothing_thrown("message") do
            throw tag
          end
        end
      end

      def test_assert_operator
        check_nothing_fails {
          assert_operator("thing", :==, "thing", "message")
        }
        check_fail(%Q{<0.15>\ngiven as the operator for #assert_operator must be a Symbol or #respond_to?(:to_str).}) do
          assert_operator("thing", 0.15, "thing")
        end
        check_fail(%Q{message.\n<"thing1"> expected to be\n==\n<"thing2">.}) {
          assert_operator("thing1", :==, "thing2", "message")
        }
      end

      def test_assert_not_operator
        check_nothing_fails {
          assert_not_operator("thing", :==, "Thing", "message")
        }
        check_fail(%Q{<42>\ngiven as the operator for #assert_not_operator must be a Symbol or #respond_to?(:to_str).}) do
          assert_not_operator("thing", 42, "message")
        end
        check_fail(%Q{message.\n<0> expected to not be\n==\n<0.0>.}) {
          assert_not_operator(0, :==, 0.0, "message")
        }
      end

      def test_assert_respond_to
        check_nothing_fails {
          assert_respond_to("thing", :to_s, "message")
        }
        check_nothing_fails {
          assert_respond_to("thing", "to_s", "message")
        }
        check_fail("<0.15>.kind_of?(Symbol) or\n" +
                    "<0.15>.respond_to?(:to_str) expected") {
          assert_respond_to("thing", 0.15)
        }
        check_fail("message.\n" +
                    "<:symbol>.respond_to?(:nonexistence) expected\n" +
                    "(Class: <Symbol>)") {
          assert_respond_to(:symbol, :nonexistence, "message")
        }
      end

      def test_assert_not_respond_to_pass_symbol
        check_nothing_fails do
          assert_not_respond_to("thing", :nonexistent, "message")
        end
      end

      def test_assert_not_respond_to_pass_string
        check_nothing_fails do
          assert_not_respond_to("thing", :nonexistent, "message")
        end
      end

      def test_assert_not_respond_to_fail_number
        check_fail("<0.15>.kind_of?(Symbol) or\n" +
                    "<0.15>.respond_to?(:to_str) expected") do
          assert_respond_to("thing", 0.15)
        end
      end

      def tset_assert_not_respond_to_fail_existence
        check_fail("message.\n" +
                    "!<:symbol>.respond_to?(:to_s) expected\n" +
                    "(Class: <Symbol>)") do
          assert_respond_to(:symbol, :to_s, "message")
        end
      end

      def test_assert_send
        object = Object.new
        class << object
          private
          def return_argument(argument, bogus)
            return argument
          end
        end
        check_nothing_fails do
          assert_send([object, :return_argument, true, "bogus"], "message")
        end

        inspected_object = AssertionMessage.convert(object)
        expected_message = <<-EOM
message.
<#{inspected_object}> expected to respond to
<return_argument(*[false, "bogus"])> with a true value but was
<false>.
EOM
        check_fail(expected_message.chomp) do
          assert_send([object, :return_argument, false, "bogus"], "message")
        end
      end

      def test_condition_invariant
        object = Object.new
        def object.inspect
          @changed = true
        end
        def object.==(other)
          @changed ||= false
          return (!@changed)
        end
        check_nothing_fails do
          assert_equal(object, object, "message")
        end
      end

      def test_assert_boolean
        check_nothing_fails do
          assert_boolean(true)
        end
        check_nothing_fails do
          assert_boolean(false)
        end

        check_fail("<true> or <false> expected but was\n<1>") do
          assert_boolean(1)
        end

        check_fail("<true> or <false> expected but was\n<nil>") do
          assert_boolean(nil)
        end

        check_fail("message.\n<true> or <false> expected but was\n<\"XXX\">") do
          assert_boolean("XXX", "message")
        end
      end

      def test_assert_true
        check_nothing_fails do
          assert_true(true)
        end

        check_fail("<true> expected but was\n<false>") do
          assert_true(false)
        end

        check_fail("<true> expected but was\n<1>") do
          assert_true(1)
        end

        check_fail("message.\n<true> expected but was\n<nil>") do
          assert_true(nil, "message")
        end
      end

      def test_assert_false
        check_nothing_fails do
          assert_false(false)
        end

        check_fail("<false> expected but was\n<true>") do
          assert_false(true)
        end

        check_fail("<false> expected but was\n<nil>") do
          assert_false(nil)
        end

        check_fail("message.\n<false> expected but was\n<:false>") do
          assert_false(:false, "message")
        end
      end

      def test_assert_compare
        check_nothing_fails do
          assert_compare(1.4, "<", 10.0)
        end

        check_nothing_fails do
          assert_compare(2, "<=", 2)
        end

        check_nothing_fails do
          assert_compare(14, ">=", 10.0)
        end

        check_nothing_fails do
          assert_compare(14, ">", 13.9)
        end

        expected_message = <<-EOM
<15> < <10> should be true
<15> expected less than
<10>.
EOM
        check_fail(expected_message.chomp) do
          assert_compare(15, "<", 10)
        end

        expected_message = <<-EOM
<15> <= <10> should be true
<15> expected less than or equal to
<10>.
EOM
        check_fail(expected_message.chomp) do
          assert_compare(15, "<=", 10)
        end

        expected_message = <<-EOM
<10> > <15> should be true
<10> expected greater than
<15>.
EOM
        check_fail(expected_message.chomp) do
          assert_compare(10, ">", 15)
        end

        expected_message = <<-EOM
<10> >= <15> should be true
<10> expected greater than or equal to
<15>.
EOM
        check_fail(expected_message.chomp) do
          assert_compare(10, ">=", 15)
        end
      end

      def test_assert_fail_assertion
        check_nothing_fails do
          assert_fail_assertion do
            flunk
          end
        end

        check_fail("Failed assertion was expected.") do
          assert_fail_assertion do
          end
        end
      end

      def test_assert_raise_message
        check_nothing_fails do
          assert_raise_message("Raise!") do
            raise "Raise!"
          end
        end

        check_nothing_fails do
          assert_raise_message("Raise!") do
            raise Exception, "Raise!"
          end
        end

        check_nothing_fails do
          assert_raise_message(/raise/i) do
            raise "Raise!"
          end
        end

        expected_message = <<-EOM
<"Expected message"> exception message expected but was
<"Actual message">.
EOM
        check_fail(expected_message.chomp) do
          assert_raise_message("Expected message") do
            raise "Actual message"
          end
        end

        expected_message = <<-EOM
<"Expected message"> exception message expected but none was thrown.
EOM
        check_fail(expected_message.chomp) do
          assert_raise_message("Expected message") do
          end
        end
      end

      def test_assert_raise_kind_of
        check_nothing_fails(true) do
          assert_raise_kind_of(SystemCallError) do
            raise Errno::EACCES
          end
        end

        expected_message = <<-EOM.chomp
<SystemCallError> family exception expected but was
<RuntimeError(<XXX>)>.
EOM
        check_fail_exception(expected_message) do
          assert_raise_kind_of(SystemCallError) do
            raise RuntimeError, "XXX"
          end
        end
      end

      def test_assert_const_defined
        check_nothing_fails do
          assert_const_defined(Test, :Unit)
        end

        check_nothing_fails do
          assert_const_defined(Test, "Unit")
        end

        check_fail("<Test>.const_defined?(<:Nonexistence>) expected.") do
          assert_const_defined(Test, :Nonexistence)
        end
      end

      def test_assert_not_const_defined
        check_nothing_fails do
          assert_not_const_defined(Test, :Nonexistence)
        end

        check_fail("!<Test>.const_defined?(<:Unit>) expected.") do
          assert_not_const_defined(Test, :Unit)
        end

        check_fail("!<Test>.const_defined?(<\"Unit\">) expected.") do
          assert_not_const_defined(Test, "Unit")
        end
      end

      def test_assert_predicate
        check_nothing_fails do
          assert_predicate([], :empty?)
        end

        check_fail("<[1]>.empty? is true value expected but was\n<false>") do
          assert_predicate([1], :empty?)
        end

        check_fail("<[1]>.respond_to?(:nonexistent?) expected\n" +
                    "(Class: <Array>)") do
          assert_predicate([1], :nonexistent?)
        end
      end

      def test_assert_not_predicate
        check_nothing_fails do
          assert_not_predicate([1], :empty?)
        end

        check_fail("<[]>.empty? is false value expected but was\n<true>") do
          assert_not_predicate([], :empty?)
        end

        check_fail("<[]>.respond_to?(:nonexistent?) expected\n" +
                    "(Class: <Array>)") do
          assert_not_predicate([], :nonexistent?)
        end
      end

      def test_assert_alias_method
        object = Object.new
        class << object
          def original_method
          end
          alias_method :alias_method, :original_method

          def other
          end
        end

        check_nothing_fails do
          assert_alias_method(object, :alias_method, :original_method)
        end

        check_nothing_fails do
          assert_alias_method(object, :original_method, :alias_method)
        end

        check_fail("<#{object.method(:other).inspect}> is alias of\n" +
                    "<#{object.method(:original_method).inspect}> expected") do
          assert_alias_method(object, :other, :original_method)
        end

        inspected_object = AssertionMessage.convert(object)
        check_fail("<#{inspected_object}>.nonexistent doesn't exist\n" +
                    "(Class: <Object>)") do
          assert_alias_method(object, :nonexistent, :original_method)
        end

        check_fail("<#{inspected_object}>.nonexistent doesn't exist\n" +
                    "(Class: <Object>)") do
          assert_alias_method(object, :alias_method, :nonexistent)
        end
      end

      def test_assert_path_exist
        check_nothing_fails do
          assert_path_exist(__FILE__)
        end

        nonexistent_file = __FILE__ + ".nonexistent"
        check_fail("<#{nonexistent_file.inspect}> expected to exist") do
          assert_path_exist(nonexistent_file)
        end
      end

      def test_assert_path_not_exist
        nonexistent_file = __FILE__ + ".nonexistent"
        check_nothing_fails do
          assert_path_not_exist(nonexistent_file)
        end

        check_fail("<#{__FILE__.inspect}> expected to not exist") do
          assert_path_not_exist(__FILE__)
        end
      end
    end

    class TestAssert < TestCase
      include AssertionCheckable

      def test_pass
        check_nothing_fails do
          assert(true)
        end
      end

      def test_pass_neither_false_or_nil
        check_nothing_fails do
          assert("a")
        end
      end

      def test_pass_with_message
        check_nothing_fails do
          assert(true, "successful assert")
        end
      end

      def test_pass_block
        check_nothing_fails do
          assert do
            true
          end
        end
      end

      def test_fail_nil
        check_fail("<nil> is not true.") do
          assert(nil)
        end
      end

      def test_fail_false
        check_fail("<false> is not true.") do
          assert(false)
        end
      end

      def test_fail_false_with_message
        check_fail("failed assert.\n" +
                    "<false> is not true.") do
          assert(false, "failed assert")
        end
      end

      def test_fail_with_assertion_message
        check_fail("user message.\n" +
                    "placeholder <:in> message") do
          assert(false, build_message("user message",
                                      "placeholder <?> message",
                                      :in))
        end
      end

      def test_fail_block
        check_fail(//) do
          assert do
            0.odd?
          end
        end
      end

      def test_error_invalid_message_true
        check_fail("assertion message must be String, Proc or " +
                    "Test::Unit::Assertions::AssertionMessage: " +
                    "<true>(<TrueClass>)") do
          begin
            assert(true, true)
          rescue ArgumentError
            raise AssertionFailedError, $!.message
          end
        end
      end

      def test_error_wrong_number_of_arguments
        check_fail("wrong number of arguments (0 for 1..2)") do
          begin
            assert
          rescue ArgumentError
            raise AssertionFailedError, $!.message
          end
        end
      end

      class TestBlock < self
        def test_with_message
          if defined?(PowerAssert)
            system_message = <<-MESSAGE
              1 == 2
MESSAGE
          else
            system_message = "<false> is not true."
          end
          check_fail("user message.\n#{system_message}") do
            assert("user message") do
              1 == 2
            end
          end
        end
      end
    end

    class TestRefute < TestCase
      include AssertionCheckable

      class TestPass < self
        def test_nil
          check_nothing_fails do
            refute(nil)
          end
        end

        def test_false
          check_nothing_fails do
            refute(false)
          end
        end

        def test_with_message
          check_nothing_fails do
            refute(nil, "successful refute")
          end
        end
      end

      class TestFailure < self
        def test_true
          check_fail("<true> is neither nil or false.") do
            refute(true)
          end
        end

        def test_with_message
          check_fail("failed refute.\n" +
                       "<true> is neither nil or false.") do
            refute(true, "failed refute")
          end
        end

        def test_fail_with_assertion_message
          check_fail("user message.\n" +
                       "placeholder <:in> message") do
            refute(true, build_message("user message",
                                       "placeholder <?> message",
                                       :in))
          end
        end

        def test_error_invalid_message_true
          check_fail("assertion message must be String, Proc or " +
                       "Test::Unit::Assertions::AssertionMessage: " +
                "<false>(<FalseClass>)") do
            begin
              refute(true, false)
            rescue ArgumentError
              raise AssertionFailedError, $!.message
            end
          end
        end
      end
    end

    class TestAssertInDelta < TestCase
      include AssertionCheckable

      def test_pass
        check_nothing_fails do
          assert_in_delta(1.4, 1.4, 0)
        end
      end

      def test_pass_without_delta
        check_nothing_fails do
          assert_in_delta(1.401, 1.402)
        end
      end

      def test_pass_with_message
        check_nothing_fails do
          assert_in_delta(0.5, 0.4, 0.1, "message")
        end
      end

      def test_pass_float_like_object
        check_nothing_fails do
          float_thing = Object.new
          def float_thing.to_f
            0.2
          end
          assert_in_delta(0.1, float_thing, 0.1)
        end
      end

      def test_pass_string_expected
        check_nothing_fails do
          assert_in_delta("0.5", 0.4, 0.1)
        end
      end

      def test_fail_with_message
        check_fail("message.\n" +
                    "<0.5> -/+ <0.05> expected to include\n" +
                    "<0.4>.\n" +
                    "\n" +
                    "Relation:\n" +
                    "<<0.4> < <0.5>-<0.05>[0.45] <= <0.5>+<0.05>[0.55]>") do
          assert_in_delta(0.5, 0.4, 0.05, "message")
        end
      end

      def test_fail_because_not_float_like_object
        object = Object.new
        inspected_object = AssertionMessage.convert(object)
        check_fail("The arguments must respond to to_f; " +
                    "the first float did not.\n" +
                    "<#{inspected_object}>.respond_to?(:to_f) expected\n" +
                    "(Class: <Object>)") do
          assert_in_delta(object, 0.4, 0.1)
        end
      end

      def test_fail_because_negaitve_delta
        check_fail("The delta should not be negative.\n" +
                    "<-0.1> expected to be\n>=\n<0.0>.") do
          assert_in_delta(0.5, 0.4, -0.1, "message")
        end
      end

      def test_fail_without_delta
        check_fail("<1.402> -/+ <0.001> expected to include\n" +
                    "<1.404>.\n" +
                    "\n" +
                    "Relation:\n" +
                    "<" +
                    "<1.402>-<0.001>[#{1.402 - 0.001}] <= " +
                    "<1.402>+<0.001>[#{1.402 + 0.001}] < " +
                    "<1.404>" +
                    ">") do
          assert_in_delta(1.402, 1.404)
        end
      end
    end

    class TestAssertNotInDelta < Test::Unit::TestCase
      include AssertionCheckable

      def test_pass
        check_nothing_fails do
          assert_not_in_delta(1.42, 1.44, 0.01)
        end
      end

      def test_pass_without_delta
        check_nothing_fails do
          assert_not_in_delta(1.402, 1.404)
        end
      end

      def test_pass_with_message
        check_nothing_fails do
          assert_not_in_delta(0.5, 0.4, 0.09, "message")
        end
      end

      def test_pass_float_like_object
        check_nothing_fails do
          float_thing = Object.new
          def float_thing.to_f
            0.2
          end
          assert_not_in_delta(0.1, float_thing, 0.09)
        end
      end

      def test_pass_string_epxected
        check_nothing_fails do
          assert_not_in_delta("0.5", 0.4, 0.09)
        end
      end

      def test_fail
        check_fail("<1.4> -/+ <0.11> expected to not include\n" +
                    "<1.5>.\n" +
                    "\n" +
                    "Relation:\n" +
                    "<" +
                    "<1.4>-<0.11>[#{1.4 - 0.11}] <= " +
                    "<1.5> <= " +
                    "<1.4>+<0.11>[#{1.4 + 0.11}]" +
                    ">") do
          assert_not_in_delta(1.4, 1.5, 0.11)
        end
      end

      def test_fail_without_delta
        check_fail("<1.402> -/+ <0.001> expected to not include\n" +
                    "<1.4021>.\n" +
                    "\n" +
                    "Relation:\n" +
                    "<" +
                    "<1.402>-<0.001>[#{1.402 - 0.001}] <= " +
                    "<1.4021> <= " +
                    "<1.402>+<0.001>[#{1.402 + 0.001}]" +
                    ">") do
          assert_not_in_delta(1.402, 1.4021)
        end
      end

      def test_fail_with_message
        check_fail("message.\n" +
                    "<0.5> -/+ <0.11> expected to not include\n" +
                    "<0.4>.\n" +
                    "\n" +
                    "Relation:\n" +
                    "<" +
                    "<0.5>-<0.11>[0.39] <= " +
                    "<0.4> <= " +
                    "<0.5>+<0.11>[0.61]" +
                    ">") do
          assert_not_in_delta(0.5, 0.4, 0.11, "message")
        end
      end

      def test_fail_because_not_float_like_object
        object = Object.new
        inspected_object = AssertionMessage.convert(object)
        check_fail("The arguments must respond to to_f; " +
                    "the first float did not.\n" +
                    "<#{inspected_object}>.respond_to?(:to_f) expected\n" +
                    "(Class: <Object>)") do
          assert_not_in_delta(object, 0.4, 0.1)
        end
      end

      def test_fail_because_negaitve_delta
        check_fail("The delta should not be negative.\n" +
                    "<-0.11> expected to be\n>=\n<0.0>.") do
          assert_not_in_delta(0.5, 0.4, -0.11, "message")
        end
      end
    end

    class TestAssertInEpsilon < TestCase
      include AssertionCheckable

      def test_pass
        check_nothing_fails do
          assert_in_epsilon(10000, 9000, 0.1)
        end
      end

      def test_pass_without_epsilon
        check_nothing_fails do
          assert_in_epsilon(10000, 9991)
        end
      end

      def test_pass_with_message
        check_nothing_fails do
          assert_in_epsilon(10000, 9000, 0.1, "message")
        end
      end

      def test_pass_float_like_object
        check_nothing_fails do
          float_thing = Object.new
          def float_thing.to_f
            9000.0
          end
          assert_in_epsilon(10000, float_thing, 0.1)
        end
      end

      def test_pass_string_expected
        check_nothing_fails do
          assert_in_epsilon("10000", 9000, 0.1)
        end
      end

      def test_pass_zero_expected
        check_nothing_fails do
          assert_in_epsilon(0, 0.00000001)
        end
      end

      def test_pass_minus_expected
        check_nothing_fails do
          assert_in_epsilon(-1, -1)
        end
      end

      def test_fail_with_message
        check_fail("message.\n" +
                    "<10000> -/+ (<10000> * <0.1>)[1000.0] " +
                    "expected to include\n" +
                    "<8999>.\n" +
                    "\n" +
                    "Relation:\n" +
                    "<" +
                    "<8999> < " +
                    "<10000>-(<10000>*<0.1>)[9000.0] <= " +
                    "<10000>+(<10000>*<0.1>)[11000.0]" +
                    ">") do
          assert_in_epsilon(10000, 8999, 0.1, "message")
        end
      end

      def test_fail_because_not_float_like_object
        object = Object.new
        inspected_object = AssertionMessage.convert(object)
        check_fail("The arguments must respond to to_f; " +
                    "the first float did not.\n" +
                    "<#{inspected_object}>.respond_to?(:to_f) expected\n" +
                    "(Class: <Object>)") do
          assert_in_epsilon(object, 9000, 0.1)
        end
      end

      def test_fail_because_negaitve_epsilon
        check_fail("The epsilon should not be negative.\n" +
                    "<-0.1> expected to be\n>=\n<0.0>.") do
          assert_in_epsilon(10000, 9000, -0.1, "message")
        end
      end

      def test_fail_without_epsilon
        check_fail("<10000> -/+ (<10000> * <0.001>)[10.0] " +
                    "expected to include\n" +
                    "<10011>.\n" +
                    "\n" +
                    "Relation:\n" +
                    "<" +
                    "<10000>-(<10000>*<0.001>)[9990.0] <= " +
                    "<10000>+(<10000>*<0.001>)[10010.0] < " +
                    "<10011>" +
                    ">") do
          assert_in_epsilon(10000, 10011)
        end
      end
    end

    class TestAssertNotInEpsilon < Test::Unit::TestCase
      include AssertionCheckable

      def test_pass
        check_nothing_fails do
          assert_not_in_epsilon(10000, 8999, 0.1)
        end
      end

      def test_pass_without_epsilon
        check_nothing_fails do
          assert_not_in_epsilon(10000, 9989)
        end
      end

      def test_pass_with_message
        check_nothing_fails do
          assert_not_in_epsilon(10000, 8999, 0.1, "message")
        end
      end

      def test_pass_float_like_object
        check_nothing_fails do
          float_thing = Object.new
          def float_thing.to_f
            8999.0
          end
          assert_not_in_epsilon(10000, float_thing, 0.1)
        end
      end

      def test_pass_string_epxected
        check_nothing_fails do
          assert_not_in_epsilon("10000", 8999, 0.1)
        end
      end

      def test_fail
        check_fail("<10000> -/+ (<10000> * <0.1>)[1000.0] " +
                    "expected to not include\n" +
                    "<9000>.\n" +
                    "\n" +
                    "Relation:\n" +
                    "<" +
                    "<10000>-(<10000>*<0.1>)[9000.0] <= " +
                    "<9000> <= " +
                    "<10000>+(<10000>*<0.1>)[11000.0]" +
                    ">") do
          assert_not_in_epsilon(10000, 9000, 0.1)
        end
      end

      def test_fail_without_epsilon
        check_fail("<10000> -/+ (<10000> * <0.001>)[10.0] " +
                    "expected to not include\n" +
                    "<9990>.\n" +
                    "\n" +
                    "Relation:\n" +
                    "<" +
                    "<10000>-(<10000>*<0.001>)[9990.0] <= " +
                    "<9990> <= " +
                    "<10000>+(<10000>*<0.001>)[10010.0]" +
                    ">") do
          assert_not_in_epsilon(10000, 9990)
        end
      end

      def test_fail_with_message
        check_fail("message.\n" +
                    "<10000> -/+ (<10000> * <0.1>)[1000.0] " +
                    "expected to not include\n" +
                    "<9000>.\n" +
                    "\n" +
                    "Relation:\n" +
                    "<" +
                    "<10000>-(<10000>*<0.1>)[9000.0] <= " +
                    "<9000> <= " +
                    "<10000>+(<10000>*<0.1>)[11000.0]" +
                    ">") do
          assert_not_in_epsilon(10000, 9000, 0.1, "message")
        end
      end

      def test_fail_because_not_float_like_object
        object = Object.new
        inspected_object = AssertionMessage.convert(object)
        check_fail("The arguments must respond to to_f; " +
                    "the first float did not.\n" +
                    "<#{inspected_object}>.respond_to?(:to_f) expected\n" +
                    "(Class: <Object>)") do
          assert_not_in_epsilon(object, 9000, 0.1)
        end
      end

      def test_fail_because_negaitve_epsilon
        check_fail("The epsilon should not be negative.\n" +
                    "<-0.1> expected to be\n>=\n<0.0>.") do
          assert_not_in_epsilon(10000, 9000, -0.1, "message")
        end
      end
    end

    class TestAssertInclude < Test::Unit::TestCase
      include AssertionCheckable

      def test_pass
        check_nothing_fails do
          assert_include([1, 2, 3], 1)
        end
      end

      def test_pass_with_message
        check_nothing_fails do
          assert_include([1, 2, 3], 1, "message")
        end
      end

      def test_fail
        check_fail("<[1, 2, 3]> expected to include\n" +
                    "<4>.") do
          assert_include([1, 2, 3], 4)
        end
      end

      def test_fail_with_message
        check_fail("message.\n" +
                    "<[1, 2, 3]> expected to include\n" +
                    "<4>.") do
          assert_include([1, 2, 3], 4, "message")
        end
      end

      def test_fail_because_not_collection_like_object
        object = Object.new
        inspected_object = AssertionMessage.convert(object)
        check_fail("The collection must respond to :include?.\n" +
                    "<#{inspected_object}>.respond_to?(:include?) expected\n" +
                    "(Class: <Object>)") do
          assert_include(object, 1)
        end
      end
    end

    class TestAssertNotInclude < Test::Unit::TestCase
      include AssertionCheckable

      def test_pass
        check_nothing_fails do
          assert_not_include([1, 2, 3], 5)
        end
      end

      def test_pass_with_message
        check_nothing_fails do
          assert_not_include([1, 2, 3], 5, "message")
        end
      end

      def test_fail
        check_fail("<[1, 2, 3]> expected to not include\n" +
                    "<2>.") do
          assert_not_include([1, 2, 3], 2)
        end
      end

      def test_fail_with_message
        check_fail("message.\n" +
                    "<[1, 2, 3]> expected to not include\n" +
                    "<2>.") do
          assert_not_include([1, 2, 3], 2, "message")
        end
      end

      def test_fail_because_not_collection_like_object
        object = Object.new
        inspected_object = AssertionMessage.convert(object)
        check_fail("The collection must respond to :include?.\n" +
                    "<#{inspected_object}>.respond_to?(:include?) expected\n" +
                    "(Class: <Object>)") do
          assert_not_include(object, 1)
        end
      end
    end

    class TestAssertEmpty < Test::Unit::TestCase
      include AssertionCheckable

      def test_pass
        check_nothing_fails do
          assert_empty([])
        end
      end

      def test_pass_with_message
        check_nothing_fails do
          assert_empty([], "message")
        end
      end

      def test_fail
        check_fail("<[1]> expected to be empty.") do
          assert_empty([1])
        end
      end

      def test_fail_with_message
        check_fail("message.\n" +
                    "<[1]> expected to be empty.") do
          assert_empty([1], "message")
        end
      end

      def test_fail_because_no_empty_method
        object = Object.new
        inspected_object = AssertionMessage.convert(object)
        check_fail("The object must respond to :empty?.\n" +
                    "<#{inspected_object}>.respond_to?(:empty?) expected\n" +
                    "(Class: <Object>)") do
          assert_empty(object)
        end
      end
    end

    class TestAssertNotEmpty < Test::Unit::TestCase
      include AssertionCheckable

      def test_pass
        check_nothing_fails do
          assert_not_empty([1])
        end
      end

      def test_pass_with_message
        check_nothing_fails do
          assert_not_empty([1], "message")
        end
      end

      def test_fail
        check_fail("<[]> expected to not be empty.") do
          assert_not_empty([])
        end
      end

      def test_fail_with_message
        check_fail("message.\n" +
                    "<[]> expected to not be empty.") do
          assert_not_empty([], "message")
        end
      end

      def test_fail_because_no_empty_method
        object = Object.new
        inspected_object = AssertionMessage.convert(object)
        check_fail("The object must respond to :empty?.\n" +
                    "<#{inspected_object}>.respond_to?(:empty?) expected\n" +
                    "(Class: <Object>)") do
          assert_not_empty(object)
        end
      end
    end

    class TestAssertNotSend < Test::Unit::TestCase
      include AssertionCheckable

      def test_pass
        check_nothing_fails do
          assert_not_send([[1, 2], :member?, 4], "message")
        end
      end

      def test_fail
        expected_message = <<-EOM
message.
<[1, 2]> expected to respond to
<member?(*[2])> with not a true value but was
<true>.
EOM
        check_fail(expected_message.chomp) do
          assert_not_send([[1, 2], :member?, 2], "message")
        end
      end
    end

    class TestTemplate < Test::Unit::TestCase
      def test_incompatible_encoding_by_diff
        need_encoding
        assert_raise(AssertionFailedError) do
          assert_equal("UTF-8の日本語\n" * 3,
                       ("Shift_JISの日本語\n" * 3).force_encoding("ASCII-8BIT"))
        end
      end

      private
      def need_encoding
        omit("need Encoding") unless Object.const_defined?(:Encoding)
      end
    end
  end
end