minitest 5.16.3 → 5.25.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,17 +1,14 @@
1
- # encoding: UTF-8
2
-
3
1
  require "minitest/autorun"
4
-
5
- if defined? Encoding then
6
- e = Encoding.default_external
7
- if e != Encoding::UTF_8 then
8
- warn ""
9
- warn ""
10
- warn "NOTE: External encoding #{e} is not UTF-8. Tests WILL fail."
11
- warn " Run tests with `RUBYOPT=-Eutf-8 rake` to avoid errors."
12
- warn ""
13
- warn ""
14
- end
2
+ require_relative "metametameta"
3
+
4
+ e = Encoding.default_external
5
+ if e != Encoding::UTF_8 then
6
+ warn ""
7
+ warn ""
8
+ warn "NOTE: External encoding #{e} is not UTF-8. Tests WILL fail."
9
+ warn " Run tests with `RUBYOPT=-Eutf-8 rake` to avoid errors."
10
+ warn ""
11
+ warn ""
15
12
  end
16
13
 
17
14
  SomeError = Class.new Exception
@@ -26,14 +23,11 @@ class TestMinitestAssertions < Minitest::Test
26
23
  # which is not threadsafe. Nearly every method in here is an
27
24
  # assertion test so it isn't worth splitting it out further.
28
25
 
29
- RUBY18 = !defined? Encoding
30
-
31
26
  # not included in JRuby
32
27
  RE_LEVELS = /\(\d+ levels\) /
33
28
 
34
29
  class DummyTest
35
30
  include Minitest::Assertions
36
- # include Minitest::Reportable # TODO: why do I really need this?
37
31
 
38
32
  attr_accessor :assertions, :failure
39
33
 
@@ -58,15 +52,6 @@ class TestMinitestAssertions < Minitest::Test
58
52
  "expected #{@assertion_count} assertions to be fired during the test, not #{@tc.assertions}")
59
53
  end
60
54
 
61
- def assert_deprecated name
62
- dep = /DEPRECATED: #{name}. From #{__FILE__}:\d+(?::.*)?/
63
- dep = "" if $-w.nil?
64
-
65
- assert_output nil, dep do
66
- yield
67
- end
68
- end
69
-
70
55
  def assert_triggered expected, klass = Minitest::Assertion
71
56
  e = assert_raises klass do
72
57
  yield
@@ -88,10 +73,6 @@ class TestMinitestAssertions < Minitest::Test
88
73
  end
89
74
  end
90
75
 
91
- def clean s
92
- s.gsub(/^ {6,10}/, "")
93
- end
94
-
95
76
  def non_verbose
96
77
  orig_verbose = $VERBOSE
97
78
  $VERBOSE = false
@@ -144,36 +125,43 @@ class TestMinitestAssertions < Minitest::Test
144
125
  end
145
126
 
146
127
  def test_assert_equal_different_collection_array_hex_invisible
147
- object1 = Object.new
148
- object2 = Object.new
149
- msg = "No visible difference in the Array#inspect output.
128
+ exp = Object.new
129
+ act = Object.new
130
+ msg = <<~EOM.chomp
131
+ No visible difference in the Array#inspect output.
150
132
  You should look at the implementation of #== on Array or its members.
151
- [#<Object:0xXXXXXX>]".gsub(/^ +/, "")
133
+ [#<Object:0xXXXXXX>]
134
+ EOM
152
135
  assert_triggered msg do
153
- @tc.assert_equal [object1], [object2]
136
+ @tc.assert_equal [exp], [act]
154
137
  end
155
138
  end
156
139
 
157
140
  def test_assert_equal_different_collection_hash_hex_invisible
158
- h1, h2 = {}, {}
159
- h1[1] = Object.new
160
- h2[1] = Object.new
161
- msg = "No visible difference in the Hash#inspect output.
141
+ exp, act = {}, {}
142
+ exp[1] = Object.new
143
+ act[1] = Object.new
144
+ act_obj = act[1]
145
+ # TODO: switch to endless when 2.7 is dropped
146
+ act_obj.define_singleton_method(:inspect) { "#<Object:0xXXXXXX>" }
147
+ msg = <<~EOM.chomp % [act]
148
+ No visible difference in the Hash#inspect output.
162
149
  You should look at the implementation of #== on Hash or its members.
163
- {1=>#<Object:0xXXXXXX>}".gsub(/^ +/, "")
150
+ %p
151
+ EOM
164
152
 
165
153
  assert_triggered msg do
166
- @tc.assert_equal h1, h2
154
+ @tc.assert_equal exp, act
167
155
  end
168
156
  end
169
157
 
170
158
  def test_assert_equal_different_diff_deactivated
171
159
  without_diff do
172
160
  assert_triggered util_msg("haha" * 10, "blah" * 10) do
173
- o1 = "haha" * 10
174
- o2 = "blah" * 10
161
+ exp = "haha" * 10
162
+ act = "blah" * 10
175
163
 
176
- @tc.assert_equal o1, o2
164
+ @tc.assert_equal exp, act
177
165
  end
178
166
  end
179
167
  end
@@ -195,78 +183,84 @@ class TestMinitestAssertions < Minitest::Test
195
183
  def initialize s; @name = s; end
196
184
  end
197
185
 
198
- o1 = c.new "a"
199
- o2 = c.new "b"
200
- msg = clean <<-EOS
186
+ exp = c.new "a"
187
+ act = c.new "b"
188
+ msg = <<~EOS
201
189
  --- expected
202
190
  +++ actual
203
191
  @@ -1 +1 @@
204
- -#<#<Class:0xXXXXXX>:0xXXXXXX @name=\"a\">
205
- +#<#<Class:0xXXXXXX>:0xXXXXXX @name=\"b\">
192
+ -#<#<Class:0xXXXXXX>:0xXXXXXX @name="a">
193
+ +#<#<Class:0xXXXXXX>:0xXXXXXX @name="b">
206
194
  EOS
207
195
 
208
196
  assert_triggered msg do
209
- @tc.assert_equal o1, o2
197
+ @tc.assert_equal exp, act
210
198
  end
211
199
  end
212
200
 
213
201
  def test_assert_equal_different_hex_invisible
214
- o1 = Object.new
215
- o2 = Object.new
202
+ exp = Object.new
203
+ act = Object.new
216
204
 
217
- msg = "No visible difference in the Object#inspect output.
205
+ msg = <<~EOM.chomp
206
+ No visible difference in the Object#inspect output.
218
207
  You should look at the implementation of #== on Object or its members.
219
- #<Object:0xXXXXXX>".gsub(/^ +/, "")
208
+ #<Object:0xXXXXXX>
209
+ EOM
220
210
 
221
211
  assert_triggered msg do
222
- @tc.assert_equal o1, o2
212
+ @tc.assert_equal exp, act
223
213
  end
224
214
  end
225
215
 
226
216
  def test_assert_equal_different_long
227
- msg = "--- expected
217
+ msg = <<~EOM
218
+ --- expected
228
219
  +++ actual
229
220
  @@ -1 +1 @@
230
- -\"hahahahahahahahahahahahahahahahahahahaha\"
231
- +\"blahblahblahblahblahblahblahblahblahblah\"
232
- ".gsub(/^ +/, "")
221
+ -"hahahahahahahahahahahahahahahahahahahaha"
222
+ +"blahblahblahblahblahblahblahblahblahblah"
223
+ EOM
233
224
 
234
225
  assert_triggered msg do
235
- o1 = "haha" * 10
236
- o2 = "blah" * 10
226
+ exp = "haha" * 10
227
+ act = "blah" * 10
237
228
 
238
- @tc.assert_equal o1, o2
229
+ @tc.assert_equal exp, act
239
230
  end
240
231
  end
241
232
 
242
233
  def test_assert_equal_different_long_invisible
243
- msg = "No visible difference in the String#inspect output.
234
+ msg = <<~EOM.chomp
235
+ No visible difference in the String#inspect output.
244
236
  You should look at the implementation of #== on String or its members.
245
- \"blahblahblahblahblahblahblahblahblahblah\"".gsub(/^ +/, "")
237
+ "blahblahblahblahblahblahblahblahblahblah"
238
+ EOM
246
239
 
247
240
  assert_triggered msg do
248
- o1 = "blah" * 10
249
- o2 = "blah" * 10
250
- def o1.== _
241
+ exp = "blah" * 10
242
+ act = "blah" * 10
243
+ def exp.== _
251
244
  false
252
245
  end
253
- @tc.assert_equal o1, o2
246
+ @tc.assert_equal exp, act
254
247
  end
255
248
  end
256
249
 
257
250
  def test_assert_equal_different_long_msg
258
- msg = "message.
251
+ msg = <<~EOM
252
+ message.
259
253
  --- expected
260
254
  +++ actual
261
255
  @@ -1 +1 @@
262
- -\"hahahahahahahahahahahahahahahahahahahaha\"
263
- +\"blahblahblahblahblahblahblahblahblahblah\"
264
- ".gsub(/^ +/, "")
256
+ -"hahahahahahahahahahahahahahahahahahahaha"
257
+ +"blahblahblahblahblahblahblahblahblahblah"
258
+ EOM
265
259
 
266
260
  assert_triggered msg do
267
- o1 = "haha" * 10
268
- o2 = "blah" * 10
269
- @tc.assert_equal o1, o2, "message"
261
+ exp = "haha" * 10
262
+ act = "blah" * 10
263
+ @tc.assert_equal exp, act, "message"
270
264
  end
271
265
  end
272
266
 
@@ -290,7 +284,7 @@ class TestMinitestAssertions < Minitest::Test
290
284
  end
291
285
 
292
286
  def test_assert_equal_does_not_allow_lhs_nil
293
- if Minitest::VERSION =~ /^6/ then
287
+ if Minitest::VERSION >= "6" then
294
288
  warn "Time to strip the MT5 test"
295
289
 
296
290
  @assertion_count += 1
@@ -301,7 +295,7 @@ class TestMinitestAssertions < Minitest::Test
301
295
  err_re = /Use assert_nil if expecting nil from .*test_minitest_\w+.rb/
302
296
  err_re = "" if $-w.nil?
303
297
 
304
- assert_output "", err_re do
298
+ assert_deprecation err_re do
305
299
  @tc.assert_equal nil, nil
306
300
  end
307
301
  end
@@ -314,29 +308,23 @@ class TestMinitestAssertions < Minitest::Test
314
308
  end
315
309
 
316
310
  def test_assert_equal_string_bug791
317
- exp = <<-'EOF'.gsub(/^ {10}/, "") # note single quotes
318
- --- expected
319
- +++ actual
320
- @@ -1,2 +1 @@
321
- -"\\n
322
- -"
323
- +"\\\"
324
- EOF
325
-
326
- exp = "Expected: \"\\\\n\"\n Actual: \"\\\\\""
311
+ exp = <<~EOM.chomp
312
+ Expected: "\\\\n"
313
+ Actual: "\\\\"
314
+ EOM
327
315
  assert_triggered exp do
328
316
  @tc.assert_equal "\\n", "\\"
329
317
  end
330
318
  end
331
319
 
332
320
  def test_assert_equal_string_both_escaped_unescaped_newlines
333
- msg = <<-EOM.gsub(/^ {10}/, "")
321
+ msg = <<~EOM
334
322
  --- expected
335
323
  +++ actual
336
324
  @@ -1,2 +1 @@
337
- -\"A\\n
338
- -B\"
339
- +\"A\\n\\\\nB\"
325
+ -"A\\n
326
+ -B"
327
+ +"A\\n\\\\nB"
340
328
  EOM
341
329
 
342
330
  assert_triggered msg do
@@ -348,7 +336,7 @@ class TestMinitestAssertions < Minitest::Test
348
336
  end
349
337
 
350
338
  def test_assert_equal_string_encodings
351
- msg = <<-EOM.gsub(/^ {10}/, "")
339
+ msg = <<~EOM
352
340
  --- expected
353
341
  +++ actual
354
342
  @@ -1,3 +1,3 @@
@@ -360,14 +348,14 @@ class TestMinitestAssertions < Minitest::Test
360
348
  EOM
361
349
 
362
350
  assert_triggered msg do
363
- x = "bad-utf8-\xF1.txt"
364
- y = x.dup.force_encoding "binary" # TODO: switch to .b when 1.9 dropped
365
- @tc.assert_equal x, y
351
+ exp = "bad-utf8-\xF1.txt"
352
+ act = exp.dup.b
353
+ @tc.assert_equal exp, act
366
354
  end
367
- end unless RUBY18
355
+ end
368
356
 
369
357
  def test_assert_equal_string_encodings_both_different
370
- msg = <<-EOM.gsub(/^ {10}/, "")
358
+ msg = <<~EOM
371
359
  --- expected
372
360
  +++ actual
373
361
  @@ -1,3 +1,3 @@
@@ -379,14 +367,14 @@ class TestMinitestAssertions < Minitest::Test
379
367
  EOM
380
368
 
381
369
  assert_triggered msg do
382
- x = "bad-utf8-\xF1.txt".force_encoding "ASCII"
383
- y = x.dup.force_encoding "binary" # TODO: switch to .b when 1.9 dropped
384
- @tc.assert_equal x, y
370
+ exp = "bad-utf8-\xF1.txt".dup.force_encoding Encoding::ASCII
371
+ act = exp.dup.b
372
+ @tc.assert_equal exp, act
385
373
  end
386
- end unless RUBY18
374
+ end
387
375
 
388
376
  def test_assert_equal_unescape_newlines
389
- msg = <<-'EOM'.gsub(/^ {10}/, "") # NOTE single quotes on heredoc
377
+ msg = <<~'EOM' # NOTE single quotes on heredoc
390
378
  --- expected
391
379
  +++ actual
392
380
  @@ -1,2 +1,2 @@
@@ -438,7 +426,7 @@ class TestMinitestAssertions < Minitest::Test
438
426
  end
439
427
 
440
428
  def test_assert_in_epsilon_triggered_negative_case
441
- x = (RUBY18 and not maglev?) ? "0.1" : "0.100000xxx"
429
+ x = "0.100000xxx"
442
430
  y = "0.1"
443
431
  assert_triggered "Expected |-1.1 - -1| (#{x}) to be <= #{y}." do
444
432
  @tc.assert_in_epsilon(-1.1, -1, 0.1)
@@ -728,6 +716,7 @@ class TestMinitestAssertions < Minitest::Test
728
716
  end
729
717
  end
730
718
  end
719
+
731
720
  def test_assert_predicate
732
721
  @tc.assert_predicate "", :empty?
733
722
  end
@@ -757,17 +746,18 @@ class TestMinitestAssertions < Minitest::Test
757
746
  end
758
747
  end
759
748
 
760
- expected = clean <<-EOM.chomp
749
+ expected = <<~EOM.chomp
761
750
  [StandardError] exception expected, not
762
751
  Class: <SomeError>
763
- Message: <\"blah\">
752
+ Message: <"blah">
764
753
  ---Backtrace---
765
- FILE:LINE:in \`block in test_assert_raises_default_triggered\'
754
+ FILE:LINE:in 'block in test_assert_raises_default_triggered'
766
755
  ---------------
767
756
  EOM
768
757
 
769
758
  actual = e.message.gsub(/^.+:\d+/, "FILE:LINE")
770
- actual.gsub!(RE_LEVELS, "") unless jruby?
759
+ actual.gsub! RE_LEVELS, "" unless jruby?
760
+ actual.gsub!(/[`']block in (?:TestMinitestAssertions#)?/, "'block in ")
771
761
 
772
762
  assert_equal expected, actual
773
763
  end
@@ -836,17 +826,18 @@ class TestMinitestAssertions < Minitest::Test
836
826
  end
837
827
  end
838
828
 
839
- expected = clean <<-EOM
829
+ expected = <<~EOM
840
830
  [SomeError] exception expected, not
841
831
  Class: <AnError>
842
- Message: <\"some message\">
832
+ Message: <"some message">
843
833
  ---Backtrace---
844
- FILE:LINE:in \`block in test_assert_raises_subclass_triggered\'
834
+ FILE:LINE:in 'block in test_assert_raises_subclass_triggered'
845
835
  ---------------
846
836
  EOM
847
837
 
848
838
  actual = e.message.gsub(/^.+:\d+/, "FILE:LINE")
849
- actual.gsub!(RE_LEVELS, "") unless jruby?
839
+ actual.gsub! RE_LEVELS, "" unless jruby?
840
+ actual.gsub!(/[`']block in (?:TestMinitestAssertions#)?/, "'block in ")
850
841
 
851
842
  assert_equal expected.chomp, actual
852
843
  end
@@ -858,17 +849,18 @@ class TestMinitestAssertions < Minitest::Test
858
849
  end
859
850
  end
860
851
 
861
- expected = clean <<-EOM.chomp
852
+ expected = <<~EOM.chomp
862
853
  [RuntimeError] exception expected, not
863
854
  Class: <SyntaxError>
864
- Message: <\"icky\">
855
+ Message: <"icky">
865
856
  ---Backtrace---
866
- FILE:LINE:in \`block in test_assert_raises_triggered_different\'
857
+ FILE:LINE:in 'block in test_assert_raises_triggered_different'
867
858
  ---------------
868
859
  EOM
869
860
 
870
861
  actual = e.message.gsub(/^.+:\d+/, "FILE:LINE")
871
- actual.gsub!(RE_LEVELS, "") unless jruby?
862
+ actual.gsub! RE_LEVELS, "" unless jruby?
863
+ actual.gsub!(/[`']block in (?:TestMinitestAssertions#)?/, "'block in ")
872
864
 
873
865
  assert_equal expected, actual
874
866
  end
@@ -880,18 +872,19 @@ class TestMinitestAssertions < Minitest::Test
880
872
  end
881
873
  end
882
874
 
883
- expected = clean <<-EOM
875
+ expected = <<~EOM
884
876
  XXX.
885
877
  [RuntimeError] exception expected, not
886
878
  Class: <SyntaxError>
887
- Message: <\"icky\">
879
+ Message: <"icky">
888
880
  ---Backtrace---
889
- FILE:LINE:in \`block in test_assert_raises_triggered_different_msg\'
881
+ FILE:LINE:in 'block in test_assert_raises_triggered_different_msg'
890
882
  ---------------
891
883
  EOM
892
884
 
893
885
  actual = e.message.gsub(/^.+:\d+/, "FILE:LINE")
894
- actual.gsub!(RE_LEVELS, "") unless jruby?
886
+ actual.gsub! RE_LEVELS, "" unless jruby?
887
+ actual.gsub!(/[`']block in (?:TestMinitestAssertions#)?/, "'block in ")
895
888
 
896
889
  assert_equal expected.chomp, actual
897
890
  end
@@ -936,6 +929,16 @@ class TestMinitestAssertions < Minitest::Test
936
929
  end
937
930
  end
938
931
 
932
+ def test_assert_respond_to__include_all
933
+ @tc.assert_respond_to @tc, :exit, include_all: true
934
+ end
935
+
936
+ def test_assert_respond_to__include_all_triggered
937
+ assert_triggered(/Expected .+::DummyTest. to respond to #exit\?/) do
938
+ @tc.assert_respond_to @tc, :exit?, include_all: true
939
+ end
940
+ end
941
+
939
942
  def test_assert_same
940
943
  @assertion_count = 3
941
944
 
@@ -952,8 +955,8 @@ class TestMinitestAssertions < Minitest::Test
952
955
  @tc.assert_same 1, 2
953
956
  end
954
957
 
955
- s1 = "blah"
956
- s2 = "blah"
958
+ s1 = +"blah"
959
+ s2 = +"blah"
957
960
 
958
961
  assert_triggered 'Expected "blah" (oid=N) to be the same as "blah" (oid=N).' do
959
962
  @tc.assert_same s1, s2
@@ -961,16 +964,24 @@ class TestMinitestAssertions < Minitest::Test
961
964
  end
962
965
 
963
966
  def test_assert_send
964
- assert_deprecated :assert_send do
967
+ @assertion_count = 0 if error_on_warn?
968
+ assert_deprecation(/DEPRECATED: assert_send/) do
965
969
  @tc.assert_send [1, :<, 2]
966
970
  end
967
971
  end
968
972
 
969
973
  def test_assert_send_bad
970
- assert_deprecated :assert_send do
971
- assert_triggered "Expected 1.>(*[2]) to return true." do
974
+ if error_on_warn? then
975
+ @assertion_count = 0
976
+ assert_deprecation(/DEPRECATED: assert_send/) do
972
977
  @tc.assert_send [1, :>, 2]
973
978
  end
979
+ else
980
+ assert_triggered "Expected 1.>(*[2]) to return true." do
981
+ assert_deprecation(/DEPRECATED: assert_send/) do
982
+ @tc.assert_send [1, :>, 2]
983
+ end
984
+ end
974
985
  end
975
986
  end
976
987
 
@@ -1062,6 +1073,66 @@ class TestMinitestAssertions < Minitest::Test
1062
1073
  end
1063
1074
  end
1064
1075
 
1076
+ def test_assert_pattern
1077
+ if RUBY_VERSION > "3" then
1078
+ @tc.assert_pattern do
1079
+ exp = if RUBY_VERSION.start_with? "3.0"
1080
+ "(eval):1: warning: One-line pattern matching is experimental, and the behavior may change in future versions of Ruby!\n"
1081
+ else
1082
+ ""
1083
+ end
1084
+ assert_output nil, exp do
1085
+ eval "[1,2,3] => [Integer, Integer, Integer]" # eval to escape parser for ruby<3
1086
+ end
1087
+ end
1088
+ else
1089
+ @assertion_count = 0
1090
+
1091
+ assert_raises NotImplementedError do
1092
+ @tc.assert_pattern do
1093
+ # do nothing
1094
+ end
1095
+ end
1096
+ end
1097
+ end
1098
+
1099
+ def test_assert_pattern_traps_nomatchingpatternerror
1100
+ skip unless RUBY_VERSION > "3"
1101
+ exp = if RUBY_VERSION.start_with? "3.0" then
1102
+ "[1, 2, 3]" # terrible error message!
1103
+ else
1104
+ /length mismatch/
1105
+ end
1106
+
1107
+ assert_triggered exp do
1108
+ @tc.assert_pattern do
1109
+ capture_io do # 3.0 is noisy
1110
+ eval "[1,2,3] => [Integer, Integer]" # eval to escape parser for ruby<3
1111
+ end
1112
+ end
1113
+ end
1114
+ end
1115
+
1116
+ def test_assert_pattern_raises_other_exceptions
1117
+ skip unless RUBY_VERSION >= "3.0"
1118
+
1119
+ @assertion_count = 0
1120
+
1121
+ assert_raises RuntimeError do
1122
+ @tc.assert_pattern do
1123
+ raise "boom"
1124
+ end
1125
+ end
1126
+ end
1127
+
1128
+ def test_assert_pattern_with_no_block
1129
+ skip unless RUBY_VERSION >= "3.0"
1130
+
1131
+ assert_triggered "assert_pattern requires a block to capture errors." do
1132
+ @tc.assert_pattern
1133
+ end
1134
+ end
1135
+
1065
1136
  def test_capture_io
1066
1137
  @assertion_count = 0
1067
1138
 
@@ -1081,8 +1152,8 @@ class TestMinitestAssertions < Minitest::Test
1081
1152
 
1082
1153
  non_verbose do
1083
1154
  out, err = capture_subprocess_io do
1084
- system("echo hi")
1085
- system("echo bye! 1>&2")
1155
+ system "echo hi"
1156
+ system "echo bye! 1>&2"
1086
1157
  end
1087
1158
 
1088
1159
  assert_equal "hi\n", out
@@ -1093,18 +1164,14 @@ class TestMinitestAssertions < Minitest::Test
1093
1164
  def test_class_asserts_match_refutes
1094
1165
  @assertion_count = 0
1095
1166
 
1096
- methods = Minitest::Assertions.public_instance_methods
1097
- methods.map!(&:to_s) if Symbol === methods.first
1167
+ methods = Minitest::Assertions.public_instance_methods.map(&:to_s)
1098
1168
 
1099
1169
  # These don't have corresponding refutes _on purpose_. They're
1100
1170
  # useless and will never be added, so don't bother.
1101
1171
  ignores = %w[assert_output assert_raises assert_send
1102
1172
  assert_silent assert_throws assert_mock]
1103
1173
 
1104
- # These are test/unit methods. I'm not actually sure why they're still here
1105
- ignores += %w[assert_no_match assert_not_equal assert_not_nil
1106
- assert_not_same assert_nothing_raised
1107
- assert_nothing_thrown assert_raise]
1174
+ ignores += %w[assert_allocations] # for minitest-gcstats
1108
1175
 
1109
1176
  asserts = methods.grep(/^assert/).sort - ignores
1110
1177
  refutes = methods.grep(/^refute/).sort - ignores
@@ -1314,6 +1381,56 @@ class TestMinitestAssertions < Minitest::Test
1314
1381
  end
1315
1382
  end
1316
1383
 
1384
+ def test_refute_pattern
1385
+ if RUBY_VERSION >= "3.0"
1386
+ @tc.refute_pattern do
1387
+ capture_io do # 3.0 is noisy
1388
+ eval "[1,2,3] => [Integer, Integer, String]"
1389
+ end
1390
+ end
1391
+ else
1392
+ @assertion_count = 0
1393
+
1394
+ assert_raises NotImplementedError do
1395
+ @tc.refute_pattern do
1396
+ eval "[1,2,3] => [Integer, Integer, String]"
1397
+ end
1398
+ end
1399
+ end
1400
+ end
1401
+
1402
+ def test_refute_pattern_expects_nomatchingpatternerror
1403
+ skip unless RUBY_VERSION > "3"
1404
+
1405
+ assert_triggered(/NoMatchingPatternError expected, but nothing was raised./) do
1406
+ @tc.refute_pattern do
1407
+ capture_io do # 3.0 is noisy
1408
+ eval "[1,2,3] => [Integer, Integer, Integer]"
1409
+ end
1410
+ end
1411
+ end
1412
+ end
1413
+
1414
+ def test_refute_pattern_raises_other_exceptions
1415
+ skip unless RUBY_VERSION >= "3.0"
1416
+
1417
+ @assertion_count = 0
1418
+
1419
+ assert_raises RuntimeError do
1420
+ @tc.refute_pattern do
1421
+ raise "boom"
1422
+ end
1423
+ end
1424
+ end
1425
+
1426
+ def test_refute_pattern_with_no_block
1427
+ skip unless RUBY_VERSION >= "3.0"
1428
+
1429
+ assert_triggered "refute_pattern requires a block to capture errors." do
1430
+ @tc.refute_pattern
1431
+ end
1432
+ end
1433
+
1317
1434
  def test_refute_predicate
1318
1435
  @tc.refute_predicate "42", :empty?
1319
1436
  end
@@ -1334,6 +1451,16 @@ class TestMinitestAssertions < Minitest::Test
1334
1451
  end
1335
1452
  end
1336
1453
 
1454
+ def test_refute_respond_to__include_all
1455
+ @tc.refute_respond_to "blah", :missing, include_all: true
1456
+ end
1457
+
1458
+ def test_refute_respond_to__include_all_triggered
1459
+ assert_triggered(/Expected .*DummyTest.* to not respond to exit./) do
1460
+ @tc.refute_respond_to @tc, :exit, include_all: true
1461
+ end
1462
+ end
1463
+
1337
1464
  def test_refute_same
1338
1465
  @tc.refute_same 1, 2
1339
1466
  end
@@ -1372,7 +1499,7 @@ class TestMinitestAssertions < Minitest::Test
1372
1499
  d0 = Time.now
1373
1500
  d1 = d0 + 86_400 # I am an idiot
1374
1501
 
1375
- assert_output "", /Stale skip_until \"not yet\" at .*?:\d+$/ do
1502
+ assert_deprecation(/Stale skip_until \"not yet\" at .*?:\d+$/) do
1376
1503
  assert_skip_until d0, "not yet"
1377
1504
  end
1378
1505
 
@@ -1419,9 +1546,11 @@ class TestMinitestAssertionHelpers < Minitest::Test
1419
1546
  end
1420
1547
 
1421
1548
  def test_diff_equal
1422
- msg = "No visible difference in the String#inspect output.
1549
+ msg = <<~EOM.chomp
1550
+ No visible difference in the String#inspect output.
1423
1551
  You should look at the implementation of #== on String or its members.
1424
- \"blahblahblahblahblahblahblahblahblahblah\"".gsub(/^ +/, "")
1552
+ "blahblahblahblahblahblahblahblahblahblah"
1553
+ EOM
1425
1554
 
1426
1555
  o1 = "blah" * 10
1427
1556
  o2 = "blah" * 10
@@ -1433,7 +1562,7 @@ class TestMinitestAssertionHelpers < Minitest::Test
1433
1562
  end
1434
1563
 
1435
1564
  def test_diff_str_mixed
1436
- msg = <<-'EOM'.gsub(/^ {10}/, "") # NOTE single quotes on heredoc
1565
+ msg = <<~'EOM' # NOTE single quotes on heredoc
1437
1566
  --- expected
1438
1567
  +++ actual
1439
1568
  @@ -1 +1 @@
@@ -1448,7 +1577,7 @@ class TestMinitestAssertionHelpers < Minitest::Test
1448
1577
  end
1449
1578
 
1450
1579
  def test_diff_str_multiline
1451
- msg = <<-'EOM'.gsub(/^ {10}/, "") # NOTE single quotes on heredoc
1580
+ msg = <<~EOM
1452
1581
  --- expected
1453
1582
  +++ actual
1454
1583
  @@ -1,2 +1,2 @@
@@ -1464,7 +1593,7 @@ class TestMinitestAssertionHelpers < Minitest::Test
1464
1593
  end
1465
1594
 
1466
1595
  def test_diff_str_simple
1467
- msg = <<-'EOM'.gsub(/^ {10}/, "").chomp # NOTE single quotes on heredoc
1596
+ msg = <<~EOM.chomp
1468
1597
  Expected: "A"
1469
1598
  Actual: "B"
1470
1599
  EOM
@@ -1516,14 +1645,14 @@ class TestMinitestAssertionHelpers < Minitest::Test
1516
1645
  end
1517
1646
 
1518
1647
  def test_mu_pp_for_diff_str_bad_encoding
1519
- str = "\666".force_encoding Encoding::UTF_8
1648
+ str = "\666".dup.force_encoding Encoding::UTF_8
1520
1649
  exp = "# encoding: UTF-8\n# valid: false\n\"\\xB6\""
1521
1650
 
1522
1651
  assert_mu_pp_for_diff exp, str, :raw
1523
1652
  end
1524
1653
 
1525
1654
  def test_mu_pp_for_diff_str_bad_encoding_both
1526
- str = "\666A\\n\nB".force_encoding Encoding::UTF_8
1655
+ str = "\666A\\n\nB".dup.force_encoding Encoding::UTF_8
1527
1656
  exp = "# encoding: UTF-8\n# valid: false\n\"\\xB6A\\\\n\\nB\""
1528
1657
 
1529
1658
  assert_mu_pp_for_diff exp, str, :raw
@@ -1570,7 +1699,7 @@ class TestMinitestAssertionHelpers < Minitest::Test
1570
1699
  end
1571
1700
 
1572
1701
  def test_mu_pp_str_bad_encoding
1573
- str = "\666".force_encoding Encoding::UTF_8
1702
+ str = "\666".dup.force_encoding Encoding::UTF_8
1574
1703
  exp = "# encoding: UTF-8\n# valid: false\n\"\\xB6\""
1575
1704
 
1576
1705
  assert_mu_pp exp, str, :raw