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