minitest 5.16.2 → 6.0.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.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/History.rdoc +373 -1
  4. data/Manifest.txt +16 -4
  5. data/README.rdoc +48 -118
  6. data/Rakefile +17 -2
  7. data/bin/minitest +5 -0
  8. data/design_rationale.rb +21 -19
  9. data/lib/hoe/minitest.rb +4 -2
  10. data/lib/minitest/assertions.rb +142 -124
  11. data/lib/minitest/autorun.rb +3 -11
  12. data/lib/minitest/benchmark.rb +9 -12
  13. data/lib/minitest/bisect.rb +304 -0
  14. data/lib/minitest/complete.rb +56 -0
  15. data/lib/minitest/compress.rb +94 -0
  16. data/lib/minitest/error_on_warning.rb +11 -0
  17. data/lib/minitest/expectations.rb +18 -0
  18. data/lib/minitest/find_minimal_combination.rb +127 -0
  19. data/lib/minitest/hell.rb +1 -1
  20. data/lib/minitest/manual_plugins.rb +4 -0
  21. data/lib/minitest/parallel.rb +10 -8
  22. data/lib/minitest/path_expander.rb +432 -0
  23. data/lib/minitest/pride.rb +2 -2
  24. data/lib/minitest/pride_plugin.rb +17 -24
  25. data/lib/minitest/server.rb +49 -0
  26. data/lib/minitest/server_plugin.rb +88 -0
  27. data/lib/minitest/spec.rb +27 -46
  28. data/lib/minitest/sprint.rb +105 -0
  29. data/lib/minitest/sprint_plugin.rb +39 -0
  30. data/lib/minitest/test.rb +32 -52
  31. data/lib/minitest/test_task.rb +68 -42
  32. data/lib/minitest.rb +361 -215
  33. data/test/minitest/metametameta.rb +33 -19
  34. data/test/minitest/test_bisect.rb +249 -0
  35. data/test/minitest/test_find_minimal_combination.rb +138 -0
  36. data/test/minitest/test_minitest_assertions.rb +311 -173
  37. data/test/minitest/test_minitest_benchmark.rb +15 -1
  38. data/test/minitest/test_minitest_reporter.rb +148 -23
  39. data/test/minitest/test_minitest_spec.rb +157 -132
  40. data/test/minitest/test_minitest_test.rb +270 -204
  41. data/test/minitest/test_minitest_test_task.rb +18 -7
  42. data/test/minitest/test_path_expander.rb +229 -0
  43. data/test/minitest/test_server.rb +146 -0
  44. data.tar.gz.sig +2 -2
  45. metadata +97 -37
  46. metadata.gz.sig +0 -0
  47. data/.autotest +0 -34
  48. data/lib/minitest/mock.rb +0 -323
  49. data/lib/minitest/unit.rb +0 -42
  50. data/test/minitest/test_minitest_mock.rb +0 -1139
@@ -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,48 +125,60 @@ 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
+ def act_obj.inspect = "#<Object:0xXXXXXX>"
146
+ msg = <<~EOM.chomp % [act]
147
+ No visible difference in the Hash#inspect output.
162
148
  You should look at the implementation of #== on Hash or its members.
163
- {1=>#<Object:0xXXXXXX>}".gsub(/^ +/, "")
149
+ %p
150
+ EOM
164
151
 
165
152
  assert_triggered msg do
166
- @tc.assert_equal h1, h2
153
+ @tc.assert_equal exp, act
167
154
  end
168
155
  end
169
156
 
170
157
  def test_assert_equal_different_diff_deactivated
171
158
  without_diff do
172
159
  assert_triggered util_msg("haha" * 10, "blah" * 10) do
173
- o1 = "haha" * 10
174
- o2 = "blah" * 10
160
+ exp = "haha" * 10
161
+ act = "blah" * 10
175
162
 
176
- @tc.assert_equal o1, o2
163
+ @tc.assert_equal exp, act
177
164
  end
178
165
  end
179
166
  end
180
167
 
181
- def test_assert_equal_different_message
168
+ def test_assert_equal_string_message
182
169
  assert_triggered "whoops.\nExpected: 1\n Actual: 2" do
170
+ @tc.assert_equal 1, 2, "whoops"
171
+ end
172
+ end
173
+
174
+ def test_assert_equal_different_message
175
+ assert_triggered "whoops." do
183
176
  @tc.assert_equal 1, 2, message { "whoops" }
184
177
  end
185
178
  end
186
179
 
187
180
  def test_assert_equal_different_lambda
188
- assert_triggered "whoops.\nExpected: 1\n Actual: 2" do
181
+ assert_triggered "whoops" do
189
182
  @tc.assert_equal 1, 2, lambda { "whoops" }
190
183
  end
191
184
  end
@@ -195,78 +188,84 @@ class TestMinitestAssertions < Minitest::Test
195
188
  def initialize s; @name = s; end
196
189
  end
197
190
 
198
- o1 = c.new "a"
199
- o2 = c.new "b"
200
- msg = clean <<-EOS
191
+ exp = c.new "a"
192
+ act = c.new "b"
193
+ msg = <<~EOS
201
194
  --- expected
202
195
  +++ actual
203
196
  @@ -1 +1 @@
204
- -#<#<Class:0xXXXXXX>:0xXXXXXX @name=\"a\">
205
- +#<#<Class:0xXXXXXX>:0xXXXXXX @name=\"b\">
197
+ -#<#<Class:0xXXXXXX>:0xXXXXXX @name="a">
198
+ +#<#<Class:0xXXXXXX>:0xXXXXXX @name="b">
206
199
  EOS
207
200
 
208
201
  assert_triggered msg do
209
- @tc.assert_equal o1, o2
202
+ @tc.assert_equal exp, act
210
203
  end
211
204
  end
212
205
 
213
206
  def test_assert_equal_different_hex_invisible
214
- o1 = Object.new
215
- o2 = Object.new
207
+ exp = Object.new
208
+ act = Object.new
216
209
 
217
- msg = "No visible difference in the Object#inspect output.
210
+ msg = <<~EOM.chomp
211
+ No visible difference in the Object#inspect output.
218
212
  You should look at the implementation of #== on Object or its members.
219
- #<Object:0xXXXXXX>".gsub(/^ +/, "")
213
+ #<Object:0xXXXXXX>
214
+ EOM
220
215
 
221
216
  assert_triggered msg do
222
- @tc.assert_equal o1, o2
217
+ @tc.assert_equal exp, act
223
218
  end
224
219
  end
225
220
 
226
221
  def test_assert_equal_different_long
227
- msg = "--- expected
222
+ msg = <<~EOM
223
+ --- expected
228
224
  +++ actual
229
225
  @@ -1 +1 @@
230
- -\"hahahahahahahahahahahahahahahahahahahaha\"
231
- +\"blahblahblahblahblahblahblahblahblahblah\"
232
- ".gsub(/^ +/, "")
226
+ -"hahahahahahahahahahahahahahahahahahahaha"
227
+ +"blahblahblahblahblahblahblahblahblahblah"
228
+ EOM
233
229
 
234
230
  assert_triggered msg do
235
- o1 = "haha" * 10
236
- o2 = "blah" * 10
231
+ exp = "haha" * 10
232
+ act = "blah" * 10
237
233
 
238
- @tc.assert_equal o1, o2
234
+ @tc.assert_equal exp, act
239
235
  end
240
236
  end
241
237
 
242
238
  def test_assert_equal_different_long_invisible
243
- msg = "No visible difference in the String#inspect output.
239
+ msg = <<~EOM.chomp
240
+ No visible difference in the String#inspect output.
244
241
  You should look at the implementation of #== on String or its members.
245
- \"blahblahblahblahblahblahblahblahblahblah\"".gsub(/^ +/, "")
242
+ "blahblahblahblahblahblahblahblahblahblah"
243
+ EOM
246
244
 
247
245
  assert_triggered msg do
248
- o1 = "blah" * 10
249
- o2 = "blah" * 10
250
- def o1.== _
246
+ exp = "blah" * 10
247
+ act = "blah" * 10
248
+ def exp.== _
251
249
  false
252
250
  end
253
- @tc.assert_equal o1, o2
251
+ @tc.assert_equal exp, act
254
252
  end
255
253
  end
256
254
 
257
255
  def test_assert_equal_different_long_msg
258
- msg = "message.
256
+ msg = <<~EOM
257
+ message.
259
258
  --- expected
260
259
  +++ actual
261
260
  @@ -1 +1 @@
262
- -\"hahahahahahahahahahahahahahahahahahahaha\"
263
- +\"blahblahblahblahblahblahblahblahblahblah\"
264
- ".gsub(/^ +/, "")
261
+ -"hahahahahahahahahahahahahahahahahahahaha"
262
+ +"blahblahblahblahblahblahblahblahblahblah"
263
+ EOM
265
264
 
266
265
  assert_triggered msg do
267
- o1 = "haha" * 10
268
- o2 = "blah" * 10
269
- @tc.assert_equal o1, o2, "message"
266
+ exp = "haha" * 10
267
+ act = "blah" * 10
268
+ @tc.assert_equal exp, act, "message"
270
269
  end
271
270
  end
272
271
 
@@ -290,53 +289,29 @@ class TestMinitestAssertions < Minitest::Test
290
289
  end
291
290
 
292
291
  def test_assert_equal_does_not_allow_lhs_nil
293
- if Minitest::VERSION =~ /^6/ then
294
- warn "Time to strip the MT5 test"
295
-
296
- @assertion_count += 1
297
- assert_triggered(/Use assert_nil if expecting nil/) do
298
- @tc.assert_equal nil, nil
299
- end
300
- else
301
- err_re = /Use assert_nil if expecting nil from .*test_minitest_\w+.rb/
302
- err_re = "" if $-w.nil?
303
-
304
- assert_output "", err_re do
305
- @tc.assert_equal nil, nil
306
- end
307
- end
308
- end
309
-
310
- def test_assert_equal_does_not_allow_lhs_nil_triggered
311
- assert_triggered "Expected: nil\n Actual: false" do
312
- @tc.assert_equal nil, false
292
+ assert_triggered(/Use assert_nil if expecting nil/) do
293
+ @tc.assert_equal nil, nil
313
294
  end
314
295
  end
315
296
 
316
297
  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: \"\\\\\""
298
+ exp = <<~EOM.chomp
299
+ Expected: "\\\\n"
300
+ Actual: "\\\\"
301
+ EOM
327
302
  assert_triggered exp do
328
303
  @tc.assert_equal "\\n", "\\"
329
304
  end
330
305
  end
331
306
 
332
307
  def test_assert_equal_string_both_escaped_unescaped_newlines
333
- msg = <<-EOM.gsub(/^ {10}/, "")
308
+ msg = <<~'EOM' # NOTE: single quotes on heredoc
334
309
  --- expected
335
310
  +++ actual
336
311
  @@ -1,2 +1 @@
337
- -\"A\\n
338
- -B\"
339
- +\"A\\n\\\\nB\"
312
+ -"A\n
313
+ -B"
314
+ +"A\n\\nB"
340
315
  EOM
341
316
 
342
317
  assert_triggered msg do
@@ -348,7 +323,7 @@ class TestMinitestAssertions < Minitest::Test
348
323
  end
349
324
 
350
325
  def test_assert_equal_string_encodings
351
- msg = <<-EOM.gsub(/^ {10}/, "")
326
+ msg = <<~EOM
352
327
  --- expected
353
328
  +++ actual
354
329
  @@ -1,3 +1,3 @@
@@ -360,14 +335,14 @@ class TestMinitestAssertions < Minitest::Test
360
335
  EOM
361
336
 
362
337
  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
338
+ exp = "bad-utf8-\xF1.txt"
339
+ act = exp.dup.b
340
+ @tc.assert_equal exp, act
366
341
  end
367
- end unless RUBY18
342
+ end
368
343
 
369
344
  def test_assert_equal_string_encodings_both_different
370
- msg = <<-EOM.gsub(/^ {10}/, "")
345
+ msg = <<~EOM
371
346
  --- expected
372
347
  +++ actual
373
348
  @@ -1,3 +1,3 @@
@@ -379,14 +354,14 @@ class TestMinitestAssertions < Minitest::Test
379
354
  EOM
380
355
 
381
356
  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
357
+ exp = "bad-utf8-\xF1.txt".dup.force_encoding Encoding::ASCII
358
+ act = exp.dup.b
359
+ @tc.assert_equal exp, act
385
360
  end
386
- end unless RUBY18
361
+ end
387
362
 
388
363
  def test_assert_equal_unescape_newlines
389
- msg = <<-'EOM'.gsub(/^ {10}/, "") # NOTE single quotes on heredoc
364
+ msg = <<~'EOM' # NOTE single quotes on heredoc
390
365
  --- expected
391
366
  +++ actual
392
367
  @@ -1,2 +1,2 @@
@@ -438,7 +413,7 @@ class TestMinitestAssertions < Minitest::Test
438
413
  end
439
414
 
440
415
  def test_assert_in_epsilon_triggered_negative_case
441
- x = (RUBY18 and not maglev?) ? "0.1" : "0.100000xxx"
416
+ x = "0.100000xxx"
442
417
  y = "0.1"
443
418
  assert_triggered "Expected |-1.1 - -1| (#{x}) to be <= #{y}." do
444
419
  @tc.assert_in_epsilon(-1.1, -1, 0.1)
@@ -538,10 +513,14 @@ class TestMinitestAssertions < Minitest::Test
538
513
  end
539
514
 
540
515
  def test_assert_operator
516
+ @assertion_count += 1
517
+
541
518
  @tc.assert_operator 2, :>, 1
542
519
  end
543
520
 
544
521
  def test_assert_operator_bad_object
522
+ @assertion_count += 1
523
+
545
524
  bad = Object.new
546
525
  def bad.== _; true end
547
526
 
@@ -549,6 +528,8 @@ class TestMinitestAssertions < Minitest::Test
549
528
  end
550
529
 
551
530
  def test_assert_operator_triggered
531
+ @assertion_count += 1
532
+
552
533
  assert_triggered "Expected 2 to be < 1." do
553
534
  @tc.assert_operator 2, :<, 1
554
535
  end
@@ -728,11 +709,16 @@ class TestMinitestAssertions < Minitest::Test
728
709
  end
729
710
  end
730
711
  end
712
+
731
713
  def test_assert_predicate
714
+ @assertion_count += 1
715
+
732
716
  @tc.assert_predicate "", :empty?
733
717
  end
734
718
 
735
719
  def test_assert_predicate_triggered
720
+ @assertion_count += 1
721
+
736
722
  assert_triggered 'Expected "blah" to be empty?.' do
737
723
  @tc.assert_predicate "blah", :empty?
738
724
  end
@@ -757,17 +743,18 @@ class TestMinitestAssertions < Minitest::Test
757
743
  end
758
744
  end
759
745
 
760
- expected = clean <<-EOM.chomp
746
+ expected = <<~EOM.chomp
761
747
  [StandardError] exception expected, not
762
748
  Class: <SomeError>
763
- Message: <\"blah\">
749
+ Message: <"blah">
764
750
  ---Backtrace---
765
- FILE:LINE:in \`block in test_assert_raises_default_triggered\'
751
+ FILE:LINE:in 'block in test_assert_raises_default_triggered'
766
752
  ---------------
767
753
  EOM
768
754
 
769
755
  actual = e.message.gsub(/^.+:\d+/, "FILE:LINE")
770
- actual.gsub!(RE_LEVELS, "") unless jruby?
756
+ actual.gsub! RE_LEVELS, "" unless jruby?
757
+ actual.gsub!(/[`']block in (?:TestMinitestAssertions#)?/, "'block in ")
771
758
 
772
759
  assert_equal expected, actual
773
760
  end
@@ -823,6 +810,66 @@ class TestMinitestAssertions < Minitest::Test
823
810
  end
824
811
  end
825
812
 
813
+ def test_assert_raises__string_msg
814
+ e = assert_raises Minitest::Assertion do
815
+ @tc.assert_raises RuntimeError, "assertion message" do
816
+ raise SomeError, "blah"
817
+ end
818
+ end
819
+
820
+ expected = <<~EOM.chomp
821
+ assertion message.
822
+ [RuntimeError] exception expected, not
823
+ Class: <SomeError>
824
+ Message: <"blah">
825
+ ---Backtrace---
826
+ FILE:LINE:in 'block in test_assert_raises__string_msg'
827
+ ---------------
828
+ EOM
829
+
830
+ actual = e.message.gsub(/^.+:\d+/, "FILE:LINE")
831
+ actual.gsub! RE_LEVELS, "" unless jruby?
832
+ actual.gsub!(/[`']block in (?:TestMinitestAssertions#)?/, "'block in ")
833
+
834
+ assert_equal expected, actual
835
+ end
836
+
837
+ def test_assert_raises__regexp_err
838
+ @assertion_count = 0
839
+
840
+ e = assert_raises TypeError do
841
+ @tc.assert_raises RuntimeError, %r%does not work%, "assertion message" do
842
+ raise SomeError, "blah"
843
+ end
844
+ end
845
+
846
+ expected = <<~EOM.chomp
847
+ class or module required for rescue clause. Got [RuntimeError, /does not work/]
848
+ EOM
849
+
850
+ actual = e.message
851
+
852
+ assert_equal expected, actual
853
+ end
854
+
855
+ def test_assert_raises__regexp_err_default
856
+ @assertion_count = 0
857
+
858
+ e = assert_raises TypeError do
859
+ @tc.assert_raises %r%does not work% do
860
+ raise "blah"
861
+ end
862
+ end
863
+
864
+ expected = <<~EOM.chomp
865
+ class or module required for rescue clause. Got [/does not work/]
866
+ EOM
867
+
868
+ actual = e.message
869
+
870
+ assert_equal expected, actual
871
+ end
872
+
826
873
  def test_assert_raises_subclass
827
874
  @tc.assert_raises StandardError do
828
875
  raise AnError
@@ -836,17 +883,18 @@ class TestMinitestAssertions < Minitest::Test
836
883
  end
837
884
  end
838
885
 
839
- expected = clean <<-EOM
886
+ expected = <<~EOM
840
887
  [SomeError] exception expected, not
841
888
  Class: <AnError>
842
- Message: <\"some message\">
889
+ Message: <"some message">
843
890
  ---Backtrace---
844
- FILE:LINE:in \`block in test_assert_raises_subclass_triggered\'
891
+ FILE:LINE:in 'block in test_assert_raises_subclass_triggered'
845
892
  ---------------
846
893
  EOM
847
894
 
848
895
  actual = e.message.gsub(/^.+:\d+/, "FILE:LINE")
849
- actual.gsub!(RE_LEVELS, "") unless jruby?
896
+ actual.gsub! RE_LEVELS, "" unless jruby?
897
+ actual.gsub!(/[`']block in (?:TestMinitestAssertions#)?/, "'block in ")
850
898
 
851
899
  assert_equal expected.chomp, actual
852
900
  end
@@ -858,17 +906,18 @@ class TestMinitestAssertions < Minitest::Test
858
906
  end
859
907
  end
860
908
 
861
- expected = clean <<-EOM.chomp
909
+ expected = <<~EOM.chomp
862
910
  [RuntimeError] exception expected, not
863
911
  Class: <SyntaxError>
864
- Message: <\"icky\">
912
+ Message: <"icky">
865
913
  ---Backtrace---
866
- FILE:LINE:in \`block in test_assert_raises_triggered_different\'
914
+ FILE:LINE:in 'block in test_assert_raises_triggered_different'
867
915
  ---------------
868
916
  EOM
869
917
 
870
918
  actual = e.message.gsub(/^.+:\d+/, "FILE:LINE")
871
- actual.gsub!(RE_LEVELS, "") unless jruby?
919
+ actual.gsub! RE_LEVELS, "" unless jruby?
920
+ actual.gsub!(/[`']block in (?:TestMinitestAssertions#)?/, "'block in ")
872
921
 
873
922
  assert_equal expected, actual
874
923
  end
@@ -880,18 +929,19 @@ class TestMinitestAssertions < Minitest::Test
880
929
  end
881
930
  end
882
931
 
883
- expected = clean <<-EOM
932
+ expected = <<~EOM
884
933
  XXX.
885
934
  [RuntimeError] exception expected, not
886
935
  Class: <SyntaxError>
887
- Message: <\"icky\">
936
+ Message: <"icky">
888
937
  ---Backtrace---
889
- FILE:LINE:in \`block in test_assert_raises_triggered_different_msg\'
938
+ FILE:LINE:in 'block in test_assert_raises_triggered_different_msg'
890
939
  ---------------
891
940
  EOM
892
941
 
893
942
  actual = e.message.gsub(/^.+:\d+/, "FILE:LINE")
894
- actual.gsub!(RE_LEVELS, "") unless jruby?
943
+ actual.gsub! RE_LEVELS, "" unless jruby?
944
+ actual.gsub!(/[`']block in (?:TestMinitestAssertions#)?/, "'block in ")
895
945
 
896
946
  assert_equal expected.chomp, actual
897
947
  end
@@ -936,6 +986,16 @@ class TestMinitestAssertions < Minitest::Test
936
986
  end
937
987
  end
938
988
 
989
+ def test_assert_respond_to__include_all
990
+ @tc.assert_respond_to @tc, :exit, include_all: true
991
+ end
992
+
993
+ def test_assert_respond_to__include_all_triggered
994
+ assert_triggered(/Expected .+::DummyTest. to respond to #exit\?/) do
995
+ @tc.assert_respond_to @tc, :exit?, include_all: true
996
+ end
997
+ end
998
+
939
999
  def test_assert_same
940
1000
  @assertion_count = 3
941
1001
 
@@ -952,25 +1012,17 @@ class TestMinitestAssertions < Minitest::Test
952
1012
  @tc.assert_same 1, 2
953
1013
  end
954
1014
 
955
- s1 = "blah"
956
- s2 = "blah"
1015
+ s1 = +"blah"
1016
+ s2 = +"blah"
957
1017
 
958
1018
  assert_triggered 'Expected "blah" (oid=N) to be the same as "blah" (oid=N).' do
959
1019
  @tc.assert_same s1, s2
960
1020
  end
961
1021
  end
962
1022
 
963
- def test_assert_send
964
- assert_deprecated :assert_send do
965
- @tc.assert_send [1, :<, 2]
966
- end
967
- end
968
-
969
- def test_assert_send_bad
970
- assert_deprecated :assert_send do
971
- assert_triggered "Expected 1.>(*[2]) to return true." do
972
- @tc.assert_send [1, :>, 2]
973
- end
1023
+ def test_assert_same__does_not_allow_lhs_nil
1024
+ assert_triggered(/Use assert_nil if expecting nil/) do
1025
+ @tc.assert_same nil, nil
974
1026
  end
975
1027
  end
976
1028
 
@@ -1062,6 +1114,40 @@ class TestMinitestAssertions < Minitest::Test
1062
1114
  end
1063
1115
  end
1064
1116
 
1117
+ def test_assert_pattern
1118
+ @tc.assert_pattern do
1119
+ assert_output nil, "" do
1120
+ [1,2,3] => [Integer, Integer, Integer]
1121
+ end
1122
+ end
1123
+ end
1124
+
1125
+ def test_assert_pattern_traps_nomatchingpatternerror
1126
+ exp = /length mismatch/
1127
+
1128
+ assert_triggered exp do
1129
+ @tc.assert_pattern do
1130
+ [1,2,3] => [Integer, Integer]
1131
+ end
1132
+ end
1133
+ end
1134
+
1135
+ def test_assert_pattern_raises_other_exceptions
1136
+ @assertion_count = 0
1137
+
1138
+ assert_raises RuntimeError do
1139
+ @tc.assert_pattern do
1140
+ raise "boom"
1141
+ end
1142
+ end
1143
+ end
1144
+
1145
+ def test_assert_pattern_with_no_block
1146
+ assert_triggered "assert_pattern requires a block to capture errors." do
1147
+ @tc.assert_pattern
1148
+ end
1149
+ end
1150
+
1065
1151
  def test_capture_io
1066
1152
  @assertion_count = 0
1067
1153
 
@@ -1081,8 +1167,8 @@ class TestMinitestAssertions < Minitest::Test
1081
1167
 
1082
1168
  non_verbose do
1083
1169
  out, err = capture_subprocess_io do
1084
- system("echo hi")
1085
- system("echo bye! 1>&2")
1170
+ system "echo hi"
1171
+ system "echo bye! 1>&2"
1086
1172
  end
1087
1173
 
1088
1174
  assert_equal "hi\n", out
@@ -1093,18 +1179,14 @@ class TestMinitestAssertions < Minitest::Test
1093
1179
  def test_class_asserts_match_refutes
1094
1180
  @assertion_count = 0
1095
1181
 
1096
- methods = Minitest::Assertions.public_instance_methods
1097
- methods.map!(&:to_s) if Symbol === methods.first
1182
+ methods = Minitest::Assertions.public_instance_methods.map(&:to_s)
1098
1183
 
1099
1184
  # These don't have corresponding refutes _on purpose_. They're
1100
1185
  # useless and will never be added, so don't bother.
1101
- ignores = %w[assert_output assert_raises assert_send
1186
+ ignores = %w[assert_output assert_raises
1102
1187
  assert_silent assert_throws assert_mock]
1103
1188
 
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]
1189
+ ignores += %w[assert_allocations] # for minitest-gcstats
1108
1190
 
1109
1191
  asserts = methods.grep(/^assert/).sort - ignores
1110
1192
  refutes = methods.grep(/^refute/).sort - ignores
@@ -1213,12 +1295,16 @@ class TestMinitestAssertions < Minitest::Test
1213
1295
  end
1214
1296
 
1215
1297
  def test_refute_in_epsilon_triggered
1216
- assert_triggered "Expected |10000 - 9990| (10) to not be <= 10.0." do
1217
- @tc.refute_in_epsilon 10_000, 9990
1298
+ assert_triggered "Expected |10000 - 9991| (9) to not be <= 9.991." do
1299
+ @tc.refute_in_epsilon 10_000, 9991
1218
1300
  flunk
1219
1301
  end
1220
1302
  end
1221
1303
 
1304
+ def test_refute_in_epsilon_minimum
1305
+ @tc.refute_in_epsilon 10_000, 9990
1306
+ end
1307
+
1222
1308
  def test_refute_includes
1223
1309
  @assertion_count = 2
1224
1310
 
@@ -1298,10 +1384,14 @@ class TestMinitestAssertions < Minitest::Test
1298
1384
  end
1299
1385
 
1300
1386
  def test_refute_operator
1387
+ @assertion_count += 1
1388
+
1301
1389
  @tc.refute_operator 2, :<, 1
1302
1390
  end
1303
1391
 
1304
1392
  def test_refute_operator_bad_object
1393
+ @assertion_count += 1
1394
+
1305
1395
  bad = Object.new
1306
1396
  def bad.== _; true end
1307
1397
 
@@ -1309,16 +1399,52 @@ class TestMinitestAssertions < Minitest::Test
1309
1399
  end
1310
1400
 
1311
1401
  def test_refute_operator_triggered
1402
+ @assertion_count += 1
1403
+
1312
1404
  assert_triggered "Expected 2 to not be > 1." do
1313
1405
  @tc.refute_operator 2, :>, 1
1314
1406
  end
1315
1407
  end
1316
1408
 
1409
+ def test_refute_pattern
1410
+ @tc.refute_pattern do
1411
+ [1,2,3] => [Integer, Integer, String]
1412
+ end
1413
+ end
1414
+
1415
+ def test_refute_pattern_expects_nomatchingpatternerror
1416
+ assert_triggered(/NoMatchingPatternError expected, but nothing was raised./) do
1417
+ @tc.refute_pattern do
1418
+ [1,2,3] => [Integer, Integer, Integer]
1419
+ end
1420
+ end
1421
+ end
1422
+
1423
+ def test_refute_pattern_raises_other_exceptions
1424
+ @assertion_count = 0
1425
+
1426
+ assert_raises RuntimeError do
1427
+ @tc.refute_pattern do
1428
+ raise "boom"
1429
+ end
1430
+ end
1431
+ end
1432
+
1433
+ def test_refute_pattern_with_no_block
1434
+ assert_triggered "refute_pattern requires a block to capture errors." do
1435
+ @tc.refute_pattern
1436
+ end
1437
+ end
1438
+
1317
1439
  def test_refute_predicate
1440
+ @assertion_count += 1
1441
+
1318
1442
  @tc.refute_predicate "42", :empty?
1319
1443
  end
1320
1444
 
1321
1445
  def test_refute_predicate_triggered
1446
+ @assertion_count += 1
1447
+
1322
1448
  assert_triggered 'Expected "" to not be empty?.' do
1323
1449
  @tc.refute_predicate "", :empty?
1324
1450
  end
@@ -1334,6 +1460,16 @@ class TestMinitestAssertions < Minitest::Test
1334
1460
  end
1335
1461
  end
1336
1462
 
1463
+ def test_refute_respond_to__include_all
1464
+ @tc.refute_respond_to "blah", :missing, include_all: true
1465
+ end
1466
+
1467
+ def test_refute_respond_to__include_all_triggered
1468
+ assert_triggered(/Expected .*DummyTest.* to not respond to exit./) do
1469
+ @tc.refute_respond_to @tc, :exit, include_all: true
1470
+ end
1471
+ end
1472
+
1337
1473
  def test_refute_same
1338
1474
  @tc.refute_same 1, 2
1339
1475
  end
@@ -1372,7 +1508,7 @@ class TestMinitestAssertions < Minitest::Test
1372
1508
  d0 = Time.now
1373
1509
  d1 = d0 + 86_400 # I am an idiot
1374
1510
 
1375
- assert_output "", /Stale skip_until \"not yet\" at .*?:\d+$/ do
1511
+ assert_deprecation(/Stale skip_until \"not yet\" at .*?:\d+$/) do
1376
1512
  assert_skip_until d0, "not yet"
1377
1513
  end
1378
1514
 
@@ -1419,9 +1555,11 @@ class TestMinitestAssertionHelpers < Minitest::Test
1419
1555
  end
1420
1556
 
1421
1557
  def test_diff_equal
1422
- msg = "No visible difference in the String#inspect output.
1558
+ msg = <<~EOM.chomp
1559
+ No visible difference in the String#inspect output.
1423
1560
  You should look at the implementation of #== on String or its members.
1424
- \"blahblahblahblahblahblahblahblahblahblah\"".gsub(/^ +/, "")
1561
+ "blahblahblahblahblahblahblahblahblahblah"
1562
+ EOM
1425
1563
 
1426
1564
  o1 = "blah" * 10
1427
1565
  o2 = "blah" * 10
@@ -1433,7 +1571,7 @@ class TestMinitestAssertionHelpers < Minitest::Test
1433
1571
  end
1434
1572
 
1435
1573
  def test_diff_str_mixed
1436
- msg = <<-'EOM'.gsub(/^ {10}/, "") # NOTE single quotes on heredoc
1574
+ msg = <<~'EOM' # NOTE single quotes on heredoc
1437
1575
  --- expected
1438
1576
  +++ actual
1439
1577
  @@ -1 +1 @@
@@ -1448,7 +1586,7 @@ class TestMinitestAssertionHelpers < Minitest::Test
1448
1586
  end
1449
1587
 
1450
1588
  def test_diff_str_multiline
1451
- msg = <<-'EOM'.gsub(/^ {10}/, "") # NOTE single quotes on heredoc
1589
+ msg = <<~EOM
1452
1590
  --- expected
1453
1591
  +++ actual
1454
1592
  @@ -1,2 +1,2 @@
@@ -1464,7 +1602,7 @@ class TestMinitestAssertionHelpers < Minitest::Test
1464
1602
  end
1465
1603
 
1466
1604
  def test_diff_str_simple
1467
- msg = <<-'EOM'.gsub(/^ {10}/, "").chomp # NOTE single quotes on heredoc
1605
+ msg = <<~EOM.chomp
1468
1606
  Expected: "A"
1469
1607
  Actual: "B"
1470
1608
  EOM
@@ -1482,10 +1620,10 @@ class TestMinitestAssertionHelpers < Minitest::Test
1482
1620
  assert_equal "blah1.\nblah2.", message("blah1") { "blah2" }.call
1483
1621
 
1484
1622
  message = proc { "blah1" }
1485
- assert_equal "blah1.\nblah2.", message(message) { "blah2" }.call
1623
+ assert_equal "blah1", message(message) { "blah2" }.call
1486
1624
 
1487
1625
  message = message { "blah1" }
1488
- assert_equal "blah1.\nblah2.", message(message) { "blah2" }.call
1626
+ assert_equal "blah1.", message(message) { "blah2" }.call
1489
1627
  end
1490
1628
 
1491
1629
  def test_message_deferred
@@ -1516,14 +1654,14 @@ class TestMinitestAssertionHelpers < Minitest::Test
1516
1654
  end
1517
1655
 
1518
1656
  def test_mu_pp_for_diff_str_bad_encoding
1519
- str = "\666".force_encoding Encoding::UTF_8
1657
+ str = "\666".dup.force_encoding Encoding::UTF_8
1520
1658
  exp = "# encoding: UTF-8\n# valid: false\n\"\\xB6\""
1521
1659
 
1522
1660
  assert_mu_pp_for_diff exp, str, :raw
1523
1661
  end
1524
1662
 
1525
1663
  def test_mu_pp_for_diff_str_bad_encoding_both
1526
- str = "\666A\\n\nB".force_encoding Encoding::UTF_8
1664
+ str = "\666A\\n\nB".dup.force_encoding Encoding::UTF_8
1527
1665
  exp = "# encoding: UTF-8\n# valid: false\n\"\\xB6A\\\\n\\nB\""
1528
1666
 
1529
1667
  assert_mu_pp_for_diff exp, str, :raw
@@ -1570,7 +1708,7 @@ class TestMinitestAssertionHelpers < Minitest::Test
1570
1708
  end
1571
1709
 
1572
1710
  def test_mu_pp_str_bad_encoding
1573
- str = "\666".force_encoding Encoding::UTF_8
1711
+ str = "\666".dup.force_encoding Encoding::UTF_8
1574
1712
  exp = "# encoding: UTF-8\n# valid: false\n\"\\xB6\""
1575
1713
 
1576
1714
  assert_mu_pp exp, str, :raw