minitest 5.20.0 → 5.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +4 -4
- data/History.rdoc +206 -3
- data/Manifest.txt +3 -0
- data/README.rdoc +30 -17
- data/Rakefile +24 -2
- data/design_rationale.rb +21 -19
- data/lib/hoe/minitest.rb +4 -2
- data/lib/minitest/assertions.rb +92 -100
- data/lib/minitest/autorun.rb +4 -11
- data/lib/minitest/benchmark.rb +8 -11
- data/lib/minitest/compress.rb +94 -0
- data/lib/minitest/error_on_warning.rb +11 -0
- data/lib/minitest/expectations.rb +2 -2
- data/lib/minitest/hell.rb +1 -1
- data/lib/minitest/manual_plugins.rb +16 -0
- data/lib/minitest/mock.rb +44 -44
- data/lib/minitest/parallel.rb +7 -5
- data/lib/minitest/pride.rb +1 -1
- data/lib/minitest/pride_plugin.rb +17 -24
- data/lib/minitest/spec.rb +22 -18
- data/lib/minitest/test.rb +19 -29
- data/lib/minitest/test_task.rb +45 -23
- data/lib/minitest/unit.rb +1 -1
- data/lib/minitest.rb +289 -160
- data/test/minitest/metametameta.rb +32 -18
- data/test/minitest/test_minitest_assertions.rb +173 -197
- data/test/minitest/test_minitest_benchmark.rb +1 -1
- data/test/minitest/test_minitest_mock.rb +156 -89
- data/test/minitest/test_minitest_reporter.rb +120 -24
- data/test/minitest/test_minitest_spec.rb +95 -82
- data/test/minitest/test_minitest_test.rb +212 -120
- data/test/minitest/test_minitest_test_task.rb +18 -7
- data.tar.gz.sig +0 -0
- metadata +36 -22
- metadata.gz.sig +0 -0
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
# encoding: UTF-8
|
|
2
|
-
|
|
3
1
|
require "minitest/autorun"
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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,42 @@ class TestMinitestAssertions < Minitest::Test
|
|
|
144
125
|
end
|
|
145
126
|
|
|
146
127
|
def test_assert_equal_different_collection_array_hex_invisible
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
msg =
|
|
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>]
|
|
133
|
+
[#<Object:0xXXXXXX>]
|
|
134
|
+
EOM
|
|
152
135
|
assert_triggered msg do
|
|
153
|
-
@tc.assert_equal [
|
|
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
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
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
|
-
|
|
149
|
+
%p
|
|
150
|
+
EOM
|
|
164
151
|
|
|
165
152
|
assert_triggered msg do
|
|
166
|
-
@tc.assert_equal
|
|
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
|
-
|
|
174
|
-
|
|
160
|
+
exp = "haha" * 10
|
|
161
|
+
act = "blah" * 10
|
|
175
162
|
|
|
176
|
-
@tc.assert_equal
|
|
163
|
+
@tc.assert_equal exp, act
|
|
177
164
|
end
|
|
178
165
|
end
|
|
179
166
|
end
|
|
@@ -195,78 +182,84 @@ class TestMinitestAssertions < Minitest::Test
|
|
|
195
182
|
def initialize s; @name = s; end
|
|
196
183
|
end
|
|
197
184
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
msg =
|
|
185
|
+
exp = c.new "a"
|
|
186
|
+
act = c.new "b"
|
|
187
|
+
msg = <<~EOS
|
|
201
188
|
--- expected
|
|
202
189
|
+++ actual
|
|
203
190
|
@@ -1 +1 @@
|
|
204
|
-
-#<#<Class:0xXXXXXX>:0xXXXXXX @name
|
|
205
|
-
+#<#<Class:0xXXXXXX>:0xXXXXXX @name
|
|
191
|
+
-#<#<Class:0xXXXXXX>:0xXXXXXX @name="a">
|
|
192
|
+
+#<#<Class:0xXXXXXX>:0xXXXXXX @name="b">
|
|
206
193
|
EOS
|
|
207
194
|
|
|
208
195
|
assert_triggered msg do
|
|
209
|
-
@tc.assert_equal
|
|
196
|
+
@tc.assert_equal exp, act
|
|
210
197
|
end
|
|
211
198
|
end
|
|
212
199
|
|
|
213
200
|
def test_assert_equal_different_hex_invisible
|
|
214
|
-
|
|
215
|
-
|
|
201
|
+
exp = Object.new
|
|
202
|
+
act = Object.new
|
|
216
203
|
|
|
217
|
-
msg =
|
|
204
|
+
msg = <<~EOM.chomp
|
|
205
|
+
No visible difference in the Object#inspect output.
|
|
218
206
|
You should look at the implementation of #== on Object or its members.
|
|
219
|
-
#<Object:0xXXXXXX>
|
|
207
|
+
#<Object:0xXXXXXX>
|
|
208
|
+
EOM
|
|
220
209
|
|
|
221
210
|
assert_triggered msg do
|
|
222
|
-
@tc.assert_equal
|
|
211
|
+
@tc.assert_equal exp, act
|
|
223
212
|
end
|
|
224
213
|
end
|
|
225
214
|
|
|
226
215
|
def test_assert_equal_different_long
|
|
227
|
-
msg =
|
|
216
|
+
msg = <<~EOM
|
|
217
|
+
--- expected
|
|
228
218
|
+++ actual
|
|
229
219
|
@@ -1 +1 @@
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
220
|
+
-"hahahahahahahahahahahahahahahahahahahaha"
|
|
221
|
+
+"blahblahblahblahblahblahblahblahblahblah"
|
|
222
|
+
EOM
|
|
233
223
|
|
|
234
224
|
assert_triggered msg do
|
|
235
|
-
|
|
236
|
-
|
|
225
|
+
exp = "haha" * 10
|
|
226
|
+
act = "blah" * 10
|
|
237
227
|
|
|
238
|
-
@tc.assert_equal
|
|
228
|
+
@tc.assert_equal exp, act
|
|
239
229
|
end
|
|
240
230
|
end
|
|
241
231
|
|
|
242
232
|
def test_assert_equal_different_long_invisible
|
|
243
|
-
msg =
|
|
233
|
+
msg = <<~EOM.chomp
|
|
234
|
+
No visible difference in the String#inspect output.
|
|
244
235
|
You should look at the implementation of #== on String or its members.
|
|
245
|
-
|
|
236
|
+
"blahblahblahblahblahblahblahblahblahblah"
|
|
237
|
+
EOM
|
|
246
238
|
|
|
247
239
|
assert_triggered msg do
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
def
|
|
240
|
+
exp = "blah" * 10
|
|
241
|
+
act = "blah" * 10
|
|
242
|
+
def exp.== _
|
|
251
243
|
false
|
|
252
244
|
end
|
|
253
|
-
@tc.assert_equal
|
|
245
|
+
@tc.assert_equal exp, act
|
|
254
246
|
end
|
|
255
247
|
end
|
|
256
248
|
|
|
257
249
|
def test_assert_equal_different_long_msg
|
|
258
|
-
msg =
|
|
250
|
+
msg = <<~EOM
|
|
251
|
+
message.
|
|
259
252
|
--- expected
|
|
260
253
|
+++ actual
|
|
261
254
|
@@ -1 +1 @@
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
255
|
+
-"hahahahahahahahahahahahahahahahahahahaha"
|
|
256
|
+
+"blahblahblahblahblahblahblahblahblahblah"
|
|
257
|
+
EOM
|
|
265
258
|
|
|
266
259
|
assert_triggered msg do
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
@tc.assert_equal
|
|
260
|
+
exp = "haha" * 10
|
|
261
|
+
act = "blah" * 10
|
|
262
|
+
@tc.assert_equal exp, act, "message"
|
|
270
263
|
end
|
|
271
264
|
end
|
|
272
265
|
|
|
@@ -290,7 +283,7 @@ class TestMinitestAssertions < Minitest::Test
|
|
|
290
283
|
end
|
|
291
284
|
|
|
292
285
|
def test_assert_equal_does_not_allow_lhs_nil
|
|
293
|
-
if Minitest::VERSION
|
|
286
|
+
if Minitest::VERSION >= "6" then
|
|
294
287
|
warn "Time to strip the MT5 test"
|
|
295
288
|
|
|
296
289
|
@assertion_count += 1
|
|
@@ -298,10 +291,10 @@ class TestMinitestAssertions < Minitest::Test
|
|
|
298
291
|
@tc.assert_equal nil, nil
|
|
299
292
|
end
|
|
300
293
|
else
|
|
301
|
-
err_re =
|
|
294
|
+
err_re = /.*?test_minitest_\w+.rb:\d+: warning: DEPRECATED: Use assert_nil if expecting nil. This will fail in Minitest 6./
|
|
302
295
|
err_re = "" if $-w.nil?
|
|
303
296
|
|
|
304
|
-
|
|
297
|
+
assert_deprecation err_re do
|
|
305
298
|
@tc.assert_equal nil, nil
|
|
306
299
|
end
|
|
307
300
|
end
|
|
@@ -314,29 +307,23 @@ class TestMinitestAssertions < Minitest::Test
|
|
|
314
307
|
end
|
|
315
308
|
|
|
316
309
|
def test_assert_equal_string_bug791
|
|
317
|
-
exp =
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
-"\\n
|
|
322
|
-
-"
|
|
323
|
-
+"\\\"
|
|
324
|
-
EOF
|
|
325
|
-
|
|
326
|
-
exp = "Expected: \"\\\\n\"\n Actual: \"\\\\\""
|
|
310
|
+
exp = <<~EOM.chomp
|
|
311
|
+
Expected: "\\\\n"
|
|
312
|
+
Actual: "\\\\"
|
|
313
|
+
EOM
|
|
327
314
|
assert_triggered exp do
|
|
328
315
|
@tc.assert_equal "\\n", "\\"
|
|
329
316
|
end
|
|
330
317
|
end
|
|
331
318
|
|
|
332
319
|
def test_assert_equal_string_both_escaped_unescaped_newlines
|
|
333
|
-
msg =
|
|
320
|
+
msg = <<~'EOM' # NOTE: single quotes on heredoc
|
|
334
321
|
--- expected
|
|
335
322
|
+++ actual
|
|
336
323
|
@@ -1,2 +1 @@
|
|
337
|
-
|
|
338
|
-
-B
|
|
339
|
-
|
|
324
|
+
-"A\n
|
|
325
|
+
-B"
|
|
326
|
+
+"A\n\\nB"
|
|
340
327
|
EOM
|
|
341
328
|
|
|
342
329
|
assert_triggered msg do
|
|
@@ -348,7 +335,7 @@ class TestMinitestAssertions < Minitest::Test
|
|
|
348
335
|
end
|
|
349
336
|
|
|
350
337
|
def test_assert_equal_string_encodings
|
|
351
|
-
msg =
|
|
338
|
+
msg = <<~EOM
|
|
352
339
|
--- expected
|
|
353
340
|
+++ actual
|
|
354
341
|
@@ -1,3 +1,3 @@
|
|
@@ -360,14 +347,14 @@ class TestMinitestAssertions < Minitest::Test
|
|
|
360
347
|
EOM
|
|
361
348
|
|
|
362
349
|
assert_triggered msg do
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
@tc.assert_equal
|
|
350
|
+
exp = "bad-utf8-\xF1.txt"
|
|
351
|
+
act = exp.dup.b
|
|
352
|
+
@tc.assert_equal exp, act
|
|
366
353
|
end
|
|
367
|
-
end
|
|
354
|
+
end
|
|
368
355
|
|
|
369
356
|
def test_assert_equal_string_encodings_both_different
|
|
370
|
-
msg =
|
|
357
|
+
msg = <<~EOM
|
|
371
358
|
--- expected
|
|
372
359
|
+++ actual
|
|
373
360
|
@@ -1,3 +1,3 @@
|
|
@@ -379,14 +366,14 @@ class TestMinitestAssertions < Minitest::Test
|
|
|
379
366
|
EOM
|
|
380
367
|
|
|
381
368
|
assert_triggered msg do
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
@tc.assert_equal
|
|
369
|
+
exp = "bad-utf8-\xF1.txt".dup.force_encoding Encoding::ASCII
|
|
370
|
+
act = exp.dup.b
|
|
371
|
+
@tc.assert_equal exp, act
|
|
385
372
|
end
|
|
386
|
-
end
|
|
373
|
+
end
|
|
387
374
|
|
|
388
375
|
def test_assert_equal_unescape_newlines
|
|
389
|
-
msg =
|
|
376
|
+
msg = <<~'EOM' # NOTE single quotes on heredoc
|
|
390
377
|
--- expected
|
|
391
378
|
+++ actual
|
|
392
379
|
@@ -1,2 +1,2 @@
|
|
@@ -438,7 +425,7 @@ class TestMinitestAssertions < Minitest::Test
|
|
|
438
425
|
end
|
|
439
426
|
|
|
440
427
|
def test_assert_in_epsilon_triggered_negative_case
|
|
441
|
-
x =
|
|
428
|
+
x = "0.100000xxx"
|
|
442
429
|
y = "0.1"
|
|
443
430
|
assert_triggered "Expected |-1.1 - -1| (#{x}) to be <= #{y}." do
|
|
444
431
|
@tc.assert_in_epsilon(-1.1, -1, 0.1)
|
|
@@ -728,6 +715,7 @@ class TestMinitestAssertions < Minitest::Test
|
|
|
728
715
|
end
|
|
729
716
|
end
|
|
730
717
|
end
|
|
718
|
+
|
|
731
719
|
def test_assert_predicate
|
|
732
720
|
@tc.assert_predicate "", :empty?
|
|
733
721
|
end
|
|
@@ -757,17 +745,18 @@ class TestMinitestAssertions < Minitest::Test
|
|
|
757
745
|
end
|
|
758
746
|
end
|
|
759
747
|
|
|
760
|
-
expected =
|
|
748
|
+
expected = <<~EOM.chomp
|
|
761
749
|
[StandardError] exception expected, not
|
|
762
750
|
Class: <SomeError>
|
|
763
|
-
Message:
|
|
751
|
+
Message: <"blah">
|
|
764
752
|
---Backtrace---
|
|
765
|
-
FILE:LINE:in
|
|
753
|
+
FILE:LINE:in 'block in test_assert_raises_default_triggered'
|
|
766
754
|
---------------
|
|
767
755
|
EOM
|
|
768
756
|
|
|
769
757
|
actual = e.message.gsub(/^.+:\d+/, "FILE:LINE")
|
|
770
|
-
actual.gsub!
|
|
758
|
+
actual.gsub! RE_LEVELS, "" unless jruby?
|
|
759
|
+
actual.gsub!(/[`']block in (?:TestMinitestAssertions#)?/, "'block in ")
|
|
771
760
|
|
|
772
761
|
assert_equal expected, actual
|
|
773
762
|
end
|
|
@@ -836,17 +825,18 @@ class TestMinitestAssertions < Minitest::Test
|
|
|
836
825
|
end
|
|
837
826
|
end
|
|
838
827
|
|
|
839
|
-
expected =
|
|
828
|
+
expected = <<~EOM
|
|
840
829
|
[SomeError] exception expected, not
|
|
841
830
|
Class: <AnError>
|
|
842
|
-
Message:
|
|
831
|
+
Message: <"some message">
|
|
843
832
|
---Backtrace---
|
|
844
|
-
FILE:LINE:in
|
|
833
|
+
FILE:LINE:in 'block in test_assert_raises_subclass_triggered'
|
|
845
834
|
---------------
|
|
846
835
|
EOM
|
|
847
836
|
|
|
848
837
|
actual = e.message.gsub(/^.+:\d+/, "FILE:LINE")
|
|
849
|
-
actual.gsub!
|
|
838
|
+
actual.gsub! RE_LEVELS, "" unless jruby?
|
|
839
|
+
actual.gsub!(/[`']block in (?:TestMinitestAssertions#)?/, "'block in ")
|
|
850
840
|
|
|
851
841
|
assert_equal expected.chomp, actual
|
|
852
842
|
end
|
|
@@ -858,17 +848,18 @@ class TestMinitestAssertions < Minitest::Test
|
|
|
858
848
|
end
|
|
859
849
|
end
|
|
860
850
|
|
|
861
|
-
expected =
|
|
851
|
+
expected = <<~EOM.chomp
|
|
862
852
|
[RuntimeError] exception expected, not
|
|
863
853
|
Class: <SyntaxError>
|
|
864
|
-
Message:
|
|
854
|
+
Message: <"icky">
|
|
865
855
|
---Backtrace---
|
|
866
|
-
FILE:LINE:in
|
|
856
|
+
FILE:LINE:in 'block in test_assert_raises_triggered_different'
|
|
867
857
|
---------------
|
|
868
858
|
EOM
|
|
869
859
|
|
|
870
860
|
actual = e.message.gsub(/^.+:\d+/, "FILE:LINE")
|
|
871
|
-
actual.gsub!
|
|
861
|
+
actual.gsub! RE_LEVELS, "" unless jruby?
|
|
862
|
+
actual.gsub!(/[`']block in (?:TestMinitestAssertions#)?/, "'block in ")
|
|
872
863
|
|
|
873
864
|
assert_equal expected, actual
|
|
874
865
|
end
|
|
@@ -880,18 +871,19 @@ class TestMinitestAssertions < Minitest::Test
|
|
|
880
871
|
end
|
|
881
872
|
end
|
|
882
873
|
|
|
883
|
-
expected =
|
|
874
|
+
expected = <<~EOM
|
|
884
875
|
XXX.
|
|
885
876
|
[RuntimeError] exception expected, not
|
|
886
877
|
Class: <SyntaxError>
|
|
887
|
-
Message:
|
|
878
|
+
Message: <"icky">
|
|
888
879
|
---Backtrace---
|
|
889
|
-
FILE:LINE:in
|
|
880
|
+
FILE:LINE:in 'block in test_assert_raises_triggered_different_msg'
|
|
890
881
|
---------------
|
|
891
882
|
EOM
|
|
892
883
|
|
|
893
884
|
actual = e.message.gsub(/^.+:\d+/, "FILE:LINE")
|
|
894
|
-
actual.gsub!
|
|
885
|
+
actual.gsub! RE_LEVELS, "" unless jruby?
|
|
886
|
+
actual.gsub!(/[`']block in (?:TestMinitestAssertions#)?/, "'block in ")
|
|
895
887
|
|
|
896
888
|
assert_equal expected.chomp, actual
|
|
897
889
|
end
|
|
@@ -936,6 +928,16 @@ class TestMinitestAssertions < Minitest::Test
|
|
|
936
928
|
end
|
|
937
929
|
end
|
|
938
930
|
|
|
931
|
+
def test_assert_respond_to__include_all
|
|
932
|
+
@tc.assert_respond_to @tc, :exit, include_all: true
|
|
933
|
+
end
|
|
934
|
+
|
|
935
|
+
def test_assert_respond_to__include_all_triggered
|
|
936
|
+
assert_triggered(/Expected .+::DummyTest. to respond to #exit\?/) do
|
|
937
|
+
@tc.assert_respond_to @tc, :exit?, include_all: true
|
|
938
|
+
end
|
|
939
|
+
end
|
|
940
|
+
|
|
939
941
|
def test_assert_same
|
|
940
942
|
@assertion_count = 3
|
|
941
943
|
|
|
@@ -952,8 +954,8 @@ class TestMinitestAssertions < Minitest::Test
|
|
|
952
954
|
@tc.assert_same 1, 2
|
|
953
955
|
end
|
|
954
956
|
|
|
955
|
-
s1 = "blah"
|
|
956
|
-
s2 = "blah"
|
|
957
|
+
s1 = +"blah"
|
|
958
|
+
s2 = +"blah"
|
|
957
959
|
|
|
958
960
|
assert_triggered 'Expected "blah" (oid=N) to be the same as "blah" (oid=N).' do
|
|
959
961
|
@tc.assert_same s1, s2
|
|
@@ -961,16 +963,24 @@ class TestMinitestAssertions < Minitest::Test
|
|
|
961
963
|
end
|
|
962
964
|
|
|
963
965
|
def test_assert_send
|
|
964
|
-
|
|
966
|
+
@assertion_count = 0 if error_on_warn?
|
|
967
|
+
assert_deprecation(/DEPRECATED: assert_send/) do
|
|
965
968
|
@tc.assert_send [1, :<, 2]
|
|
966
969
|
end
|
|
967
970
|
end
|
|
968
971
|
|
|
969
972
|
def test_assert_send_bad
|
|
970
|
-
|
|
971
|
-
|
|
973
|
+
if error_on_warn? then
|
|
974
|
+
@assertion_count = 0
|
|
975
|
+
assert_deprecation(/DEPRECATED: assert_send/) do
|
|
972
976
|
@tc.assert_send [1, :>, 2]
|
|
973
977
|
end
|
|
978
|
+
else
|
|
979
|
+
assert_triggered "Expected 1.>(*[2]) to return true." do
|
|
980
|
+
assert_deprecation(/DEPRECATED: assert_send/) do
|
|
981
|
+
@tc.assert_send [1, :>, 2]
|
|
982
|
+
end
|
|
983
|
+
end
|
|
974
984
|
end
|
|
975
985
|
end
|
|
976
986
|
|
|
@@ -1063,48 +1073,24 @@ class TestMinitestAssertions < Minitest::Test
|
|
|
1063
1073
|
end
|
|
1064
1074
|
|
|
1065
1075
|
def test_assert_pattern
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
"(eval):1: warning: One-line pattern matching is experimental, and the behavior may change in future versions of Ruby!\n"
|
|
1070
|
-
else
|
|
1071
|
-
""
|
|
1072
|
-
end
|
|
1073
|
-
assert_output nil, exp do
|
|
1074
|
-
eval "[1,2,3] => [Integer, Integer, Integer]" # eval to escape parser for ruby<3
|
|
1075
|
-
end
|
|
1076
|
-
end
|
|
1077
|
-
else
|
|
1078
|
-
@assertion_count = 0
|
|
1079
|
-
|
|
1080
|
-
assert_raises NotImplementedError do
|
|
1081
|
-
@tc.assert_pattern do
|
|
1082
|
-
# do nothing
|
|
1083
|
-
end
|
|
1076
|
+
@tc.assert_pattern do
|
|
1077
|
+
assert_output nil, "" do
|
|
1078
|
+
[1,2,3] => [Integer, Integer, Integer]
|
|
1084
1079
|
end
|
|
1085
1080
|
end
|
|
1086
1081
|
end
|
|
1087
1082
|
|
|
1088
1083
|
def test_assert_pattern_traps_nomatchingpatternerror
|
|
1089
|
-
|
|
1090
|
-
exp = if RUBY_VERSION.start_with? "3.0" then
|
|
1091
|
-
"[1, 2, 3]" # terrible error message!
|
|
1092
|
-
else
|
|
1093
|
-
/length mismatch/
|
|
1094
|
-
end
|
|
1084
|
+
exp = /length mismatch/
|
|
1095
1085
|
|
|
1096
1086
|
assert_triggered exp do
|
|
1097
1087
|
@tc.assert_pattern do
|
|
1098
|
-
|
|
1099
|
-
eval "[1,2,3] => [Integer, Integer]" # eval to escape parser for ruby<3
|
|
1100
|
-
end
|
|
1088
|
+
[1,2,3] => [Integer, Integer]
|
|
1101
1089
|
end
|
|
1102
1090
|
end
|
|
1103
1091
|
end
|
|
1104
1092
|
|
|
1105
1093
|
def test_assert_pattern_raises_other_exceptions
|
|
1106
|
-
skip unless RUBY_VERSION >= "3.0"
|
|
1107
|
-
|
|
1108
1094
|
@assertion_count = 0
|
|
1109
1095
|
|
|
1110
1096
|
assert_raises RuntimeError do
|
|
@@ -1115,8 +1101,6 @@ class TestMinitestAssertions < Minitest::Test
|
|
|
1115
1101
|
end
|
|
1116
1102
|
|
|
1117
1103
|
def test_assert_pattern_with_no_block
|
|
1118
|
-
skip unless RUBY_VERSION >= "3.0"
|
|
1119
|
-
|
|
1120
1104
|
assert_triggered "assert_pattern requires a block to capture errors." do
|
|
1121
1105
|
@tc.assert_pattern
|
|
1122
1106
|
end
|
|
@@ -1141,8 +1125,8 @@ class TestMinitestAssertions < Minitest::Test
|
|
|
1141
1125
|
|
|
1142
1126
|
non_verbose do
|
|
1143
1127
|
out, err = capture_subprocess_io do
|
|
1144
|
-
system
|
|
1145
|
-
system
|
|
1128
|
+
system "echo hi"
|
|
1129
|
+
system "echo bye! 1>&2"
|
|
1146
1130
|
end
|
|
1147
1131
|
|
|
1148
1132
|
assert_equal "hi\n", out
|
|
@@ -1153,18 +1137,14 @@ class TestMinitestAssertions < Minitest::Test
|
|
|
1153
1137
|
def test_class_asserts_match_refutes
|
|
1154
1138
|
@assertion_count = 0
|
|
1155
1139
|
|
|
1156
|
-
methods = Minitest::Assertions.public_instance_methods
|
|
1157
|
-
methods.map!(&:to_s) if Symbol === methods.first
|
|
1140
|
+
methods = Minitest::Assertions.public_instance_methods.map(&:to_s)
|
|
1158
1141
|
|
|
1159
1142
|
# These don't have corresponding refutes _on purpose_. They're
|
|
1160
1143
|
# useless and will never be added, so don't bother.
|
|
1161
1144
|
ignores = %w[assert_output assert_raises assert_send
|
|
1162
1145
|
assert_silent assert_throws assert_mock]
|
|
1163
1146
|
|
|
1164
|
-
|
|
1165
|
-
ignores += %w[assert_no_match assert_not_equal assert_not_nil
|
|
1166
|
-
assert_not_same assert_nothing_raised
|
|
1167
|
-
assert_nothing_thrown assert_raise]
|
|
1147
|
+
ignores += %w[assert_allocations] # for minitest-gcstats
|
|
1168
1148
|
|
|
1169
1149
|
asserts = methods.grep(/^assert/).sort - ignores
|
|
1170
1150
|
refutes = methods.grep(/^refute/).sort - ignores
|
|
@@ -1273,12 +1253,16 @@ class TestMinitestAssertions < Minitest::Test
|
|
|
1273
1253
|
end
|
|
1274
1254
|
|
|
1275
1255
|
def test_refute_in_epsilon_triggered
|
|
1276
|
-
assert_triggered "Expected |10000 -
|
|
1277
|
-
@tc.refute_in_epsilon 10_000,
|
|
1256
|
+
assert_triggered "Expected |10000 - 9991| (9) to not be <= 9.991." do
|
|
1257
|
+
@tc.refute_in_epsilon 10_000, 9991
|
|
1278
1258
|
flunk
|
|
1279
1259
|
end
|
|
1280
1260
|
end
|
|
1281
1261
|
|
|
1262
|
+
def test_refute_in_epsilon_minimum
|
|
1263
|
+
@tc.refute_in_epsilon 10_000, 9990
|
|
1264
|
+
end
|
|
1265
|
+
|
|
1282
1266
|
def test_refute_includes
|
|
1283
1267
|
@assertion_count = 2
|
|
1284
1268
|
|
|
@@ -1375,38 +1359,20 @@ class TestMinitestAssertions < Minitest::Test
|
|
|
1375
1359
|
end
|
|
1376
1360
|
|
|
1377
1361
|
def test_refute_pattern
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
capture_io do # 3.0 is noisy
|
|
1381
|
-
eval "[1,2,3] => [Integer, Integer, String]"
|
|
1382
|
-
end
|
|
1383
|
-
end
|
|
1384
|
-
else
|
|
1385
|
-
@assertion_count = 0
|
|
1386
|
-
|
|
1387
|
-
assert_raises NotImplementedError do
|
|
1388
|
-
@tc.refute_pattern do
|
|
1389
|
-
eval "[1,2,3] => [Integer, Integer, String]"
|
|
1390
|
-
end
|
|
1391
|
-
end
|
|
1362
|
+
@tc.refute_pattern do
|
|
1363
|
+
[1,2,3] => [Integer, Integer, String]
|
|
1392
1364
|
end
|
|
1393
1365
|
end
|
|
1394
1366
|
|
|
1395
1367
|
def test_refute_pattern_expects_nomatchingpatternerror
|
|
1396
|
-
skip unless RUBY_VERSION > "3"
|
|
1397
|
-
|
|
1398
1368
|
assert_triggered(/NoMatchingPatternError expected, but nothing was raised./) do
|
|
1399
1369
|
@tc.refute_pattern do
|
|
1400
|
-
|
|
1401
|
-
eval "[1,2,3] => [Integer, Integer, Integer]"
|
|
1402
|
-
end
|
|
1370
|
+
[1,2,3] => [Integer, Integer, Integer]
|
|
1403
1371
|
end
|
|
1404
1372
|
end
|
|
1405
1373
|
end
|
|
1406
1374
|
|
|
1407
1375
|
def test_refute_pattern_raises_other_exceptions
|
|
1408
|
-
skip unless RUBY_VERSION >= "3.0"
|
|
1409
|
-
|
|
1410
1376
|
@assertion_count = 0
|
|
1411
1377
|
|
|
1412
1378
|
assert_raises RuntimeError do
|
|
@@ -1417,8 +1383,6 @@ class TestMinitestAssertions < Minitest::Test
|
|
|
1417
1383
|
end
|
|
1418
1384
|
|
|
1419
1385
|
def test_refute_pattern_with_no_block
|
|
1420
|
-
skip unless RUBY_VERSION >= "3.0"
|
|
1421
|
-
|
|
1422
1386
|
assert_triggered "refute_pattern requires a block to capture errors." do
|
|
1423
1387
|
@tc.refute_pattern
|
|
1424
1388
|
end
|
|
@@ -1444,6 +1408,16 @@ class TestMinitestAssertions < Minitest::Test
|
|
|
1444
1408
|
end
|
|
1445
1409
|
end
|
|
1446
1410
|
|
|
1411
|
+
def test_refute_respond_to__include_all
|
|
1412
|
+
@tc.refute_respond_to "blah", :missing, include_all: true
|
|
1413
|
+
end
|
|
1414
|
+
|
|
1415
|
+
def test_refute_respond_to__include_all_triggered
|
|
1416
|
+
assert_triggered(/Expected .*DummyTest.* to not respond to exit./) do
|
|
1417
|
+
@tc.refute_respond_to @tc, :exit, include_all: true
|
|
1418
|
+
end
|
|
1419
|
+
end
|
|
1420
|
+
|
|
1447
1421
|
def test_refute_same
|
|
1448
1422
|
@tc.refute_same 1, 2
|
|
1449
1423
|
end
|
|
@@ -1482,7 +1456,7 @@ class TestMinitestAssertions < Minitest::Test
|
|
|
1482
1456
|
d0 = Time.now
|
|
1483
1457
|
d1 = d0 + 86_400 # I am an idiot
|
|
1484
1458
|
|
|
1485
|
-
|
|
1459
|
+
assert_deprecation(/Stale skip_until \"not yet\" at .*?:\d+$/) do
|
|
1486
1460
|
assert_skip_until d0, "not yet"
|
|
1487
1461
|
end
|
|
1488
1462
|
|
|
@@ -1529,9 +1503,11 @@ class TestMinitestAssertionHelpers < Minitest::Test
|
|
|
1529
1503
|
end
|
|
1530
1504
|
|
|
1531
1505
|
def test_diff_equal
|
|
1532
|
-
msg =
|
|
1506
|
+
msg = <<~EOM.chomp
|
|
1507
|
+
No visible difference in the String#inspect output.
|
|
1533
1508
|
You should look at the implementation of #== on String or its members.
|
|
1534
|
-
|
|
1509
|
+
"blahblahblahblahblahblahblahblahblahblah"
|
|
1510
|
+
EOM
|
|
1535
1511
|
|
|
1536
1512
|
o1 = "blah" * 10
|
|
1537
1513
|
o2 = "blah" * 10
|
|
@@ -1543,7 +1519,7 @@ class TestMinitestAssertionHelpers < Minitest::Test
|
|
|
1543
1519
|
end
|
|
1544
1520
|
|
|
1545
1521
|
def test_diff_str_mixed
|
|
1546
|
-
msg =
|
|
1522
|
+
msg = <<~'EOM' # NOTE single quotes on heredoc
|
|
1547
1523
|
--- expected
|
|
1548
1524
|
+++ actual
|
|
1549
1525
|
@@ -1 +1 @@
|
|
@@ -1558,7 +1534,7 @@ class TestMinitestAssertionHelpers < Minitest::Test
|
|
|
1558
1534
|
end
|
|
1559
1535
|
|
|
1560
1536
|
def test_diff_str_multiline
|
|
1561
|
-
msg =
|
|
1537
|
+
msg = <<~EOM
|
|
1562
1538
|
--- expected
|
|
1563
1539
|
+++ actual
|
|
1564
1540
|
@@ -1,2 +1,2 @@
|
|
@@ -1574,7 +1550,7 @@ class TestMinitestAssertionHelpers < Minitest::Test
|
|
|
1574
1550
|
end
|
|
1575
1551
|
|
|
1576
1552
|
def test_diff_str_simple
|
|
1577
|
-
msg =
|
|
1553
|
+
msg = <<~EOM.chomp
|
|
1578
1554
|
Expected: "A"
|
|
1579
1555
|
Actual: "B"
|
|
1580
1556
|
EOM
|
|
@@ -1626,14 +1602,14 @@ class TestMinitestAssertionHelpers < Minitest::Test
|
|
|
1626
1602
|
end
|
|
1627
1603
|
|
|
1628
1604
|
def test_mu_pp_for_diff_str_bad_encoding
|
|
1629
|
-
str = "\666".force_encoding Encoding::UTF_8
|
|
1605
|
+
str = "\666".dup.force_encoding Encoding::UTF_8
|
|
1630
1606
|
exp = "# encoding: UTF-8\n# valid: false\n\"\\xB6\""
|
|
1631
1607
|
|
|
1632
1608
|
assert_mu_pp_for_diff exp, str, :raw
|
|
1633
1609
|
end
|
|
1634
1610
|
|
|
1635
1611
|
def test_mu_pp_for_diff_str_bad_encoding_both
|
|
1636
|
-
str = "\666A\\n\nB".force_encoding Encoding::UTF_8
|
|
1612
|
+
str = "\666A\\n\nB".dup.force_encoding Encoding::UTF_8
|
|
1637
1613
|
exp = "# encoding: UTF-8\n# valid: false\n\"\\xB6A\\\\n\\nB\""
|
|
1638
1614
|
|
|
1639
1615
|
assert_mu_pp_for_diff exp, str, :raw
|
|
@@ -1680,7 +1656,7 @@ class TestMinitestAssertionHelpers < Minitest::Test
|
|
|
1680
1656
|
end
|
|
1681
1657
|
|
|
1682
1658
|
def test_mu_pp_str_bad_encoding
|
|
1683
|
-
str = "\666".force_encoding Encoding::UTF_8
|
|
1659
|
+
str = "\666".dup.force_encoding Encoding::UTF_8
|
|
1684
1660
|
exp = "# encoding: UTF-8\n# valid: false\n\"\\xB6\""
|
|
1685
1661
|
|
|
1686
1662
|
assert_mu_pp exp, str, :raw
|