minitest 5.12.2 → 5.14.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -289,21 +289,28 @@ class Minitest::Spec < Minitest::Test
289
289
 
290
290
  module InstanceMethods
291
291
  ##
292
- # Returns a value monad that has all of Expectations methods
293
- # available to it.
292
+ # Takes a value or a block and returns a value monad that has
293
+ # all of Expectations methods available to it.
294
294
  #
295
- # Also aliased to #value and #expect for your aesthetic pleasure:
295
+ # _(1 + 1).must_equal 2
296
296
  #
297
- # _(1 + 1).must_equal 2
298
- # value(1 + 1).must_equal 2
299
- # expect(1 + 1).must_equal 2
297
+ # And for blocks:
298
+ #
299
+ # _ { 1 + "1" }.must_raise TypeError
300
300
  #
301
301
  # This method of expectation-based testing is preferable to
302
302
  # straight-expectation methods (on Object) because it stores its
303
303
  # test context, bypassing our hacky use of thread-local variables.
304
304
  #
305
- # At some point, the methods on Object will be deprecated and then
306
- # removed.
305
+ # NOTE: At some point, the methods on Object will be deprecated
306
+ # and then removed.
307
+ #
308
+ # It is also aliased to #value and #expect for your aesthetic
309
+ # pleasure:
310
+ #
311
+ # _(1 + 1).must_equal 2
312
+ # value(1 + 1).must_equal 2
313
+ # expect(1 + 1).must_equal 2
307
314
 
308
315
  def _ value = nil, &block
309
316
  Minitest::Expectation.new block || value, self
@@ -6,8 +6,27 @@ class Minitest::Test
6
6
  def clean s
7
7
  s.gsub(/^ {6}/, "")
8
8
  end
9
+
10
+ def with_empty_backtrace_filter
11
+ original = Minitest.backtrace_filter
12
+
13
+ obj = Minitest::BacktraceFilter.new
14
+ def obj.filter _bt
15
+ []
16
+ end
17
+
18
+ Minitest::Test.io_lock.synchronize do # try not to trounce in parallel
19
+ begin
20
+ Minitest.backtrace_filter = obj
21
+ yield
22
+ ensure
23
+ Minitest.backtrace_filter = original
24
+ end
25
+ end
26
+ end
9
27
  end
10
28
 
29
+
11
30
  class FakeNamedTest < Minitest::Test
12
31
  @@count = 0
13
32
 
@@ -25,6 +44,14 @@ class AnError < StandardError; include MyModule; end
25
44
  class MetaMetaMetaTestCase < Minitest::Test
26
45
  attr_accessor :reporter, :output, :tu
27
46
 
47
+ def with_stderr err
48
+ old = $stderr
49
+ $stderr = err
50
+ yield
51
+ ensure
52
+ $stderr = old
53
+ end
54
+
28
55
  def run_tu_with_fresh_reporter flags = %w[--seed 42]
29
56
  options = Minitest.process_args flags
30
57
 
@@ -34,18 +61,20 @@ class MetaMetaMetaTestCase < Minitest::Test
34
61
  reporter << Minitest::SummaryReporter.new(@output, options)
35
62
  reporter << Minitest::ProgressReporter.new(@output, options)
36
63
 
37
- reporter.start
64
+ with_stderr @output do
65
+ reporter.start
38
66
 
39
- yield(reporter) if block_given?
67
+ yield(reporter) if block_given?
40
68
 
41
- @tus ||= [@tu]
42
- @tus.each do |tu|
43
- Minitest::Runnable.runnables.delete tu
69
+ @tus ||= [@tu]
70
+ @tus.each do |tu|
71
+ Minitest::Runnable.runnables.delete tu
44
72
 
45
- tu.run reporter, options
46
- end
73
+ tu.run reporter, options
74
+ end
47
75
 
48
- reporter.report
76
+ reporter.report
77
+ end
49
78
  end
50
79
 
51
80
  def first_reporter
@@ -84,6 +113,8 @@ class MetaMetaMetaTestCase < Minitest::Test
84
113
  output.gsub!(/^(\s+)[^:]+:\d+:in/, '\1FILE:LINE:in')
85
114
  end
86
115
 
116
+ output.gsub!(/( at )[^:]+:\d+/, '\1[FILE:LINE]')
117
+
87
118
  output
88
119
  end
89
120
 
@@ -77,6 +77,14 @@ class TestMinitestAssertions < Minitest::Test
77
77
  self.send assert_msg, expected, msg
78
78
  end
79
79
 
80
+ def assert_unexpected expected
81
+ expected = Regexp.new expected if String === expected
82
+
83
+ assert_triggered expected, Minitest::UnexpectedError do
84
+ yield
85
+ end
86
+ end
87
+
80
88
  def clean s
81
89
  s.gsub(/^ {6,10}/, "")
82
90
  end
@@ -397,7 +405,7 @@ class TestMinitestAssertions < Minitest::Test
397
405
  end
398
406
 
399
407
  def test_assert_in_delta_triggered
400
- x = maglev? ? "9.999999xxxe-07" : "1.0e-06"
408
+ x = "1.0e-06"
401
409
  assert_triggered "Expected |0.0 - 0.001| (0.001) to be <= #{x}." do
402
410
  @tc.assert_in_delta 0.0, 1.0 / 1000, 0.000001
403
411
  end
@@ -428,7 +436,7 @@ class TestMinitestAssertions < Minitest::Test
428
436
 
429
437
  def test_assert_in_epsilon_triggered_negative_case
430
438
  x = (RUBY18 and not maglev?) ? "0.1" : "0.100000xxx"
431
- y = maglev? ? "0.100000xxx" : "0.1"
439
+ y = "0.1"
432
440
  assert_triggered "Expected |-1.1 - -1| (#{x}) to be <= #{y}." do
433
441
  @tc.assert_in_epsilon(-1.1, -1, 0.1)
434
442
  end
@@ -603,12 +611,117 @@ class TestMinitestAssertions < Minitest::Test
603
611
  end
604
612
  end
605
613
 
606
- def test_assert_output_without_block
614
+ def test_assert_output_no_block
607
615
  assert_triggered "assert_output requires a block to capture output." do
608
616
  @tc.assert_output "blah"
609
617
  end
610
618
  end
611
619
 
620
+ def test_assert_output_nested_assert_uncaught
621
+ @assertion_count = 1
622
+
623
+ assert_triggered "Epic Fail!" do
624
+ @tc.assert_output "blah\n" do
625
+ puts "blah"
626
+ @tc.flunk
627
+ end
628
+ end
629
+ end
630
+
631
+ def test_assert_output_nested_raise
632
+ @assertion_count = 2
633
+
634
+ @tc.assert_output "blah\n" do
635
+ @tc.assert_raises RuntimeError do
636
+ puts "blah"
637
+ raise "boom!"
638
+ end
639
+ end
640
+ end
641
+
642
+ def test_assert_output_nested_raise_bad
643
+ @assertion_count = 0
644
+
645
+ assert_unexpected "boom!" do
646
+ @tc.assert_raises do # 2) bypassed via UnexpectedError
647
+ @tc.assert_output "blah\n" do # 1) captures and raises UnexpectedError
648
+ puts "not_blah"
649
+ raise "boom!"
650
+ end
651
+ end
652
+ end
653
+ end
654
+
655
+ def test_assert_output_nested_raise_mismatch
656
+ # this test is redundant, but illustrative
657
+ @assertion_count = 0
658
+
659
+ assert_unexpected "boom!" do
660
+ @tc.assert_raises RuntimeError do # 2) bypassed via UnexpectedError
661
+ @tc.assert_output "blah\n" do # 1) captures and raises UnexpectedError
662
+ puts "not_blah"
663
+ raise ArgumentError, "boom!"
664
+ end
665
+ end
666
+ end
667
+ end
668
+
669
+ def test_assert_output_nested_throw_caught
670
+ @assertion_count = 2
671
+
672
+ @tc.assert_output "blah\n" do
673
+ @tc.assert_throws :boom! do
674
+ puts "blah"
675
+ throw :boom!
676
+ end
677
+ end
678
+ end
679
+
680
+ def test_assert_output_nested_throw_caught_bad
681
+ @assertion_count = 1 # want 0; can't prevent throw from escaping :(
682
+
683
+ @tc.assert_throws :boom! do # 2) captured via catch
684
+ @tc.assert_output "blah\n" do # 1) bypassed via throw
685
+ puts "not_blah"
686
+ throw :boom!
687
+ end
688
+ end
689
+ end
690
+
691
+ def test_assert_output_nested_throw_mismatch
692
+ @assertion_count = 0
693
+
694
+ assert_unexpected "uncaught throw :boom!" do
695
+ @tc.assert_throws :not_boom! do # 2) captured via assert_throws+rescue
696
+ @tc.assert_output "blah\n" do # 1) bypassed via throw
697
+ puts "not_blah"
698
+ throw :boom!
699
+ end
700
+ end
701
+ end
702
+ end
703
+
704
+ def test_assert_output_uncaught_raise
705
+ @assertion_count = 0
706
+
707
+ assert_unexpected "RuntimeError: boom!" do
708
+ @tc.assert_output "blah\n" do
709
+ puts "not_blah"
710
+ raise "boom!"
711
+ end
712
+ end
713
+ end
714
+
715
+ def test_assert_output_uncaught_throw
716
+ @assertion_count = 0
717
+
718
+ assert_unexpected "uncaught throw :boom!" do
719
+ @tc.assert_output "blah\n" do
720
+ puts "not_blah"
721
+ throw :boom!
722
+ end
723
+ end
724
+ end
612
725
  def test_assert_predicate
613
726
  @tc.assert_predicate "", :empty?
614
727
  end
@@ -671,6 +784,19 @@ class TestMinitestAssertions < Minitest::Test
671
784
  end
672
785
  end
673
786
 
787
+ def test_assert_raises_throw_nested_bad
788
+ @assertion_count = 0
789
+
790
+ assert_unexpected "RuntimeError: boom!" do
791
+ @tc.assert_raises do
792
+ @tc.assert_throws :blah do
793
+ raise "boom!"
794
+ throw :not_blah
795
+ end
796
+ end
797
+ end
798
+ end
799
+
674
800
  ##
675
801
  # *sigh* This is quite an odd scenario, but it is from real (albeit
676
802
  # ugly) test code in ruby-core:
@@ -875,7 +1001,9 @@ class TestMinitestAssertions < Minitest::Test
875
1001
  end
876
1002
 
877
1003
  def test_assert_throws_argument_exception
878
- @tc.assert_raises ArgumentError do
1004
+ @assertion_count = 0
1005
+
1006
+ assert_unexpected "ArgumentError" do
879
1007
  @tc.assert_throws :blah do
880
1008
  raise ArgumentError
881
1009
  end
@@ -891,7 +1019,9 @@ class TestMinitestAssertions < Minitest::Test
891
1019
  end
892
1020
 
893
1021
  def test_assert_throws_name_error
894
- @tc.assert_raises NameError do
1022
+ @assertion_count = 0
1023
+
1024
+ assert_unexpected "NameError" do
895
1025
  @tc.assert_throws :blah do
896
1026
  raise NameError
897
1027
  end
@@ -906,6 +1036,16 @@ class TestMinitestAssertions < Minitest::Test
906
1036
  end
907
1037
  end
908
1038
 
1039
+ def test_assert_path_exists
1040
+ @tc.assert_path_exists __FILE__
1041
+ end
1042
+
1043
+ def test_assert_path_exists_triggered
1044
+ assert_triggered "Expected path 'blah' to exist." do
1045
+ @tc.assert_path_exists "blah"
1046
+ end
1047
+ end
1048
+
909
1049
  def test_capture_io
910
1050
  @assertion_count = 0
911
1051
 
@@ -978,6 +1118,23 @@ class TestMinitestAssertions < Minitest::Test
978
1118
  end
979
1119
  end
980
1120
 
1121
+ def assert_fail_after t
1122
+ @tc.fail_after t.year, t.month, t.day, "remove the deprecations"
1123
+ end
1124
+
1125
+ def test_fail_after
1126
+ d0 = Time.now
1127
+ d1 = d0 + 86_400 # I am an idiot
1128
+
1129
+ assert_silent do
1130
+ assert_fail_after d1
1131
+ end
1132
+
1133
+ assert_triggered "remove the deprecations" do
1134
+ assert_fail_after d0
1135
+ end
1136
+ end
1137
+
981
1138
  def test_flunk
982
1139
  assert_triggered "Epic Fail!" do
983
1140
  @tc.flunk
@@ -997,7 +1154,7 @@ class TestMinitestAssertions < Minitest::Test
997
1154
  def test_refute
998
1155
  @assertion_count = 2
999
1156
 
1000
- @tc.assert_equal false, @tc.refute(false), "returns false on success"
1157
+ @tc.assert_equal true, @tc.refute(false), "returns true on success"
1001
1158
  end
1002
1159
 
1003
1160
  def test_refute_empty
@@ -1029,7 +1186,7 @@ class TestMinitestAssertions < Minitest::Test
1029
1186
  end
1030
1187
 
1031
1188
  def test_refute_in_delta_triggered
1032
- x = maglev? ? "0.100000xxx" : "0.1"
1189
+ x = "0.1"
1033
1190
  assert_triggered "Expected |0.0 - 0.001| (0.001) to not be <= #{x}." do
1034
1191
  @tc.refute_in_delta 0.0, 1.0 / 1000, 0.1
1035
1192
  end
@@ -1171,6 +1328,16 @@ class TestMinitestAssertions < Minitest::Test
1171
1328
  end
1172
1329
  end
1173
1330
 
1331
+ def test_refute_path_exists
1332
+ @tc.refute_path_exists "blah"
1333
+ end
1334
+
1335
+ def test_refute_path_exists_triggered
1336
+ assert_triggered "Expected path '#{__FILE__}' to not exist." do
1337
+ @tc.refute_path_exists __FILE__
1338
+ end
1339
+ end
1340
+
1174
1341
  def test_skip
1175
1342
  @assertion_count = 0
1176
1343
 
@@ -1179,6 +1346,25 @@ class TestMinitestAssertions < Minitest::Test
1179
1346
  end
1180
1347
  end
1181
1348
 
1349
+ def assert_skip_until t, msg
1350
+ @tc.skip_until t.year, t.month, t.day, msg
1351
+ end
1352
+
1353
+ def test_skip_until
1354
+ @assertion_count = 0
1355
+
1356
+ d0 = Time.now
1357
+ d1 = d0 + 86_400 # I am an idiot
1358
+
1359
+ assert_output "", /Stale skip_until \"not yet\" at .*?:\d+$/ do
1360
+ assert_skip_until d0, "not yet"
1361
+ end
1362
+
1363
+ assert_triggered "not ready yet", Minitest::Skip do
1364
+ assert_skip_until d1, "not ready yet"
1365
+ end
1366
+ end
1367
+
1182
1368
  def util_msg exp, act, msg = nil
1183
1369
  s = "Expected: #{exp.inspect}\n Actual: #{act.inspect}"
1184
1370
  s = "#{msg}.\n#{s}" if msg
@@ -64,8 +64,6 @@ class TestMinitestMock < Minitest::Test
64
64
  end
65
65
 
66
66
  def test_mock_args_does_not_raise
67
- skip "non-opaque use of ==" if maglev?
68
-
69
67
  arg = Minitest::Mock.new
70
68
  mock = Minitest::Mock.new
71
69
  mock.expect(:foo, nil, [arg])
@@ -26,9 +26,8 @@ describe Minitest::Spec do
26
26
 
27
27
  msg = e.message.sub(/(---Backtrace---).*/m, '\1')
28
28
  msg.gsub!(/\(oid=[-0-9]+\)/, "(oid=N)")
29
- msg.gsub!(/@.+>/, "@PATH>")
30
29
  msg.gsub!(/(\d\.\d{6})\d+/, '\1xxx') # normalize: ruby version, impl, platform
31
- msg.gsub!(/:0x[a-fA-F0-9]{4,}/m, ":0xXXXXXX")
30
+ msg.gsub!(/:0x[Xa-fA-F0-9]{4,}[ @].+?>/, ":0xXXXXXX@PATH>")
32
31
 
33
32
  if expected
34
33
  @assertion_count += 1
@@ -44,6 +43,10 @@ describe Minitest::Spec do
44
43
  end
45
44
  end
46
45
 
46
+ def assert_success spec
47
+ assert_equal true, spec
48
+ end
49
+
47
50
  before do
48
51
  @assertion_count = 4
49
52
  end
@@ -60,10 +63,30 @@ describe Minitest::Spec do
60
63
  end
61
64
  end
62
65
 
66
+ it "needs to check for file existence" do
67
+ @assertion_count = 3
68
+
69
+ assert_success _(__FILE__).path_must_exist
70
+
71
+ assert_triggered "Expected path 'blah' to exist." do
72
+ _("blah").path_must_exist
73
+ end
74
+ end
75
+
76
+ it "needs to check for file non-existence" do
77
+ @assertion_count = 3
78
+
79
+ assert_success _("blah").path_wont_exist
80
+
81
+ assert_triggered "Expected path '#{__FILE__}' to not exist." do
82
+ _(__FILE__).path_wont_exist
83
+ end
84
+ end
85
+
63
86
  it "needs to be sensible about must_include order" do
64
87
  @assertion_count += 3 # must_include is 2 assertions
65
88
 
66
- _(_([1, 2, 3]).must_include(2)).must_equal true
89
+ assert_success _([1, 2, 3]).must_include(2)
67
90
 
68
91
  assert_triggered "Expected [1, 2, 3] to include 5." do
69
92
  _([1, 2, 3]).must_include 5
@@ -77,7 +100,7 @@ describe Minitest::Spec do
77
100
  it "needs to be sensible about wont_include order" do
78
101
  @assertion_count += 3 # wont_include is 2 assertions
79
102
 
80
- _(_([1, 2, 3]).wont_include(5)).must_equal false
103
+ assert_success _([1, 2, 3]).wont_include(5)
81
104
 
82
105
  assert_triggered "Expected [1, 2, 3] to not include 2." do
83
106
  _([1, 2, 3]).wont_include 2
@@ -118,7 +141,7 @@ describe Minitest::Spec do
118
141
  @assertion_count -= 1 # no msg
119
142
  @assertion_count += 2 # assert_output is 2 assertions
120
143
 
121
- _(expect {}.must_be_silent).must_equal true
144
+ assert_success expect {}.must_be_silent
122
145
 
123
146
  assert_triggered "In stdout.\nExpected: \"\"\n Actual: \"xxx\"" do
124
147
  expect { print "xxx" }.must_be_silent
@@ -130,10 +153,10 @@ describe Minitest::Spec do
130
153
 
131
154
  @assertion_count = 2
132
155
 
133
- methods = Object.public_instance_methods.find_all { |n| n =~ /^must|^wont/ }
156
+ methods = Minitest::Expectations.public_instance_methods.grep(/must|wont/)
134
157
  methods.map!(&:to_s) if Symbol === methods.first
135
158
 
136
- musts, wonts = methods.sort.partition { |m| m =~ /^must/ }
159
+ musts, wonts = methods.sort.partition { |m| m =~ /must/ }
137
160
 
138
161
  expected_musts = %w[must_be
139
162
  must_be_close_to
@@ -151,11 +174,12 @@ describe Minitest::Spec do
151
174
  must_output
152
175
  must_raise
153
176
  must_respond_to
154
- must_throw]
177
+ must_throw
178
+ path_must_exist]
155
179
 
156
180
  bad = %w[not raise throw send output be_silent]
157
181
 
158
- expected_wonts = expected_musts.map { |m| m.sub(/^must/, "wont") }
182
+ expected_wonts = expected_musts.map { |m| m.sub(/must/, "wont") }.sort
159
183
  expected_wonts.reject! { |m| m =~ /wont_#{Regexp.union(*bad)}/ }
160
184
 
161
185
  _(musts).must_equal expected_musts
@@ -175,7 +199,7 @@ describe Minitest::Spec do
175
199
  end
176
200
 
177
201
  it "needs to verify binary messages" do
178
- _(_(42).wont_be(:<, 24)).must_equal false
202
+ assert_success _(42).wont_be(:<, 24)
179
203
 
180
204
  assert_triggered "Expected 24 to not be < 42." do
181
205
  _(24).wont_be :<, 42
@@ -189,7 +213,7 @@ describe Minitest::Spec do
189
213
  it "needs to verify emptyness" do
190
214
  @assertion_count += 3 # empty is 2 assertions
191
215
 
192
- _(_([]).must_be_empty).must_equal true
216
+ assert_success _([]).must_be_empty
193
217
 
194
218
  assert_triggered "Expected [42] to be empty." do
195
219
  _([42]).must_be_empty
@@ -203,7 +227,7 @@ describe Minitest::Spec do
203
227
  it "needs to verify equality" do
204
228
  @assertion_count += 1
205
229
 
206
- _(_(6 * 7).must_equal(42)).must_equal true
230
+ assert_success _(6 * 7).must_equal(42)
207
231
 
208
232
  assert_triggered "Expected: 42\n Actual: 54" do
209
233
  _(6 * 9).must_equal 42
@@ -213,7 +237,7 @@ describe Minitest::Spec do
213
237
  _(6 * 9).must_equal 42, "msg"
214
238
  end
215
239
 
216
- assert_triggered(/^-42\n\+#<Proc:0xXXXXXX@PATH>\n/) do
240
+ assert_triggered(/^-42\n\+#<Proc:0xXXXXXX[ @]PATH>\n/) do
217
241
  _(proc { 42 }).must_equal 42 # proc isn't called, so expectation fails
218
242
  end
219
243
  end
@@ -222,7 +246,7 @@ describe Minitest::Spec do
222
246
  @assertion_count += 1 # extra test
223
247
 
224
248
  out, err = capture_io do
225
- _(_(nil).must_equal(nil)).must_equal true
249
+ assert_success _(nil).must_equal(nil)
226
250
  end
227
251
 
228
252
  exp = "DEPRECATED: Use assert_nil if expecting nil from #{__FILE__}:#{__LINE__-3}. " \
@@ -236,13 +260,13 @@ describe Minitest::Spec do
236
260
  it "needs to verify floats outside a delta" do
237
261
  @assertion_count += 1 # extra test
238
262
 
239
- _(_(24).wont_be_close_to(42)).must_equal false
263
+ assert_success _(24).wont_be_close_to(42)
240
264
 
241
265
  assert_triggered "Expected |42 - 42.0| (0.0) to not be <= 0.001." do
242
266
  _(6 * 7.0).wont_be_close_to 42
243
267
  end
244
268
 
245
- x = maglev? ? "1.0000000000000001e-05" : "1.0e-05"
269
+ x = "1.0e-05"
246
270
  assert_triggered "Expected |42 - 42.0| (0.0) to not be <= #{x}." do
247
271
  _(6 * 7.0).wont_be_close_to 42, 0.00001
248
272
  end
@@ -255,14 +279,14 @@ describe Minitest::Spec do
255
279
  it "needs to verify floats outside an epsilon" do
256
280
  @assertion_count += 1 # extra test
257
281
 
258
- _(_(24).wont_be_within_epsilon(42)).must_equal false
282
+ assert_success _(24).wont_be_within_epsilon(42)
259
283
 
260
- x = maglev? ? "0.042000000000000003" : "0.042"
284
+ x = "0.042"
261
285
  assert_triggered "Expected |42 - 42.0| (0.0) to not be <= #{x}." do
262
286
  _(6 * 7.0).wont_be_within_epsilon 42
263
287
  end
264
288
 
265
- x = maglev? ? "0.00042000000000000002" : "0.00042"
289
+ x = "0.00042"
266
290
  assert_triggered "Expected |42 - 42.0| (0.0) to not be <= #{x}." do
267
291
  _(6 * 7.0).wont_be_within_epsilon 42, 0.00001
268
292
  end
@@ -275,13 +299,13 @@ describe Minitest::Spec do
275
299
  it "needs to verify floats within a delta" do
276
300
  @assertion_count += 1 # extra test
277
301
 
278
- _(_(6.0 * 7).must_be_close_to(42.0)).must_equal true
302
+ assert_success _(6.0 * 7).must_be_close_to(42.0)
279
303
 
280
304
  assert_triggered "Expected |0.0 - 0.01| (0.01) to be <= 0.001." do
281
305
  _(1.0 / 100).must_be_close_to 0.0
282
306
  end
283
307
 
284
- x = maglev? ? "9.9999999999999995e-07" : "1.0e-06"
308
+ x = "1.0e-06"
285
309
  assert_triggered "Expected |0.0 - 0.001| (0.001) to be <= #{x}." do
286
310
  _(1.0 / 1000).must_be_close_to 0.0, 0.000001
287
311
  end
@@ -294,7 +318,7 @@ describe Minitest::Spec do
294
318
  it "needs to verify floats within an epsilon" do
295
319
  @assertion_count += 1 # extra test
296
320
 
297
- _(_(6.0 * 7).must_be_within_epsilon(42.0)).must_equal true
321
+ assert_success _(6.0 * 7).must_be_within_epsilon(42.0)
298
322
 
299
323
  assert_triggered "Expected |0.0 - 0.01| (0.01) to be <= 0.0." do
300
324
  _(1.0 / 100).must_be_within_epsilon 0.0
@@ -310,7 +334,7 @@ describe Minitest::Spec do
310
334
  end
311
335
 
312
336
  it "needs to verify identity" do
313
- _(_(1).must_be_same_as(1)).must_equal true
337
+ assert_success _(1).must_be_same_as(1)
314
338
 
315
339
  assert_triggered "Expected 1 (oid=N) to be the same as 2 (oid=N)." do
316
340
  _(1).must_be_same_as 2
@@ -323,8 +347,8 @@ describe Minitest::Spec do
323
347
 
324
348
  it "needs to verify inequality" do
325
349
  @assertion_count += 2
326
- _(_(42).wont_equal(6 * 9)).must_equal false
327
- _(_(proc {}).wont_equal(42)).must_equal false
350
+ assert_success _(42).wont_equal(6 * 9)
351
+ assert_success _(proc {}).wont_equal(42)
328
352
 
329
353
  assert_triggered "Expected 1 to not be equal to 1." do
330
354
  _(1).wont_equal 1
@@ -336,7 +360,7 @@ describe Minitest::Spec do
336
360
  end
337
361
 
338
362
  it "needs to verify instances of a class" do
339
- _(_(42).wont_be_instance_of(String)).must_equal false
363
+ assert_success _(42).wont_be_instance_of(String)
340
364
 
341
365
  assert_triggered "Expected 42 to not be a kind of #{Int.name}." do
342
366
  _(42).wont_be_kind_of Int
@@ -350,8 +374,8 @@ describe Minitest::Spec do
350
374
  it "needs to verify kinds of a class" do
351
375
  @assertion_count += 2
352
376
 
353
- _(_(42).wont_be_kind_of(String)).must_equal false
354
- _(_(proc {}).wont_be_kind_of(String)).must_equal false
377
+ assert_success _(42).wont_be_kind_of(String)
378
+ assert_success _(proc {}).wont_be_kind_of(String)
355
379
 
356
380
  assert_triggered "Expected 42 to not be a kind of #{Int.name}." do
357
381
  _(42).wont_be_kind_of Int
@@ -365,8 +389,8 @@ describe Minitest::Spec do
365
389
  it "needs to verify kinds of objects" do
366
390
  @assertion_count += 3 # extra test
367
391
 
368
- _(_(6 * 7).must_be_kind_of(Int)).must_equal true
369
- _(_(6 * 7).must_be_kind_of(Numeric)).must_equal true
392
+ assert_success _(6 * 7).must_be_kind_of(Int)
393
+ assert_success _(6 * 7).must_be_kind_of(Numeric)
370
394
 
371
395
  assert_triggered "Expected 42 to be a kind of String, not #{Int.name}." do
372
396
  _(6 * 7).must_be_kind_of String
@@ -385,7 +409,7 @@ describe Minitest::Spec do
385
409
  it "needs to verify mismatch" do
386
410
  @assertion_count += 3 # match is 2
387
411
 
388
- _(_("blah").wont_match(/\d+/)).must_equal false
412
+ assert_success _("blah").wont_match(/\d+/)
389
413
 
390
414
  assert_triggered "Expected /\\w+/ to not match \"blah\"." do
391
415
  _("blah").wont_match(/\w+/)
@@ -397,7 +421,7 @@ describe Minitest::Spec do
397
421
  end
398
422
 
399
423
  it "needs to verify nil" do
400
- _(_(nil).must_be_nil).must_equal true
424
+ assert_success _(nil).must_be_nil
401
425
 
402
426
  assert_triggered "Expected 42 to be nil." do
403
427
  _(42).must_be_nil
@@ -411,7 +435,7 @@ describe Minitest::Spec do
411
435
  it "needs to verify non-emptyness" do
412
436
  @assertion_count += 3 # empty is 2 assertions
413
437
 
414
- _(_(["some item"]).wont_be_empty).must_equal false
438
+ assert_success _(["some item"]).wont_be_empty
415
439
 
416
440
  assert_triggered "Expected [] to not be empty." do
417
441
  _([]).wont_be_empty
@@ -423,7 +447,7 @@ describe Minitest::Spec do
423
447
  end
424
448
 
425
449
  it "needs to verify non-identity" do
426
- _(_(1).wont_be_same_as(2)).must_equal false
450
+ assert_success _(1).wont_be_same_as(2)
427
451
 
428
452
  assert_triggered "Expected 1 (oid=N) to not be the same as 1 (oid=N)." do
429
453
  _(1).wont_be_same_as 1
@@ -435,7 +459,7 @@ describe Minitest::Spec do
435
459
  end
436
460
 
437
461
  it "needs to verify non-nil" do
438
- _(_(42).wont_be_nil).must_equal false
462
+ assert_success _(42).wont_be_nil
439
463
 
440
464
  assert_triggered "Expected nil to not be nil." do
441
465
  _(nil).wont_be_nil
@@ -447,7 +471,7 @@ describe Minitest::Spec do
447
471
  end
448
472
 
449
473
  it "needs to verify objects not responding to a message" do
450
- _(_("").wont_respond_to(:woot!)).must_equal false
474
+ assert_success _("").wont_respond_to(:woot!)
451
475
 
452
476
  assert_triggered "Expected \"\" to not respond to to_s." do
453
477
  _("").wont_respond_to :to_s
@@ -461,7 +485,7 @@ describe Minitest::Spec do
461
485
  it "needs to verify output in stderr" do
462
486
  @assertion_count -= 1 # no msg
463
487
 
464
- _(expect { $stderr.print "blah" }.must_output(nil, "blah")).must_equal true
488
+ assert_success expect { $stderr.print "blah" }.must_output(nil, "blah")
465
489
 
466
490
  assert_triggered "In stderr.\nExpected: \"blah\"\n Actual: \"xxx\"" do
467
491
  expect { $stderr.print "xxx" }.must_output(nil, "blah")
@@ -471,7 +495,7 @@ describe Minitest::Spec do
471
495
  it "needs to verify output in stdout" do
472
496
  @assertion_count -= 1 # no msg
473
497
 
474
- _(expect { print "blah" }.must_output("blah")).must_equal true
498
+ assert_success expect { print "blah" }.must_output("blah")
475
499
 
476
500
  assert_triggered "In stdout.\nExpected: \"blah\"\n Actual: \"xxx\"" do
477
501
  expect { print "xxx" }.must_output("blah")
@@ -481,7 +505,7 @@ describe Minitest::Spec do
481
505
  it "needs to verify regexp matches" do
482
506
  @assertion_count += 3 # must_match is 2 assertions
483
507
 
484
- _(_("blah").must_match(/\w+/)).must_equal true
508
+ assert_success _("blah").must_match(/\w+/)
485
509
 
486
510
  assert_triggered "Expected /\\d+/ to match \"blah\"." do
487
511
  _("blah").must_match(/\d+/)
@@ -547,12 +571,28 @@ describe Minitest::Spec do
547
571
  (1 + 1).must_equal 2
548
572
  end
549
573
  end
574
+
575
+ # https://github.com/seattlerb/minitest/issues/837
576
+ # https://github.com/rails/rails/pull/39304
577
+ it "deprecates expectation used without _ with empty backtrace_filter" do
578
+ skip "N/A" if ENV["MT_NO_EXPECTATIONS"]
579
+
580
+ @assertion_count += 3
581
+
582
+ exp = /DEPRECATED: global use of must_equal from/
583
+
584
+ with_empty_backtrace_filter do
585
+ assert_output "", exp do
586
+ (1 + 1).must_equal 2
587
+ end
588
+ end
589
+ end
550
590
  end
551
591
 
552
592
  it "needs to verify throw" do
553
593
  @assertion_count += 2 # 2 extra tests
554
594
 
555
- _(expect { throw :blah }.must_throw(:blah)).must_equal true
595
+ assert_success expect { throw :blah }.must_throw(:blah)
556
596
 
557
597
  assert_triggered "Expected :blah to have been thrown." do
558
598
  expect {}.must_throw :blah
@@ -572,7 +612,7 @@ describe Minitest::Spec do
572
612
  end
573
613
 
574
614
  it "needs to verify types of objects" do
575
- _(_(6 * 7).must_be_instance_of(Int)).must_equal true
615
+ assert_success _(6 * 7).must_be_instance_of(Int)
576
616
 
577
617
  exp = "Expected 42 to be an instance of String, not #{Int.name}."
578
618
 
@@ -588,7 +628,7 @@ describe Minitest::Spec do
588
628
  it "needs to verify using any (negative) predicate" do
589
629
  @assertion_count -= 1 # doesn"t take a message
590
630
 
591
- _(_("blah").wont_be(:empty?)).must_equal false
631
+ assert_success _("blah").wont_be(:empty?)
592
632
 
593
633
  assert_triggered "Expected \"\" to not be empty?." do
594
634
  _("").wont_be :empty?
@@ -598,7 +638,7 @@ describe Minitest::Spec do
598
638
  it "needs to verify using any binary operator" do
599
639
  @assertion_count -= 1 # no msg
600
640
 
601
- _(_(41).must_be(:<, 42)).must_equal true
641
+ assert_success _(41).must_be(:<, 42)
602
642
 
603
643
  assert_triggered "Expected 42 to be < 41." do
604
644
  _(42).must_be(:<, 41)
@@ -608,7 +648,7 @@ describe Minitest::Spec do
608
648
  it "needs to verify using any predicate" do
609
649
  @assertion_count -= 1 # no msg
610
650
 
611
- _(_("").must_be(:empty?)).must_equal true
651
+ assert_success _("").must_be(:empty?)
612
652
 
613
653
  assert_triggered "Expected \"blah\" to be empty?." do
614
654
  _("blah").must_be :empty?
@@ -616,7 +656,7 @@ describe Minitest::Spec do
616
656
  end
617
657
 
618
658
  it "needs to verify using respond_to" do
619
- _(_(42).must_respond_to(:+)).must_equal true
659
+ assert_success _(42).must_respond_to(:+)
620
660
 
621
661
  assert_triggered "Expected 42 (#{Int.name}) to respond to #clear." do
622
662
  _(42).must_respond_to :clear