minitest 5.14.4 → 5.25.5

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.
@@ -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,11 +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
26
+ # not included in JRuby
27
+ RE_LEVELS = /\(\d+ levels\) /
30
28
 
31
29
  class DummyTest
32
30
  include Minitest::Assertions
33
- # include Minitest::Reportable # TODO: why do I really need this?
34
31
 
35
32
  attr_accessor :assertions, :failure
36
33
 
@@ -55,15 +52,6 @@ class TestMinitestAssertions < Minitest::Test
55
52
  "expected #{@assertion_count} assertions to be fired during the test, not #{@tc.assertions}")
56
53
  end
57
54
 
58
- def assert_deprecated name
59
- dep = /DEPRECATED: #{name}. From #{__FILE__}:\d+(?::.*)?/
60
- dep = "" if $-w.nil?
61
-
62
- assert_output nil, dep do
63
- yield
64
- end
65
- end
66
-
67
55
  def assert_triggered expected, klass = Minitest::Assertion
68
56
  e = assert_raises klass do
69
57
  yield
@@ -85,10 +73,6 @@ class TestMinitestAssertions < Minitest::Test
85
73
  end
86
74
  end
87
75
 
88
- def clean s
89
- s.gsub(/^ {6,10}/, "")
90
- end
91
-
92
76
  def non_verbose
93
77
  orig_verbose = $VERBOSE
94
78
  $VERBOSE = false
@@ -141,36 +125,43 @@ class TestMinitestAssertions < Minitest::Test
141
125
  end
142
126
 
143
127
  def test_assert_equal_different_collection_array_hex_invisible
144
- object1 = Object.new
145
- object2 = Object.new
146
- 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.
147
132
  You should look at the implementation of #== on Array or its members.
148
- [#<Object:0xXXXXXX>]".gsub(/^ +/, "")
133
+ [#<Object:0xXXXXXX>]
134
+ EOM
149
135
  assert_triggered msg do
150
- @tc.assert_equal [object1], [object2]
136
+ @tc.assert_equal [exp], [act]
151
137
  end
152
138
  end
153
139
 
154
140
  def test_assert_equal_different_collection_hash_hex_invisible
155
- h1, h2 = {}, {}
156
- h1[1] = Object.new
157
- h2[1] = Object.new
158
- 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.
159
149
  You should look at the implementation of #== on Hash or its members.
160
- {1=>#<Object:0xXXXXXX>}".gsub(/^ +/, "")
150
+ %p
151
+ EOM
161
152
 
162
153
  assert_triggered msg do
163
- @tc.assert_equal h1, h2
154
+ @tc.assert_equal exp, act
164
155
  end
165
156
  end
166
157
 
167
158
  def test_assert_equal_different_diff_deactivated
168
159
  without_diff do
169
160
  assert_triggered util_msg("haha" * 10, "blah" * 10) do
170
- o1 = "haha" * 10
171
- o2 = "blah" * 10
161
+ exp = "haha" * 10
162
+ act = "blah" * 10
172
163
 
173
- @tc.assert_equal o1, o2
164
+ @tc.assert_equal exp, act
174
165
  end
175
166
  end
176
167
  end
@@ -192,78 +183,84 @@ class TestMinitestAssertions < Minitest::Test
192
183
  def initialize s; @name = s; end
193
184
  end
194
185
 
195
- o1 = c.new "a"
196
- o2 = c.new "b"
197
- msg = clean <<-EOS
186
+ exp = c.new "a"
187
+ act = c.new "b"
188
+ msg = <<~EOS
198
189
  --- expected
199
190
  +++ actual
200
191
  @@ -1 +1 @@
201
- -#<#<Class:0xXXXXXX>:0xXXXXXX @name=\"a\">
202
- +#<#<Class:0xXXXXXX>:0xXXXXXX @name=\"b\">
192
+ -#<#<Class:0xXXXXXX>:0xXXXXXX @name="a">
193
+ +#<#<Class:0xXXXXXX>:0xXXXXXX @name="b">
203
194
  EOS
204
195
 
205
196
  assert_triggered msg do
206
- @tc.assert_equal o1, o2
197
+ @tc.assert_equal exp, act
207
198
  end
208
199
  end
209
200
 
210
201
  def test_assert_equal_different_hex_invisible
211
- o1 = Object.new
212
- o2 = Object.new
202
+ exp = Object.new
203
+ act = Object.new
213
204
 
214
- msg = "No visible difference in the Object#inspect output.
205
+ msg = <<~EOM.chomp
206
+ No visible difference in the Object#inspect output.
215
207
  You should look at the implementation of #== on Object or its members.
216
- #<Object:0xXXXXXX>".gsub(/^ +/, "")
208
+ #<Object:0xXXXXXX>
209
+ EOM
217
210
 
218
211
  assert_triggered msg do
219
- @tc.assert_equal o1, o2
212
+ @tc.assert_equal exp, act
220
213
  end
221
214
  end
222
215
 
223
216
  def test_assert_equal_different_long
224
- msg = "--- expected
217
+ msg = <<~EOM
218
+ --- expected
225
219
  +++ actual
226
220
  @@ -1 +1 @@
227
- -\"hahahahahahahahahahahahahahahahahahahaha\"
228
- +\"blahblahblahblahblahblahblahblahblahblah\"
229
- ".gsub(/^ +/, "")
221
+ -"hahahahahahahahahahahahahahahahahahahaha"
222
+ +"blahblahblahblahblahblahblahblahblahblah"
223
+ EOM
230
224
 
231
225
  assert_triggered msg do
232
- o1 = "haha" * 10
233
- o2 = "blah" * 10
226
+ exp = "haha" * 10
227
+ act = "blah" * 10
234
228
 
235
- @tc.assert_equal o1, o2
229
+ @tc.assert_equal exp, act
236
230
  end
237
231
  end
238
232
 
239
233
  def test_assert_equal_different_long_invisible
240
- msg = "No visible difference in the String#inspect output.
234
+ msg = <<~EOM.chomp
235
+ No visible difference in the String#inspect output.
241
236
  You should look at the implementation of #== on String or its members.
242
- \"blahblahblahblahblahblahblahblahblahblah\"".gsub(/^ +/, "")
237
+ "blahblahblahblahblahblahblahblahblahblah"
238
+ EOM
243
239
 
244
240
  assert_triggered msg do
245
- o1 = "blah" * 10
246
- o2 = "blah" * 10
247
- def o1.== _
241
+ exp = "blah" * 10
242
+ act = "blah" * 10
243
+ def exp.== _
248
244
  false
249
245
  end
250
- @tc.assert_equal o1, o2
246
+ @tc.assert_equal exp, act
251
247
  end
252
248
  end
253
249
 
254
250
  def test_assert_equal_different_long_msg
255
- msg = "message.
251
+ msg = <<~EOM
252
+ message.
256
253
  --- expected
257
254
  +++ actual
258
255
  @@ -1 +1 @@
259
- -\"hahahahahahahahahahahahahahahahahahahaha\"
260
- +\"blahblahblahblahblahblahblahblahblahblah\"
261
- ".gsub(/^ +/, "")
256
+ -"hahahahahahahahahahahahahahahahahahahaha"
257
+ +"blahblahblahblahblahblahblahblahblahblah"
258
+ EOM
262
259
 
263
260
  assert_triggered msg do
264
- o1 = "haha" * 10
265
- o2 = "blah" * 10
266
- @tc.assert_equal o1, o2, "message"
261
+ exp = "haha" * 10
262
+ act = "blah" * 10
263
+ @tc.assert_equal exp, act, "message"
267
264
  end
268
265
  end
269
266
 
@@ -287,7 +284,7 @@ class TestMinitestAssertions < Minitest::Test
287
284
  end
288
285
 
289
286
  def test_assert_equal_does_not_allow_lhs_nil
290
- if Minitest::VERSION =~ /^6/ then
287
+ if Minitest::VERSION >= "6" then
291
288
  warn "Time to strip the MT5 test"
292
289
 
293
290
  @assertion_count += 1
@@ -298,7 +295,7 @@ class TestMinitestAssertions < Minitest::Test
298
295
  err_re = /Use assert_nil if expecting nil from .*test_minitest_\w+.rb/
299
296
  err_re = "" if $-w.nil?
300
297
 
301
- assert_output "", err_re do
298
+ assert_deprecation err_re do
302
299
  @tc.assert_equal nil, nil
303
300
  end
304
301
  end
@@ -311,29 +308,23 @@ class TestMinitestAssertions < Minitest::Test
311
308
  end
312
309
 
313
310
  def test_assert_equal_string_bug791
314
- exp = <<-'EOF'.gsub(/^ {10}/, "") # note single quotes
315
- --- expected
316
- +++ actual
317
- @@ -1,2 +1 @@
318
- -"\\n
319
- -"
320
- +"\\\"
321
- EOF
322
-
323
- exp = "Expected: \"\\\\n\"\n Actual: \"\\\\\""
311
+ exp = <<~EOM.chomp
312
+ Expected: "\\\\n"
313
+ Actual: "\\\\"
314
+ EOM
324
315
  assert_triggered exp do
325
316
  @tc.assert_equal "\\n", "\\"
326
317
  end
327
318
  end
328
319
 
329
320
  def test_assert_equal_string_both_escaped_unescaped_newlines
330
- msg = <<-EOM.gsub(/^ {10}/, "")
321
+ msg = <<~EOM
331
322
  --- expected
332
323
  +++ actual
333
324
  @@ -1,2 +1 @@
334
- -\"A\\n
335
- -B\"
336
- +\"A\\n\\\\nB\"
325
+ -"A\\n
326
+ -B"
327
+ +"A\\n\\\\nB"
337
328
  EOM
338
329
 
339
330
  assert_triggered msg do
@@ -345,45 +336,45 @@ class TestMinitestAssertions < Minitest::Test
345
336
  end
346
337
 
347
338
  def test_assert_equal_string_encodings
348
- msg = <<-EOM.gsub(/^ {10}/, "")
339
+ msg = <<~EOM
349
340
  --- expected
350
341
  +++ actual
351
342
  @@ -1,3 +1,3 @@
352
343
  -# encoding: UTF-8
353
344
  -# valid: false
354
- +# encoding: ASCII-8BIT
345
+ +# encoding: #{Encoding::BINARY.name}
355
346
  +# valid: true
356
347
  "bad-utf8-\\xF1.txt"
357
348
  EOM
358
349
 
359
350
  assert_triggered msg do
360
- x = "bad-utf8-\xF1.txt"
361
- y = x.dup.force_encoding "binary" # TODO: switch to .b when 1.9 dropped
362
- @tc.assert_equal x, y
351
+ exp = "bad-utf8-\xF1.txt"
352
+ act = exp.dup.b
353
+ @tc.assert_equal exp, act
363
354
  end
364
- end unless RUBY18
355
+ end
365
356
 
366
357
  def test_assert_equal_string_encodings_both_different
367
- msg = <<-EOM.gsub(/^ {10}/, "")
358
+ msg = <<~EOM
368
359
  --- expected
369
360
  +++ actual
370
361
  @@ -1,3 +1,3 @@
371
362
  -# encoding: US-ASCII
372
363
  -# valid: false
373
- +# encoding: ASCII-8BIT
364
+ +# encoding: #{Encoding::BINARY.name}
374
365
  +# valid: true
375
366
  "bad-utf8-\\xF1.txt"
376
367
  EOM
377
368
 
378
369
  assert_triggered msg do
379
- x = "bad-utf8-\xF1.txt".force_encoding "ASCII"
380
- y = x.dup.force_encoding "binary" # TODO: switch to .b when 1.9 dropped
381
- @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
382
373
  end
383
- end unless RUBY18
374
+ end
384
375
 
385
376
  def test_assert_equal_unescape_newlines
386
- msg = <<-'EOM'.gsub(/^ {10}/, "") # NOTE single quotes on heredoc
377
+ msg = <<~'EOM' # NOTE single quotes on heredoc
387
378
  --- expected
388
379
  +++ actual
389
380
  @@ -1,2 +1,2 @@
@@ -435,7 +426,7 @@ class TestMinitestAssertions < Minitest::Test
435
426
  end
436
427
 
437
428
  def test_assert_in_epsilon_triggered_negative_case
438
- x = (RUBY18 and not maglev?) ? "0.1" : "0.100000xxx"
429
+ x = "0.100000xxx"
439
430
  y = "0.1"
440
431
  assert_triggered "Expected |-1.1 - -1| (#{x}) to be <= #{y}." do
441
432
  @tc.assert_in_epsilon(-1.1, -1, 0.1)
@@ -481,7 +472,10 @@ class TestMinitestAssertions < Minitest::Test
481
472
 
482
473
  def test_assert_match
483
474
  @assertion_count = 2
484
- @tc.assert_match(/\w+/, "blah blah blah")
475
+ m = @tc.assert_match(/\w+/, "blah blah blah")
476
+
477
+ assert_kind_of MatchData, m
478
+ assert_equal "blah", m[0]
485
479
  end
486
480
 
487
481
  def test_assert_match_matchee_to_str
@@ -722,6 +716,7 @@ class TestMinitestAssertions < Minitest::Test
722
716
  end
723
717
  end
724
718
  end
719
+
725
720
  def test_assert_predicate
726
721
  @tc.assert_predicate "", :empty?
727
722
  end
@@ -751,17 +746,18 @@ class TestMinitestAssertions < Minitest::Test
751
746
  end
752
747
  end
753
748
 
754
- expected = clean <<-EOM.chomp
749
+ expected = <<~EOM.chomp
755
750
  [StandardError] exception expected, not
756
751
  Class: <SomeError>
757
- Message: <\"blah\">
752
+ Message: <"blah">
758
753
  ---Backtrace---
759
- FILE:LINE:in \`test_assert_raises_default_triggered\'
754
+ FILE:LINE:in 'block in test_assert_raises_default_triggered'
760
755
  ---------------
761
756
  EOM
762
757
 
763
758
  actual = e.message.gsub(/^.+:\d+/, "FILE:LINE")
764
- actual.gsub!(/block \(\d+ levels\) in /, "") if RUBY_VERSION >= "1.9.0"
759
+ actual.gsub! RE_LEVELS, "" unless jruby?
760
+ actual.gsub!(/[`']block in (?:TestMinitestAssertions#)?/, "'block in ")
765
761
 
766
762
  assert_equal expected, actual
767
763
  end
@@ -801,7 +797,7 @@ class TestMinitestAssertions < Minitest::Test
801
797
  # *sigh* This is quite an odd scenario, but it is from real (albeit
802
798
  # ugly) test code in ruby-core:
803
799
 
804
- # http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=29259
800
+ # https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=29259
805
801
 
806
802
  def test_assert_raises_skip
807
803
  @assertion_count = 0
@@ -830,17 +826,18 @@ class TestMinitestAssertions < Minitest::Test
830
826
  end
831
827
  end
832
828
 
833
- expected = clean <<-EOM
829
+ expected = <<~EOM
834
830
  [SomeError] exception expected, not
835
831
  Class: <AnError>
836
- Message: <\"some message\">
832
+ Message: <"some message">
837
833
  ---Backtrace---
838
- FILE:LINE:in \`test_assert_raises_subclass_triggered\'
834
+ FILE:LINE:in 'block in test_assert_raises_subclass_triggered'
839
835
  ---------------
840
836
  EOM
841
837
 
842
838
  actual = e.message.gsub(/^.+:\d+/, "FILE:LINE")
843
- actual.gsub!(/block \(\d+ levels\) in /, "") if RUBY_VERSION >= "1.9.0"
839
+ actual.gsub! RE_LEVELS, "" unless jruby?
840
+ actual.gsub!(/[`']block in (?:TestMinitestAssertions#)?/, "'block in ")
844
841
 
845
842
  assert_equal expected.chomp, actual
846
843
  end
@@ -852,17 +849,18 @@ class TestMinitestAssertions < Minitest::Test
852
849
  end
853
850
  end
854
851
 
855
- expected = clean <<-EOM.chomp
852
+ expected = <<~EOM.chomp
856
853
  [RuntimeError] exception expected, not
857
854
  Class: <SyntaxError>
858
- Message: <\"icky\">
855
+ Message: <"icky">
859
856
  ---Backtrace---
860
- FILE:LINE:in \`test_assert_raises_triggered_different\'
857
+ FILE:LINE:in 'block in test_assert_raises_triggered_different'
861
858
  ---------------
862
859
  EOM
863
860
 
864
861
  actual = e.message.gsub(/^.+:\d+/, "FILE:LINE")
865
- actual.gsub!(/block \(\d+ levels\) in /, "") if RUBY_VERSION >= "1.9.0"
862
+ actual.gsub! RE_LEVELS, "" unless jruby?
863
+ actual.gsub!(/[`']block in (?:TestMinitestAssertions#)?/, "'block in ")
866
864
 
867
865
  assert_equal expected, actual
868
866
  end
@@ -874,18 +872,19 @@ class TestMinitestAssertions < Minitest::Test
874
872
  end
875
873
  end
876
874
 
877
- expected = clean <<-EOM
875
+ expected = <<~EOM
878
876
  XXX.
879
877
  [RuntimeError] exception expected, not
880
878
  Class: <SyntaxError>
881
- Message: <\"icky\">
879
+ Message: <"icky">
882
880
  ---Backtrace---
883
- FILE:LINE:in \`test_assert_raises_triggered_different_msg\'
881
+ FILE:LINE:in 'block in test_assert_raises_triggered_different_msg'
884
882
  ---------------
885
883
  EOM
886
884
 
887
885
  actual = e.message.gsub(/^.+:\d+/, "FILE:LINE")
888
- actual.gsub!(/block \(\d+ levels\) in /, "") if RUBY_VERSION >= "1.9.0"
886
+ actual.gsub! RE_LEVELS, "" unless jruby?
887
+ actual.gsub!(/[`']block in (?:TestMinitestAssertions#)?/, "'block in ")
889
888
 
890
889
  assert_equal expected.chomp, actual
891
890
  end
@@ -930,6 +929,16 @@ class TestMinitestAssertions < Minitest::Test
930
929
  end
931
930
  end
932
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
+
933
942
  def test_assert_same
934
943
  @assertion_count = 3
935
944
 
@@ -946,8 +955,8 @@ class TestMinitestAssertions < Minitest::Test
946
955
  @tc.assert_same 1, 2
947
956
  end
948
957
 
949
- s1 = "blah"
950
- s2 = "blah"
958
+ s1 = +"blah"
959
+ s2 = +"blah"
951
960
 
952
961
  assert_triggered 'Expected "blah" (oid=N) to be the same as "blah" (oid=N).' do
953
962
  @tc.assert_same s1, s2
@@ -955,16 +964,24 @@ class TestMinitestAssertions < Minitest::Test
955
964
  end
956
965
 
957
966
  def test_assert_send
958
- assert_deprecated :assert_send do
967
+ @assertion_count = 0 if error_on_warn?
968
+ assert_deprecation(/DEPRECATED: assert_send/) do
959
969
  @tc.assert_send [1, :<, 2]
960
970
  end
961
971
  end
962
972
 
963
973
  def test_assert_send_bad
964
- assert_deprecated :assert_send do
965
- 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
966
977
  @tc.assert_send [1, :>, 2]
967
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
968
985
  end
969
986
  end
970
987
 
@@ -995,9 +1012,19 @@ class TestMinitestAssertions < Minitest::Test
995
1012
  end
996
1013
 
997
1014
  def test_assert_throws
998
- @tc.assert_throws :blah do
1015
+ v = @tc.assert_throws :blah do
999
1016
  throw :blah
1000
1017
  end
1018
+
1019
+ assert_nil v
1020
+ end
1021
+
1022
+ def test_assert_throws_value
1023
+ v = @tc.assert_throws :blah do
1024
+ throw :blah, 42
1025
+ end
1026
+
1027
+ assert_equal 42, v
1001
1028
  end
1002
1029
 
1003
1030
  def test_assert_throws_argument_exception
@@ -1046,6 +1073,66 @@ class TestMinitestAssertions < Minitest::Test
1046
1073
  end
1047
1074
  end
1048
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
+
1049
1136
  def test_capture_io
1050
1137
  @assertion_count = 0
1051
1138
 
@@ -1065,8 +1152,8 @@ class TestMinitestAssertions < Minitest::Test
1065
1152
 
1066
1153
  non_verbose do
1067
1154
  out, err = capture_subprocess_io do
1068
- system("echo hi")
1069
- system("echo bye! 1>&2")
1155
+ system "echo hi"
1156
+ system "echo bye! 1>&2"
1070
1157
  end
1071
1158
 
1072
1159
  assert_equal "hi\n", out
@@ -1077,18 +1164,14 @@ class TestMinitestAssertions < Minitest::Test
1077
1164
  def test_class_asserts_match_refutes
1078
1165
  @assertion_count = 0
1079
1166
 
1080
- methods = Minitest::Assertions.public_instance_methods
1081
- methods.map!(&:to_s) if Symbol === methods.first
1167
+ methods = Minitest::Assertions.public_instance_methods.map(&:to_s)
1082
1168
 
1083
1169
  # These don't have corresponding refutes _on purpose_. They're
1084
1170
  # useless and will never be added, so don't bother.
1085
1171
  ignores = %w[assert_output assert_raises assert_send
1086
1172
  assert_silent assert_throws assert_mock]
1087
1173
 
1088
- # These are test/unit methods. I'm not actually sure why they're still here
1089
- ignores += %w[assert_no_match assert_not_equal assert_not_nil
1090
- assert_not_same assert_nothing_raised
1091
- assert_nothing_thrown assert_raise]
1174
+ ignores += %w[assert_allocations] # for minitest-gcstats
1092
1175
 
1093
1176
  asserts = methods.grep(/^assert/).sort - ignores
1094
1177
  refutes = methods.grep(/^refute/).sort - ignores
@@ -1298,6 +1381,56 @@ class TestMinitestAssertions < Minitest::Test
1298
1381
  end
1299
1382
  end
1300
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
+
1301
1434
  def test_refute_predicate
1302
1435
  @tc.refute_predicate "42", :empty?
1303
1436
  end
@@ -1318,6 +1451,16 @@ class TestMinitestAssertions < Minitest::Test
1318
1451
  end
1319
1452
  end
1320
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
+
1321
1464
  def test_refute_same
1322
1465
  @tc.refute_same 1, 2
1323
1466
  end
@@ -1356,7 +1499,7 @@ class TestMinitestAssertions < Minitest::Test
1356
1499
  d0 = Time.now
1357
1500
  d1 = d0 + 86_400 # I am an idiot
1358
1501
 
1359
- assert_output "", /Stale skip_until \"not yet\" at .*?:\d+$/ do
1502
+ assert_deprecation(/Stale skip_until \"not yet\" at .*?:\d+$/) do
1360
1503
  assert_skip_until d0, "not yet"
1361
1504
  end
1362
1505
 
@@ -1403,9 +1546,11 @@ class TestMinitestAssertionHelpers < Minitest::Test
1403
1546
  end
1404
1547
 
1405
1548
  def test_diff_equal
1406
- msg = "No visible difference in the String#inspect output.
1549
+ msg = <<~EOM.chomp
1550
+ No visible difference in the String#inspect output.
1407
1551
  You should look at the implementation of #== on String or its members.
1408
- \"blahblahblahblahblahblahblahblahblahblah\"".gsub(/^ +/, "")
1552
+ "blahblahblahblahblahblahblahblahblahblah"
1553
+ EOM
1409
1554
 
1410
1555
  o1 = "blah" * 10
1411
1556
  o2 = "blah" * 10
@@ -1417,7 +1562,7 @@ class TestMinitestAssertionHelpers < Minitest::Test
1417
1562
  end
1418
1563
 
1419
1564
  def test_diff_str_mixed
1420
- msg = <<-'EOM'.gsub(/^ {10}/, "") # NOTE single quotes on heredoc
1565
+ msg = <<~'EOM' # NOTE single quotes on heredoc
1421
1566
  --- expected
1422
1567
  +++ actual
1423
1568
  @@ -1 +1 @@
@@ -1432,7 +1577,7 @@ class TestMinitestAssertionHelpers < Minitest::Test
1432
1577
  end
1433
1578
 
1434
1579
  def test_diff_str_multiline
1435
- msg = <<-'EOM'.gsub(/^ {10}/, "") # NOTE single quotes on heredoc
1580
+ msg = <<~EOM
1436
1581
  --- expected
1437
1582
  +++ actual
1438
1583
  @@ -1,2 +1,2 @@
@@ -1448,7 +1593,7 @@ class TestMinitestAssertionHelpers < Minitest::Test
1448
1593
  end
1449
1594
 
1450
1595
  def test_diff_str_simple
1451
- msg = <<-'EOM'.gsub(/^ {10}/, "").chomp # NOTE single quotes on heredoc
1596
+ msg = <<~EOM.chomp
1452
1597
  Expected: "A"
1453
1598
  Actual: "B"
1454
1599
  EOM
@@ -1500,14 +1645,14 @@ class TestMinitestAssertionHelpers < Minitest::Test
1500
1645
  end
1501
1646
 
1502
1647
  def test_mu_pp_for_diff_str_bad_encoding
1503
- str = "\666".force_encoding Encoding::UTF_8
1648
+ str = "\666".dup.force_encoding Encoding::UTF_8
1504
1649
  exp = "# encoding: UTF-8\n# valid: false\n\"\\xB6\""
1505
1650
 
1506
1651
  assert_mu_pp_for_diff exp, str, :raw
1507
1652
  end
1508
1653
 
1509
1654
  def test_mu_pp_for_diff_str_bad_encoding_both
1510
- str = "\666A\\n\nB".force_encoding Encoding::UTF_8
1655
+ str = "\666A\\n\nB".dup.force_encoding Encoding::UTF_8
1511
1656
  exp = "# encoding: UTF-8\n# valid: false\n\"\\xB6A\\\\n\\nB\""
1512
1657
 
1513
1658
  assert_mu_pp_for_diff exp, str, :raw
@@ -1515,14 +1660,14 @@ class TestMinitestAssertionHelpers < Minitest::Test
1515
1660
 
1516
1661
  def test_mu_pp_for_diff_str_encoding
1517
1662
  str = "A\nB".b
1518
- exp = "# encoding: ASCII-8BIT\n# valid: true\n\"A\nB\""
1663
+ exp = "# encoding: #{Encoding::BINARY.name}\n# valid: true\n\"A\nB\""
1519
1664
 
1520
1665
  assert_mu_pp_for_diff exp, str, :raw
1521
1666
  end
1522
1667
 
1523
1668
  def test_mu_pp_for_diff_str_encoding_both
1524
1669
  str = "A\\n\nB".b
1525
- exp = "# encoding: ASCII-8BIT\n# valid: true\n\"A\\\\n\\nB\""
1670
+ exp = "# encoding: #{Encoding::BINARY.name}\n# valid: true\n\"A\\\\n\\nB\""
1526
1671
 
1527
1672
  assert_mu_pp_for_diff exp, str, :raw
1528
1673
  end
@@ -1554,7 +1699,7 @@ class TestMinitestAssertionHelpers < Minitest::Test
1554
1699
  end
1555
1700
 
1556
1701
  def test_mu_pp_str_bad_encoding
1557
- str = "\666".force_encoding Encoding::UTF_8
1702
+ str = "\666".dup.force_encoding Encoding::UTF_8
1558
1703
  exp = "# encoding: UTF-8\n# valid: false\n\"\\xB6\""
1559
1704
 
1560
1705
  assert_mu_pp exp, str, :raw
@@ -1562,7 +1707,7 @@ class TestMinitestAssertionHelpers < Minitest::Test
1562
1707
 
1563
1708
  def test_mu_pp_str_encoding
1564
1709
  str = "A\nB".b
1565
- exp = "# encoding: ASCII-8BIT\n# valid: true\n\"A\\nB\""
1710
+ exp = "# encoding: #{Encoding::BINARY.name}\n# valid: true\n\"A\\nB\""
1566
1711
 
1567
1712
  assert_mu_pp exp, str, :raw
1568
1713
  end