minitest 5.11.0 → 5.12.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -15,11 +15,6 @@ if defined? Encoding then
15
15
  end
16
16
  end
17
17
 
18
- module MyModule; end
19
- class AnError < StandardError; include MyModule; end
20
- class ImmutableString < String; def inspect; super.freeze; end; end
21
- SomeError = Class.new Exception
22
-
23
18
  class Minitest::Runnable
24
19
  def whatever # faked for testing
25
20
  assert true
@@ -124,7 +119,10 @@ class TestMinitestUnit < MetaMetaMetaTestCase
124
119
 
125
120
  test = test_class.new :test_omg
126
121
  test.run
127
- assert test.passed?
122
+
123
+ refute_predicate test, :error?
124
+ assert_predicate test, :passed?
125
+ refute_predicate test, :skipped?
128
126
  end
129
127
 
130
128
  def test_passed_eh_teardown_skipped
@@ -136,8 +134,9 @@ class TestMinitestUnit < MetaMetaMetaTestCase
136
134
  test = test_class.new :test_omg
137
135
  test.run
138
136
 
139
- assert test.skipped?
140
- refute test.passed?
137
+ refute_predicate test, :error?
138
+ refute_predicate test, :passed?
139
+ assert_predicate test, :skipped?
141
140
  end
142
141
 
143
142
  def test_passed_eh_teardown_flunked
@@ -148,7 +147,10 @@ class TestMinitestUnit < MetaMetaMetaTestCase
148
147
 
149
148
  test = test_class.new :test_omg
150
149
  test.run
151
- refute test.passed?
150
+
151
+ refute_predicate test, :error?
152
+ refute_predicate test, :passed?
153
+ refute_predicate test, :skipped?
152
154
  end
153
155
 
154
156
  def util_expand_bt bt
@@ -778,7 +780,7 @@ class TestMinitestRunnable < Minitest::Test
778
780
  def test_marshal
779
781
  setup_marshal Minitest::Runnable
780
782
 
781
- assert_marshal %w[@assertions @failures @klass @name @source_location @time]
783
+ assert_marshal %w[@NAME @assertions @failures @klass @source_location @time]
782
784
  end
783
785
 
784
786
  def test_spec_marshal
@@ -807,7 +809,7 @@ class TestMinitestTest < TestMinitestRunnable
807
809
  tc.time = 3.14
808
810
  end
809
811
 
810
- assert_marshal %w[@assertions @failures @klass @name @source_location @time] do |new_tc|
812
+ assert_marshal %w[@NAME @assertions @failures @klass @source_location @time] do |new_tc|
811
813
  assert_in_epsilon 3.14, new_tc.time
812
814
  end
813
815
  end
@@ -844,1060 +846,6 @@ class TestMinitestUnitTestCase < Minitest::Test
844
846
  $VERBOSE = orig_verbose
845
847
  end
846
848
 
847
- def test_assert
848
- @assertion_count = 2
849
-
850
- @tc.assert_equal true, @tc.assert(true), "returns true on success"
851
- end
852
-
853
- def test_assert__triggered
854
- assert_triggered "Expected false to be truthy." do
855
- @tc.assert false
856
- end
857
- end
858
-
859
- def test_assert__triggered_message
860
- assert_triggered @zomg do
861
- @tc.assert false, @zomg
862
- end
863
- end
864
-
865
- def test_assert_empty
866
- @assertion_count = 2
867
-
868
- @tc.assert_empty []
869
- end
870
-
871
- def test_assert_empty_triggered
872
- @assertion_count = 2
873
-
874
- assert_triggered "Expected [1] to be empty." do
875
- @tc.assert_empty [1]
876
- end
877
- end
878
-
879
- def test_assert_equal
880
- @tc.assert_equal 1, 1
881
- end
882
-
883
- def test_assert_equal_different_collection_array_hex_invisible
884
- object1 = Object.new
885
- object2 = Object.new
886
- msg = "No visible difference in the Array#inspect output.
887
- You should look at the implementation of #== on Array or its members.
888
- [#<Object:0xXXXXXX>]".gsub(/^ +/, "")
889
- assert_triggered msg do
890
- @tc.assert_equal [object1], [object2]
891
- end
892
- end
893
-
894
- def test_assert_equal_different_collection_hash_hex_invisible
895
- h1, h2 = {}, {}
896
- h1[1] = Object.new
897
- h2[1] = Object.new
898
- msg = "No visible difference in the Hash#inspect output.
899
- You should look at the implementation of #== on Hash or its members.
900
- {1=>#<Object:0xXXXXXX>}".gsub(/^ +/, "")
901
-
902
- assert_triggered msg do
903
- @tc.assert_equal h1, h2
904
- end
905
- end
906
-
907
- def test_assert_equal_string_encodings
908
- msg = <<-EOM.gsub(/^ {10}/, "")
909
- --- expected
910
- +++ actual
911
- @@ -1 +1,2 @@
912
- +# encoding: ASCII-8BIT
913
- "bad-utf8-\\xF1.txt"
914
- EOM
915
-
916
- assert_triggered msg do
917
- x = "bad-utf8-\xF1.txt"
918
- y = x.dup.force_encoding "binary" # TODO: switch to .b when 1.9 dropped
919
- @tc.assert_equal x, y
920
- end
921
- end unless RUBY18
922
-
923
- def test_assert_equal_string_encodings_both_different
924
- msg = <<-EOM.gsub(/^ {10}/, "")
925
- --- expected
926
- +++ actual
927
- @@ -1,2 +1,2 @@
928
- -# encoding: US-ASCII
929
- +# encoding: ASCII-8BIT
930
- "bad-utf8-\\xF1.txt"
931
- EOM
932
-
933
- assert_triggered msg do
934
- x = "bad-utf8-\xF1.txt".force_encoding "ASCII"
935
- y = x.dup.force_encoding "binary" # TODO: switch to .b when 1.9 dropped
936
- @tc.assert_equal x, y
937
- end
938
- end unless RUBY18
939
-
940
- def test_assert_equal_different_diff_deactivated
941
- skip "https://github.com/MagLev/maglev/issues/209" if maglev?
942
-
943
- without_diff do
944
- assert_triggered util_msg("haha" * 10, "blah" * 10) do
945
- o1 = "haha" * 10
946
- o2 = "blah" * 10
947
-
948
- @tc.assert_equal o1, o2
949
- end
950
- end
951
- end
952
-
953
- def test_assert_equal_different_hex
954
- c = Class.new do
955
- def initialize s; @name = s; end
956
- end
957
-
958
- o1 = c.new "a"
959
- o2 = c.new "b"
960
- msg = "--- expected
961
- +++ actual
962
- @@ -1 +1 @@
963
- -#<#<Class:0xXXXXXX>:0xXXXXXX @name=\"a\">
964
- +#<#<Class:0xXXXXXX>:0xXXXXXX @name=\"b\">
965
- ".gsub(/^ +/, "")
966
-
967
- assert_triggered msg do
968
- @tc.assert_equal o1, o2
969
- end
970
- end
971
-
972
- def test_assert_equal_different_hex_invisible
973
- o1 = Object.new
974
- o2 = Object.new
975
-
976
- msg = "No visible difference in the Object#inspect output.
977
- You should look at the implementation of #== on Object or its members.
978
- #<Object:0xXXXXXX>".gsub(/^ +/, "")
979
-
980
- assert_triggered msg do
981
- @tc.assert_equal o1, o2
982
- end
983
- end
984
-
985
- def test_assert_equal_different_long
986
- msg = "--- expected
987
- +++ actual
988
- @@ -1 +1 @@
989
- -\"hahahahahahahahahahahahahahahahahahahaha\"
990
- +\"blahblahblahblahblahblahblahblahblahblah\"
991
- ".gsub(/^ +/, "")
992
-
993
- assert_triggered msg do
994
- o1 = "haha" * 10
995
- o2 = "blah" * 10
996
-
997
- @tc.assert_equal o1, o2
998
- end
999
- end
1000
-
1001
- def test_assert_equal_different_long_invisible
1002
- msg = "No visible difference in the String#inspect output.
1003
- You should look at the implementation of #== on String or its members.
1004
- \"blahblahblahblahblahblahblahblahblahblah\"".gsub(/^ +/, "")
1005
-
1006
- assert_triggered msg do
1007
- o1 = "blah" * 10
1008
- o2 = "blah" * 10
1009
- def o1.== _
1010
- false
1011
- end
1012
- @tc.assert_equal o1, o2
1013
- end
1014
- end
1015
-
1016
- def test_assert_equal_different_long_msg
1017
- msg = "message.
1018
- --- expected
1019
- +++ actual
1020
- @@ -1 +1 @@
1021
- -\"hahahahahahahahahahahahahahahahahahahaha\"
1022
- +\"blahblahblahblahblahblahblahblahblahblah\"
1023
- ".gsub(/^ +/, "")
1024
-
1025
- assert_triggered msg do
1026
- o1 = "haha" * 10
1027
- o2 = "blah" * 10
1028
- @tc.assert_equal o1, o2, "message"
1029
- end
1030
- end
1031
-
1032
- def test_assert_equal_different_short
1033
- assert_triggered util_msg(1, 2) do
1034
- @tc.assert_equal 1, 2
1035
- end
1036
- end
1037
-
1038
- def test_assert_equal_different_short_msg
1039
- assert_triggered util_msg(1, 2, "message") do
1040
- @tc.assert_equal 1, 2, "message"
1041
- end
1042
- end
1043
-
1044
- def test_assert_equal_different_short_multiline
1045
- msg = "--- expected\n+++ actual\n@@ -1,2 +1,2 @@\n \"a\n-b\"\n+c\"\n"
1046
- assert_triggered msg do
1047
- @tc.assert_equal "a\nb", "a\nc"
1048
- end
1049
- end
1050
-
1051
- def test_assert_equal_does_not_allow_lhs_nil
1052
- if Minitest::VERSION =~ /^6/ then
1053
- warn "Time to strip the MT5 test"
1054
-
1055
- @assertion_count += 1
1056
- assert_triggered(/Use assert_nil if expecting nil/) do
1057
- @tc.assert_equal nil, nil
1058
- end
1059
- else
1060
- err_re = /Use assert_nil if expecting nil from .*test_minitest_test.rb/
1061
- err_re = "" if $-w.nil?
1062
-
1063
- assert_output "", err_re do
1064
- @tc.assert_equal nil, nil
1065
- end
1066
- end
1067
- end
1068
-
1069
- def test_assert_equal_does_not_allow_lhs_nil_triggered
1070
- assert_triggered "Expected: nil\n Actual: false" do
1071
- @tc.assert_equal nil, false
1072
- end
1073
- end
1074
-
1075
- def test_assert_in_delta
1076
- @tc.assert_in_delta 0.0, 1.0 / 1000, 0.1
1077
- end
1078
-
1079
- def test_delta_consistency
1080
- @assertion_count = 2
1081
-
1082
- @tc.assert_in_delta 0, 1, 1
1083
-
1084
- assert_triggered "Expected |0 - 1| (1) to not be <= 1." do
1085
- @tc.refute_in_delta 0, 1, 1
1086
- end
1087
- end
1088
-
1089
- def test_assert_in_delta_triggered
1090
- x = maglev? ? "9.999999xxxe-07" : "1.0e-06"
1091
- assert_triggered "Expected |0.0 - 0.001| (0.001) to be <= #{x}." do
1092
- @tc.assert_in_delta 0.0, 1.0 / 1000, 0.000001
1093
- end
1094
- end
1095
-
1096
- def test_assert_in_epsilon
1097
- @assertion_count = 10
1098
-
1099
- @tc.assert_in_epsilon 10_000, 9991
1100
- @tc.assert_in_epsilon 9991, 10_000
1101
- @tc.assert_in_epsilon 1.0, 1.001
1102
- @tc.assert_in_epsilon 1.001, 1.0
1103
-
1104
- @tc.assert_in_epsilon 10_000, 9999.1, 0.0001
1105
- @tc.assert_in_epsilon 9999.1, 10_000, 0.0001
1106
- @tc.assert_in_epsilon 1.0, 1.0001, 0.0001
1107
- @tc.assert_in_epsilon 1.0001, 1.0, 0.0001
1108
-
1109
- @tc.assert_in_epsilon(-1, -1)
1110
- @tc.assert_in_epsilon(-10_000, -9991)
1111
- end
1112
-
1113
- def test_epsilon_consistency
1114
- @assertion_count = 2
1115
-
1116
- @tc.assert_in_epsilon 1.0, 1.001
1117
-
1118
- msg = "Expected |1.0 - 1.001| (0.000999xxx) to not be <= 0.001."
1119
- assert_triggered msg do
1120
- @tc.refute_in_epsilon 1.0, 1.001
1121
- end
1122
- end
1123
-
1124
- def test_assert_in_epsilon_triggered
1125
- assert_triggered "Expected |10000 - 9990| (10) to be <= 9.99." do
1126
- @tc.assert_in_epsilon 10_000, 9990
1127
- end
1128
- end
1129
-
1130
- def test_assert_in_epsilon_triggered_negative_case
1131
- x = (RUBY18 and not maglev?) ? "0.1" : "0.100000xxx"
1132
- y = maglev? ? "0.100000xxx" : "0.1"
1133
- assert_triggered "Expected |-1.1 - -1| (#{x}) to be <= #{y}." do
1134
- @tc.assert_in_epsilon(-1.1, -1, 0.1)
1135
- end
1136
- end
1137
-
1138
- def test_assert_includes
1139
- @assertion_count = 2
1140
-
1141
- @tc.assert_includes [true], true
1142
- end
1143
-
1144
- def test_assert_includes_triggered
1145
- @assertion_count = 3
1146
-
1147
- e = @tc.assert_raises Minitest::Assertion do
1148
- @tc.assert_includes [true], false
1149
- end
1150
-
1151
- expected = "Expected [true] to include false."
1152
- assert_equal expected, e.message
1153
- end
1154
-
1155
- def test_assert_instance_of
1156
- @tc.assert_instance_of String, "blah"
1157
- end
1158
-
1159
- def test_assert_instance_of_triggered
1160
- assert_triggered 'Expected "blah" to be an instance of Array, not String.' do
1161
- @tc.assert_instance_of Array, "blah"
1162
- end
1163
- end
1164
-
1165
- def test_assert_kind_of
1166
- @tc.assert_kind_of String, "blah"
1167
- end
1168
-
1169
- def test_assert_kind_of_triggered
1170
- assert_triggered 'Expected "blah" to be a kind of Array, not String.' do
1171
- @tc.assert_kind_of Array, "blah"
1172
- end
1173
- end
1174
-
1175
- def test_assert_match
1176
- @assertion_count = 2
1177
- @tc.assert_match(/\w+/, "blah blah blah")
1178
- end
1179
-
1180
- def test_assert_match_matcher_object
1181
- @assertion_count = 2
1182
-
1183
- pattern = Object.new
1184
- def pattern.=~ _; true end
1185
-
1186
- @tc.assert_match pattern, 5
1187
- end
1188
-
1189
- def test_assert_match_matchee_to_str
1190
- @assertion_count = 2
1191
-
1192
- obj = Object.new
1193
- def obj.to_str; "blah" end
1194
-
1195
- @tc.assert_match "blah", obj
1196
- end
1197
-
1198
- def test_assert_match_object_triggered
1199
- @assertion_count = 2
1200
-
1201
- pattern = Object.new
1202
- def pattern.=~ _; false end
1203
- def pattern.inspect; "[Object]" end
1204
-
1205
- assert_triggered "Expected [Object] to match 5." do
1206
- @tc.assert_match pattern, 5
1207
- end
1208
- end
1209
-
1210
- def test_assert_match_triggered
1211
- @assertion_count = 2
1212
- assert_triggered 'Expected /\d+/ to match "blah blah blah".' do
1213
- @tc.assert_match(/\d+/, "blah blah blah")
1214
- end
1215
- end
1216
-
1217
- def test_assert_nil
1218
- @tc.assert_nil nil
1219
- end
1220
-
1221
- def test_assert_nil_triggered
1222
- assert_triggered "Expected 42 to be nil." do
1223
- @tc.assert_nil 42
1224
- end
1225
- end
1226
-
1227
- def test_assert_operator
1228
- @tc.assert_operator 2, :>, 1
1229
- end
1230
-
1231
- def test_assert_operator_bad_object
1232
- bad = Object.new
1233
- def bad.== _; true end
1234
-
1235
- @tc.assert_operator bad, :equal?, bad
1236
- end
1237
-
1238
- def test_assert_operator_triggered
1239
- assert_triggered "Expected 2 to be < 1." do
1240
- @tc.assert_operator 2, :<, 1
1241
- end
1242
- end
1243
-
1244
- def test_assert_output_both
1245
- @assertion_count = 2
1246
-
1247
- @tc.assert_output "yay", "blah" do
1248
- print "yay"
1249
- $stderr.print "blah"
1250
- end
1251
- end
1252
-
1253
- def test_assert_output_both_regexps
1254
- @assertion_count = 4
1255
-
1256
- @tc.assert_output(/y.y/, /bl.h/) do
1257
- print "yay"
1258
- $stderr.print "blah"
1259
- end
1260
- end
1261
-
1262
- def test_assert_output_err
1263
- @tc.assert_output nil, "blah" do
1264
- $stderr.print "blah"
1265
- end
1266
- end
1267
-
1268
- def test_assert_output_neither
1269
- @assertion_count = 0
1270
-
1271
- @tc.assert_output do
1272
- # do nothing
1273
- end
1274
- end
1275
-
1276
- def test_assert_output_out
1277
- @tc.assert_output "blah" do
1278
- print "blah"
1279
- end
1280
- end
1281
-
1282
- def test_assert_output_triggered_both
1283
- assert_triggered util_msg("blah", "blah blah", "In stderr") do
1284
- @tc.assert_output "yay", "blah" do
1285
- print "boo"
1286
- $stderr.print "blah blah"
1287
- end
1288
- end
1289
- end
1290
-
1291
- def test_assert_output_triggered_err
1292
- assert_triggered util_msg("blah", "blah blah", "In stderr") do
1293
- @tc.assert_output nil, "blah" do
1294
- $stderr.print "blah blah"
1295
- end
1296
- end
1297
- end
1298
-
1299
- def test_assert_output_triggered_out
1300
- assert_triggered util_msg("blah", "blah blah", "In stdout") do
1301
- @tc.assert_output "blah" do
1302
- print "blah blah"
1303
- end
1304
- end
1305
- end
1306
-
1307
- def test_assert_predicate
1308
- @tc.assert_predicate "", :empty?
1309
- end
1310
-
1311
- def test_assert_predicate_triggered
1312
- assert_triggered 'Expected "blah" to be empty?.' do
1313
- @tc.assert_predicate "blah", :empty?
1314
- end
1315
- end
1316
-
1317
- def test_assert_raises
1318
- @tc.assert_raises RuntimeError do
1319
- raise "blah"
1320
- end
1321
- end
1322
-
1323
- def test_assert_raises_default
1324
- @tc.assert_raises do
1325
- raise StandardError, "blah"
1326
- end
1327
- end
1328
-
1329
- def test_assert_raises_default_triggered
1330
- e = assert_raises Minitest::Assertion do
1331
- @tc.assert_raises do
1332
- raise SomeError, "blah"
1333
- end
1334
- end
1335
-
1336
- expected = clean <<-EOM.chomp
1337
- [StandardError] exception expected, not
1338
- Class: <SomeError>
1339
- Message: <\"blah\">
1340
- ---Backtrace---
1341
- FILE:LINE:in \`test_assert_raises_default_triggered\'
1342
- ---------------
1343
- EOM
1344
-
1345
- actual = e.message.gsub(/^.+:\d+/, "FILE:LINE")
1346
- actual.gsub!(/block \(\d+ levels\) in /, "") if RUBY_VERSION >= "1.9.0"
1347
-
1348
- assert_equal expected, actual
1349
- end
1350
-
1351
- def test_assert_raises_module
1352
- @tc.assert_raises MyModule do
1353
- raise AnError
1354
- end
1355
- end
1356
-
1357
- ##
1358
- # *sigh* This is quite an odd scenario, but it is from real (albeit
1359
- # ugly) test code in ruby-core:
1360
- #
1361
- # http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=29259
1362
-
1363
- def test_assert_raises_skip
1364
- @assertion_count = 0
1365
-
1366
- assert_triggered "skipped", Minitest::Skip do
1367
- @tc.assert_raises ArgumentError do
1368
- begin
1369
- raise "blah"
1370
- rescue
1371
- skip "skipped"
1372
- end
1373
- end
1374
- end
1375
- end
1376
-
1377
- def test_assert_raises_triggered_different
1378
- e = assert_raises Minitest::Assertion do
1379
- @tc.assert_raises RuntimeError do
1380
- raise SyntaxError, "icky"
1381
- end
1382
- end
1383
-
1384
- expected = clean <<-EOM.chomp
1385
- [RuntimeError] exception expected, not
1386
- Class: <SyntaxError>
1387
- Message: <\"icky\">
1388
- ---Backtrace---
1389
- FILE:LINE:in \`test_assert_raises_triggered_different\'
1390
- ---------------
1391
- EOM
1392
-
1393
- actual = e.message.gsub(/^.+:\d+/, "FILE:LINE")
1394
- actual.gsub!(/block \(\d+ levels\) in /, "") if RUBY_VERSION >= "1.9.0"
1395
-
1396
- assert_equal expected, actual
1397
- end
1398
-
1399
- def test_assert_raises_triggered_different_msg
1400
- e = assert_raises Minitest::Assertion do
1401
- @tc.assert_raises RuntimeError, "XXX" do
1402
- raise SyntaxError, "icky"
1403
- end
1404
- end
1405
-
1406
- expected = clean <<-EOM
1407
- XXX.
1408
- [RuntimeError] exception expected, not
1409
- Class: <SyntaxError>
1410
- Message: <\"icky\">
1411
- ---Backtrace---
1412
- FILE:LINE:in \`test_assert_raises_triggered_different_msg\'
1413
- ---------------
1414
- EOM
1415
-
1416
- actual = e.message.gsub(/^.+:\d+/, "FILE:LINE")
1417
- actual.gsub!(/block \(\d+ levels\) in /, "") if RUBY_VERSION >= "1.9.0"
1418
-
1419
- assert_equal expected.chomp, actual
1420
- end
1421
-
1422
- def test_assert_raises_triggered_none
1423
- e = assert_raises Minitest::Assertion do
1424
- @tc.assert_raises Minitest::Assertion do
1425
- # do nothing
1426
- end
1427
- end
1428
-
1429
- expected = "Minitest::Assertion expected but nothing was raised."
1430
-
1431
- assert_equal expected, e.message
1432
- end
1433
-
1434
- def test_assert_raises_triggered_none_msg
1435
- e = assert_raises Minitest::Assertion do
1436
- @tc.assert_raises Minitest::Assertion, "XXX" do
1437
- # do nothing
1438
- end
1439
- end
1440
-
1441
- expected = "XXX.\nMinitest::Assertion expected but nothing was raised."
1442
-
1443
- assert_equal expected, e.message
1444
- end
1445
-
1446
- def test_assert_raises_subclass
1447
- @tc.assert_raises StandardError do
1448
- raise AnError
1449
- end
1450
- end
1451
-
1452
- def test_assert_raises_subclass_triggered
1453
- e = assert_raises Minitest::Assertion do
1454
- @tc.assert_raises SomeError do
1455
- raise AnError, "some message"
1456
- end
1457
- end
1458
-
1459
- expected = clean <<-EOM
1460
- [SomeError] exception expected, not
1461
- Class: <AnError>
1462
- Message: <\"some message\">
1463
- ---Backtrace---
1464
- FILE:LINE:in \`test_assert_raises_subclass_triggered\'
1465
- ---------------
1466
- EOM
1467
-
1468
- actual = e.message.gsub(/^.+:\d+/, "FILE:LINE")
1469
- actual.gsub!(/block \(\d+ levels\) in /, "") if RUBY_VERSION >= "1.9.0"
1470
-
1471
- assert_equal expected.chomp, actual
1472
- end
1473
-
1474
- def test_assert_raises_exit
1475
- @tc.assert_raises SystemExit do
1476
- exit 1
1477
- end
1478
- end
1479
-
1480
- def test_assert_raises_signals
1481
- @tc.assert_raises SignalException do
1482
- raise SignalException, :INT
1483
- end
1484
- end
1485
-
1486
- def test_assert_respond_to
1487
- @tc.assert_respond_to "blah", :empty?
1488
- end
1489
-
1490
- def test_assert_respond_to_triggered
1491
- assert_triggered 'Expected "blah" (String) to respond to #rawr!.' do
1492
- @tc.assert_respond_to "blah", :rawr!
1493
- end
1494
- end
1495
-
1496
- def test_assert_same
1497
- @assertion_count = 3
1498
-
1499
- o = "blah"
1500
- @tc.assert_same 1, 1
1501
- @tc.assert_same :blah, :blah
1502
- @tc.assert_same o, o
1503
- end
1504
-
1505
- def test_assert_same_triggered
1506
- @assertion_count = 2
1507
-
1508
- assert_triggered "Expected 2 (oid=N) to be the same as 1 (oid=N)." do
1509
- @tc.assert_same 1, 2
1510
- end
1511
-
1512
- s1 = "blah"
1513
- s2 = "blah"
1514
-
1515
- assert_triggered 'Expected "blah" (oid=N) to be the same as "blah" (oid=N).' do
1516
- @tc.assert_same s1, s2
1517
- end
1518
- end
1519
-
1520
- def assert_deprecated name
1521
- dep = /DEPRECATED: #{name}. From #{__FILE__}:\d+(?::.*)?/
1522
- dep = "" if $-w.nil?
1523
-
1524
- assert_output nil, dep do
1525
- yield
1526
- end
1527
- end
1528
-
1529
- def test_assert_send
1530
- assert_deprecated :assert_send do
1531
- @tc.assert_send [1, :<, 2]
1532
- end
1533
- end
1534
-
1535
- def test_assert_send_bad
1536
- assert_deprecated :assert_send do
1537
- assert_triggered "Expected 1.>(*[2]) to return true." do
1538
- @tc.assert_send [1, :>, 2]
1539
- end
1540
- end
1541
- end
1542
-
1543
- def test_assert_silent
1544
- @assertion_count = 2
1545
-
1546
- @tc.assert_silent do
1547
- # do nothing
1548
- end
1549
- end
1550
-
1551
- def test_assert_silent_triggered_err
1552
- assert_triggered util_msg("", "blah blah", "In stderr") do
1553
- @tc.assert_silent do
1554
- $stderr.print "blah blah"
1555
- end
1556
- end
1557
- end
1558
-
1559
- def test_assert_silent_triggered_out
1560
- @assertion_count = 2
1561
-
1562
- assert_triggered util_msg("", "blah blah", "In stdout") do
1563
- @tc.assert_silent do
1564
- print "blah blah"
1565
- end
1566
- end
1567
- end
1568
-
1569
- def test_assert_throws
1570
- @tc.assert_throws :blah do
1571
- throw :blah
1572
- end
1573
- end
1574
-
1575
- def test_assert_throws_name_error
1576
- @tc.assert_raises NameError do
1577
- @tc.assert_throws :blah do
1578
- raise NameError
1579
- end
1580
- end
1581
- end
1582
-
1583
- def test_assert_throws_argument_exception
1584
- @tc.assert_raises ArgumentError do
1585
- @tc.assert_throws :blah do
1586
- raise ArgumentError
1587
- end
1588
- end
1589
- end
1590
-
1591
- def test_assert_throws_different
1592
- assert_triggered "Expected :blah to have been thrown, not :not_blah." do
1593
- @tc.assert_throws :blah do
1594
- throw :not_blah
1595
- end
1596
- end
1597
- end
1598
-
1599
- def test_assert_throws_unthrown
1600
- assert_triggered "Expected :blah to have been thrown." do
1601
- @tc.assert_throws :blah do
1602
- # do nothing
1603
- end
1604
- end
1605
- end
1606
-
1607
- def test_capture_io
1608
- @assertion_count = 0
1609
-
1610
- non_verbose do
1611
- out, err = capture_io do
1612
- puts "hi"
1613
- $stderr.puts "bye!"
1614
- end
1615
-
1616
- assert_equal "hi\n", out
1617
- assert_equal "bye!\n", err
1618
- end
1619
- end
1620
-
1621
- def test_capture_subprocess_io
1622
- @assertion_count = 0
1623
-
1624
- non_verbose do
1625
- out, err = capture_subprocess_io do
1626
- system("echo hi")
1627
- system("echo bye! 1>&2")
1628
- end
1629
-
1630
- assert_equal "hi\n", out
1631
- assert_equal "bye!", err.strip
1632
- end
1633
- end
1634
-
1635
- def test_class_asserts_match_refutes
1636
- @assertion_count = 0
1637
-
1638
- methods = Minitest::Assertions.public_instance_methods
1639
- methods.map!(&:to_s) if Symbol === methods.first
1640
-
1641
- # These don't have corresponding refutes _on purpose_. They're
1642
- # useless and will never be added, so don't bother.
1643
- ignores = %w[assert_output assert_raises assert_send
1644
- assert_silent assert_throws assert_mock]
1645
-
1646
- # These are test/unit methods. I'm not actually sure why they're still here
1647
- ignores += %w[assert_no_match assert_not_equal assert_not_nil
1648
- assert_not_same assert_nothing_raised
1649
- assert_nothing_thrown assert_raise]
1650
-
1651
- asserts = methods.grep(/^assert/).sort - ignores
1652
- refutes = methods.grep(/^refute/).sort - ignores
1653
-
1654
- assert_empty refutes.map { |n| n.sub(/^refute/, "assert") } - asserts
1655
- assert_empty asserts.map { |n| n.sub(/^assert/, "refute") } - refutes
1656
- end
1657
-
1658
- def test_flunk
1659
- assert_triggered "Epic Fail!" do
1660
- @tc.flunk
1661
- end
1662
- end
1663
-
1664
- def test_flunk_message
1665
- assert_triggered @zomg do
1666
- @tc.flunk @zomg
1667
- end
1668
- end
1669
-
1670
- def test_message
1671
- @assertion_count = 0
1672
-
1673
- assert_equal "blah2.", @tc.message { "blah2" }.call
1674
- assert_equal "blah2.", @tc.message("") { "blah2" }.call
1675
- assert_equal "blah1.\nblah2.", @tc.message(:blah1) { "blah2" }.call
1676
- assert_equal "blah1.\nblah2.", @tc.message("blah1") { "blah2" }.call
1677
-
1678
- message = proc { "blah1" }
1679
- assert_equal "blah1.\nblah2.", @tc.message(message) { "blah2" }.call
1680
-
1681
- message = @tc.message { "blah1" }
1682
- assert_equal "blah1.\nblah2.", @tc.message(message) { "blah2" }.call
1683
- end
1684
-
1685
- def test_message_message
1686
- assert_triggered "whoops.\nExpected: 1\n Actual: 2" do
1687
- @tc.assert_equal 1, 2, message { "whoops" }
1688
- end
1689
- end
1690
-
1691
- def test_message_lambda
1692
- assert_triggered "whoops.\nExpected: 1\n Actual: 2" do
1693
- @tc.assert_equal 1, 2, lambda { "whoops" }
1694
- end
1695
- end
1696
-
1697
- def test_message_deferred
1698
- @assertion_count, var = 0, nil
1699
-
1700
- msg = message { var = "blah" }
1701
-
1702
- assert_nil var
1703
-
1704
- msg.call
1705
-
1706
- assert_equal "blah", var
1707
- end
1708
-
1709
- def test_pass
1710
- @tc.pass
1711
- end
1712
-
1713
- def test_prints
1714
- printer = Class.new { extend Minitest::Assertions }
1715
- @tc.assert_equal '"test"', printer.mu_pp(ImmutableString.new "test")
1716
- end
1717
-
1718
- def test_refute
1719
- @assertion_count = 2
1720
-
1721
- @tc.assert_equal false, @tc.refute(false), "returns false on success"
1722
- end
1723
-
1724
- def test_refute_empty
1725
- @assertion_count = 2
1726
-
1727
- @tc.refute_empty [1]
1728
- end
1729
-
1730
- def test_refute_empty_triggered
1731
- @assertion_count = 2
1732
-
1733
- assert_triggered "Expected [] to not be empty." do
1734
- @tc.refute_empty []
1735
- end
1736
- end
1737
-
1738
- def test_refute_equal
1739
- @tc.refute_equal "blah", "yay"
1740
- end
1741
-
1742
- def test_refute_equal_triggered
1743
- assert_triggered 'Expected "blah" to not be equal to "blah".' do
1744
- @tc.refute_equal "blah", "blah"
1745
- end
1746
- end
1747
-
1748
- def test_refute_in_delta
1749
- @tc.refute_in_delta 0.0, 1.0 / 1000, 0.000001
1750
- end
1751
-
1752
- def test_refute_in_delta_triggered
1753
- x = maglev? ? "0.100000xxx" : "0.1"
1754
- assert_triggered "Expected |0.0 - 0.001| (0.001) to not be <= #{x}." do
1755
- @tc.refute_in_delta 0.0, 1.0 / 1000, 0.1
1756
- end
1757
- end
1758
-
1759
- def test_refute_in_epsilon
1760
- @tc.refute_in_epsilon 10_000, 9990-1
1761
- end
1762
-
1763
- def test_refute_in_epsilon_triggered
1764
- assert_triggered "Expected |10000 - 9990| (10) to not be <= 10.0." do
1765
- @tc.refute_in_epsilon 10_000, 9990
1766
- flunk
1767
- end
1768
- end
1769
-
1770
- def test_refute_includes
1771
- @assertion_count = 2
1772
-
1773
- @tc.refute_includes [true], false
1774
- end
1775
-
1776
- def test_refute_includes_triggered
1777
- @assertion_count = 3
1778
-
1779
- e = @tc.assert_raises Minitest::Assertion do
1780
- @tc.refute_includes [true], true
1781
- end
1782
-
1783
- expected = "Expected [true] to not include true."
1784
- assert_equal expected, e.message
1785
- end
1786
-
1787
- def test_refute_instance_of
1788
- @tc.refute_instance_of Array, "blah"
1789
- end
1790
-
1791
- def test_refute_instance_of_triggered
1792
- assert_triggered 'Expected "blah" to not be an instance of String.' do
1793
- @tc.refute_instance_of String, "blah"
1794
- end
1795
- end
1796
-
1797
- def test_refute_kind_of
1798
- @tc.refute_kind_of Array, "blah"
1799
- end
1800
-
1801
- def test_refute_kind_of_triggered
1802
- assert_triggered 'Expected "blah" to not be a kind of String.' do
1803
- @tc.refute_kind_of String, "blah"
1804
- end
1805
- end
1806
-
1807
- def test_refute_match
1808
- @assertion_count = 2
1809
- @tc.refute_match(/\d+/, "blah blah blah")
1810
- end
1811
-
1812
- def test_refute_match_matcher_object
1813
- @assertion_count = 2
1814
- @tc.refute_match Object.new, 5 # default #=~ returns false
1815
- end
1816
-
1817
- def test_refute_match_object_triggered
1818
- @assertion_count = 2
1819
-
1820
- pattern = Object.new
1821
- def pattern.=~ _; true end
1822
- def pattern.inspect; "[Object]" end
1823
-
1824
- assert_triggered "Expected [Object] to not match 5." do
1825
- @tc.refute_match pattern, 5
1826
- end
1827
- end
1828
-
1829
- def test_refute_match_triggered
1830
- @assertion_count = 2
1831
- assert_triggered 'Expected /\w+/ to not match "blah blah blah".' do
1832
- @tc.refute_match(/\w+/, "blah blah blah")
1833
- end
1834
- end
1835
-
1836
- def test_refute_nil
1837
- @tc.refute_nil 42
1838
- end
1839
-
1840
- def test_refute_nil_triggered
1841
- assert_triggered "Expected nil to not be nil." do
1842
- @tc.refute_nil nil
1843
- end
1844
- end
1845
-
1846
- def test_refute_predicate
1847
- @tc.refute_predicate "42", :empty?
1848
- end
1849
-
1850
- def test_refute_predicate_triggered
1851
- assert_triggered 'Expected "" to not be empty?.' do
1852
- @tc.refute_predicate "", :empty?
1853
- end
1854
- end
1855
-
1856
- def test_refute_operator
1857
- @tc.refute_operator 2, :<, 1
1858
- end
1859
-
1860
- def test_refute_operator_bad_object
1861
- bad = Object.new
1862
- def bad.== _; true end
1863
-
1864
- @tc.refute_operator true, :equal?, bad
1865
- end
1866
-
1867
- def test_refute_operator_triggered
1868
- assert_triggered "Expected 2 to not be > 1." do
1869
- @tc.refute_operator 2, :>, 1
1870
- end
1871
- end
1872
-
1873
- def test_refute_respond_to
1874
- @tc.refute_respond_to "blah", :rawr!
1875
- end
1876
-
1877
- def test_refute_respond_to_triggered
1878
- assert_triggered 'Expected "blah" to not respond to empty?.' do
1879
- @tc.refute_respond_to "blah", :empty?
1880
- end
1881
- end
1882
-
1883
- def test_refute_same
1884
- @tc.refute_same 1, 2
1885
- end
1886
-
1887
- def test_refute_same_triggered
1888
- assert_triggered "Expected 1 (oid=N) to not be the same as 1 (oid=N)." do
1889
- @tc.refute_same 1, 1
1890
- end
1891
- end
1892
-
1893
- def test_skip
1894
- @assertion_count = 0
1895
-
1896
- assert_triggered "haha!", Minitest::Skip do
1897
- @tc.skip "haha!"
1898
- end
1899
- end
1900
-
1901
849
  def test_runnable_methods_random
1902
850
  @assertion_count = 0
1903
851
 
@@ -1953,34 +901,6 @@ class TestMinitestUnitTestCase < Minitest::Test
1953
901
  shitty_test_case.i_suck_and_my_tests_are_order_dependent!
1954
902
  end
1955
903
  end
1956
-
1957
- def assert_triggered expected, klass = Minitest::Assertion
1958
- e = assert_raises klass do
1959
- yield
1960
- end
1961
-
1962
- msg = e.message.sub(/(---Backtrace---).*/m, '\1')
1963
- msg.gsub!(/\(oid=[-0-9]+\)/, "(oid=N)")
1964
- msg.gsub!(/(\d\.\d{6})\d+/, '\1xxx') # normalize: ruby version, impl, platform
1965
-
1966
- assert_msg = Regexp === expected ? :assert_match : :assert_equal
1967
- self.send assert_msg, expected, msg
1968
- end
1969
-
1970
- def util_msg exp, act, msg = nil
1971
- s = "Expected: #{exp.inspect}\n Actual: #{act.inspect}"
1972
- s = "#{msg}.\n#{s}" if msg
1973
- s
1974
- end
1975
-
1976
- def without_diff
1977
- old_diff = Minitest::Assertions.diff
1978
- Minitest::Assertions.diff = nil
1979
-
1980
- yield
1981
- ensure
1982
- Minitest::Assertions.diff = old_diff
1983
- end
1984
904
  end
1985
905
 
1986
906
  class TestMinitestGuard < Minitest::Test