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,8 +1,8 @@
|
|
|
1
1
|
require "minitest/autorun"
|
|
2
|
-
|
|
2
|
+
require_relative "metametameta"
|
|
3
3
|
require "forwardable"
|
|
4
4
|
|
|
5
|
-
class
|
|
5
|
+
class FakeTest < Minitest::Test
|
|
6
6
|
def woot
|
|
7
7
|
assert true
|
|
8
8
|
end
|
|
@@ -13,10 +13,6 @@ class TestMinitestReporter < MetaMetaMetaTestCase
|
|
|
13
13
|
attr_accessor :r, :io
|
|
14
14
|
|
|
15
15
|
def new_composite_reporter
|
|
16
|
-
# Ruby bug in older versions of 2.2 & 2.3 on all platforms
|
|
17
|
-
# Latest Windows builds were 2.2.6 and 2.3.3. Latest Ruby releases were
|
|
18
|
-
# 2.2.10 and 2.3.8.
|
|
19
|
-
skip if windows? && RUBY_VERSION < '2.4'
|
|
20
16
|
reporter = Minitest::CompositeReporter.new
|
|
21
17
|
reporter << Minitest::SummaryReporter.new(self.io)
|
|
22
18
|
reporter << Minitest::ProgressReporter.new(self.io)
|
|
@@ -31,13 +27,14 @@ class TestMinitestReporter < MetaMetaMetaTestCase
|
|
|
31
27
|
|
|
32
28
|
def setup
|
|
33
29
|
super
|
|
34
|
-
self.io = StringIO.new("")
|
|
30
|
+
self.io = StringIO.new(+"")
|
|
35
31
|
self.r = new_composite_reporter
|
|
32
|
+
@et = @ft = @pt = @st = @sse = nil
|
|
36
33
|
end
|
|
37
34
|
|
|
38
35
|
def error_test
|
|
39
|
-
unless
|
|
40
|
-
@et =
|
|
36
|
+
unless @et then
|
|
37
|
+
@et = FakeTest.new :woot
|
|
41
38
|
@et.failures << Minitest::UnexpectedError.new(begin
|
|
42
39
|
raise "no"
|
|
43
40
|
rescue => e
|
|
@@ -48,9 +45,28 @@ class TestMinitestReporter < MetaMetaMetaTestCase
|
|
|
48
45
|
@et
|
|
49
46
|
end
|
|
50
47
|
|
|
48
|
+
def system_stack_error_test
|
|
49
|
+
unless @sse then
|
|
50
|
+
|
|
51
|
+
ex = SystemStackError.new
|
|
52
|
+
|
|
53
|
+
pre = ("a".."c").to_a
|
|
54
|
+
mid = ("aa".."ad").to_a * 67
|
|
55
|
+
post = ("d".."f").to_a
|
|
56
|
+
ary = pre + mid + post
|
|
57
|
+
|
|
58
|
+
ex.set_backtrace ary
|
|
59
|
+
|
|
60
|
+
@sse = FakeTest.new :woot
|
|
61
|
+
@sse.failures << Minitest::UnexpectedError.new(ex)
|
|
62
|
+
@sse = Minitest::Result.from @sse
|
|
63
|
+
end
|
|
64
|
+
@sse
|
|
65
|
+
end
|
|
66
|
+
|
|
51
67
|
def fail_test
|
|
52
|
-
unless
|
|
53
|
-
@ft =
|
|
68
|
+
unless @ft then
|
|
69
|
+
@ft = FakeTest.new :woot
|
|
54
70
|
@ft.failures << begin
|
|
55
71
|
raise Minitest::Assertion, "boo"
|
|
56
72
|
rescue Minitest::Assertion => e
|
|
@@ -62,18 +78,18 @@ class TestMinitestReporter < MetaMetaMetaTestCase
|
|
|
62
78
|
end
|
|
63
79
|
|
|
64
80
|
def passing_test
|
|
65
|
-
@pt ||= Minitest::Result.from
|
|
81
|
+
@pt ||= Minitest::Result.from FakeTest.new(:woot)
|
|
66
82
|
end
|
|
67
83
|
|
|
68
84
|
def passing_test_with_metadata
|
|
69
|
-
test =
|
|
85
|
+
test = FakeTest.new :woot
|
|
70
86
|
test.metadata[:meta] = :data
|
|
71
87
|
@pt ||= Minitest::Result.from test
|
|
72
88
|
end
|
|
73
89
|
|
|
74
90
|
def skip_test
|
|
75
|
-
unless
|
|
76
|
-
@st =
|
|
91
|
+
unless @st then
|
|
92
|
+
@st = FakeTest.new :woot
|
|
77
93
|
@st.failures << begin
|
|
78
94
|
raise Minitest::Skip
|
|
79
95
|
rescue Minitest::Assertion => e
|
|
@@ -229,7 +245,7 @@ class TestMinitestReporter < MetaMetaMetaTestCase
|
|
|
229
245
|
r.start
|
|
230
246
|
r.report
|
|
231
247
|
|
|
232
|
-
exp =
|
|
248
|
+
exp = <<~EOM
|
|
233
249
|
Run options:
|
|
234
250
|
|
|
235
251
|
# Running:
|
|
@@ -249,7 +265,7 @@ class TestMinitestReporter < MetaMetaMetaTestCase
|
|
|
249
265
|
r.record passing_test
|
|
250
266
|
r.report
|
|
251
267
|
|
|
252
|
-
exp =
|
|
268
|
+
exp = <<~EOM
|
|
253
269
|
Run options:
|
|
254
270
|
|
|
255
271
|
# Running:
|
|
@@ -269,7 +285,7 @@ class TestMinitestReporter < MetaMetaMetaTestCase
|
|
|
269
285
|
r.record fail_test
|
|
270
286
|
r.report
|
|
271
287
|
|
|
272
|
-
exp =
|
|
288
|
+
exp = <<~EOM
|
|
273
289
|
Run options:
|
|
274
290
|
|
|
275
291
|
# Running:
|
|
@@ -279,7 +295,7 @@ class TestMinitestReporter < MetaMetaMetaTestCase
|
|
|
279
295
|
Finished in 0.00
|
|
280
296
|
|
|
281
297
|
1) Failure:
|
|
282
|
-
|
|
298
|
+
FakeTest#woot [FILE:LINE]:
|
|
283
299
|
boo
|
|
284
300
|
|
|
285
301
|
1 runs, 0 assertions, 1 failures, 0 errors, 0 skips
|
|
@@ -293,7 +309,7 @@ class TestMinitestReporter < MetaMetaMetaTestCase
|
|
|
293
309
|
r.record error_test
|
|
294
310
|
r.report
|
|
295
311
|
|
|
296
|
-
exp =
|
|
312
|
+
exp = <<~EOM
|
|
297
313
|
Run options:
|
|
298
314
|
|
|
299
315
|
# Running:
|
|
@@ -303,10 +319,46 @@ class TestMinitestReporter < MetaMetaMetaTestCase
|
|
|
303
319
|
Finished in 0.00
|
|
304
320
|
|
|
305
321
|
1) Error:
|
|
306
|
-
|
|
322
|
+
FakeTest#woot:
|
|
307
323
|
RuntimeError: no
|
|
308
|
-
FILE:LINE:in
|
|
309
|
-
FILE:LINE:in
|
|
324
|
+
FILE:LINE:in 'error_test'
|
|
325
|
+
FILE:LINE:in 'test_report_error'
|
|
326
|
+
|
|
327
|
+
1 runs, 0 assertions, 0 failures, 1 errors, 0 skips
|
|
328
|
+
EOM
|
|
329
|
+
|
|
330
|
+
assert_equal exp, normalize_output(io.string)
|
|
331
|
+
end
|
|
332
|
+
|
|
333
|
+
def test_report_error__sse
|
|
334
|
+
r.start
|
|
335
|
+
r.record system_stack_error_test
|
|
336
|
+
r.report
|
|
337
|
+
|
|
338
|
+
exp = <<~EOM
|
|
339
|
+
Run options:
|
|
340
|
+
|
|
341
|
+
# Running:
|
|
342
|
+
|
|
343
|
+
E
|
|
344
|
+
|
|
345
|
+
Finished in 0.00
|
|
346
|
+
|
|
347
|
+
1) Error:
|
|
348
|
+
FakeTest#woot:
|
|
349
|
+
SystemStackError: 274 -> 12
|
|
350
|
+
a
|
|
351
|
+
b
|
|
352
|
+
c
|
|
353
|
+
+->> 67 cycles of 4 lines:
|
|
354
|
+
| aa
|
|
355
|
+
| ab
|
|
356
|
+
| ac
|
|
357
|
+
| ad
|
|
358
|
+
+-<<
|
|
359
|
+
d
|
|
360
|
+
e
|
|
361
|
+
f
|
|
310
362
|
|
|
311
363
|
1 runs, 0 assertions, 0 failures, 1 errors, 0 skips
|
|
312
364
|
EOM
|
|
@@ -322,7 +374,7 @@ class TestMinitestReporter < MetaMetaMetaTestCase
|
|
|
322
374
|
r.report
|
|
323
375
|
end
|
|
324
376
|
|
|
325
|
-
exp =
|
|
377
|
+
exp = <<~EOM
|
|
326
378
|
Run options:
|
|
327
379
|
|
|
328
380
|
# Running:
|
|
@@ -338,4 +390,48 @@ class TestMinitestReporter < MetaMetaMetaTestCase
|
|
|
338
390
|
|
|
339
391
|
assert_equal exp, normalize_output(io.string)
|
|
340
392
|
end
|
|
393
|
+
|
|
394
|
+
def test_report_failure_uses_backtrace_filter
|
|
395
|
+
filter = Minitest::BacktraceFilter.new
|
|
396
|
+
def filter.filter _bt
|
|
397
|
+
["foo.rb:123:in 'foo'"]
|
|
398
|
+
end
|
|
399
|
+
|
|
400
|
+
with_backtrace_filter filter do
|
|
401
|
+
r.start
|
|
402
|
+
r.record fail_test
|
|
403
|
+
r.report
|
|
404
|
+
end
|
|
405
|
+
|
|
406
|
+
exp = "FakeTest#woot [foo.rb:123]"
|
|
407
|
+
|
|
408
|
+
assert_includes io.string, exp
|
|
409
|
+
end
|
|
410
|
+
|
|
411
|
+
def test_report_failure_uses_backtrace_filter_complex_sorbet
|
|
412
|
+
backtrace = <<~EOBT
|
|
413
|
+
/Users/user/.gem/ruby/3.2.2/gems/minitest-5.20.0/lib/minitest/assertions.rb:183:in 'assert'
|
|
414
|
+
example_test.rb:9:in 'assert_false'
|
|
415
|
+
/Users/user/.gem/ruby/3.2.2/gems/sorbet-runtime-0.5.11068/lib/types/private/methods/call_validation.rb:256:in 'bind_call'
|
|
416
|
+
/Users/user/.gem/ruby/3.2.2/gems/sorbet-runtime-0.5.11068/lib/types/private/methods/call_validation.rb:256:in 'validate_call'
|
|
417
|
+
/Users/user/.gem/ruby/3.2.2/gems/sorbet-runtime-0.5.11068/lib/types/private/methods/_methods.rb:275:in 'block in _on_method_added'
|
|
418
|
+
example_test.rb:25:in 'test_something'
|
|
419
|
+
/Users/user/.gem/ruby/3.2.2/gems/minitest-5.20.0/lib/minitest/test.rb:94:in 'block (3 levels) in run'
|
|
420
|
+
/Users/user/.gem/ruby/3.2.2/gems/minitest-5.20.0/lib/minitest/test.rb:191:in 'capture_exceptions'
|
|
421
|
+
/Users/user/.gem/ruby/3.2.2/gems/minitest-5.20.0/lib/minitest/test.rb:89:in 'block (2 levels) in run'
|
|
422
|
+
... so many lines ...
|
|
423
|
+
EOBT
|
|
424
|
+
|
|
425
|
+
filter = Minitest::BacktraceFilter.new %r%lib/minitest|gems/sorbet%
|
|
426
|
+
|
|
427
|
+
with_backtrace_filter filter do
|
|
428
|
+
begin
|
|
429
|
+
assert_equal 1, 2
|
|
430
|
+
rescue Minitest::Assertion => e
|
|
431
|
+
e.set_backtrace backtrace.lines.map(&:chomp)
|
|
432
|
+
|
|
433
|
+
assert_match "example_test.rb:25", e.location
|
|
434
|
+
end
|
|
435
|
+
end
|
|
436
|
+
end
|
|
341
437
|
end
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
require "minitest/metametameta"
|
|
1
|
+
require_relative "metametameta"
|
|
3
2
|
require "stringio"
|
|
4
3
|
|
|
5
4
|
class MiniSpecA < Minitest::Spec; end
|
|
@@ -12,15 +11,12 @@ class ExampleA; end
|
|
|
12
11
|
class ExampleB < ExampleA; end
|
|
13
12
|
|
|
14
13
|
describe Minitest::Spec do
|
|
15
|
-
# helps to deal with 2.4 deprecation of Fixnum for Integer
|
|
16
|
-
Int = 1.class
|
|
17
|
-
|
|
18
14
|
# do not parallelize this suite... it just can"t handle it.
|
|
19
15
|
|
|
20
16
|
def assert_triggered expected = "blah", klass = Minitest::Assertion
|
|
21
17
|
@assertion_count += 1
|
|
22
18
|
|
|
23
|
-
e = assert_raises
|
|
19
|
+
e = assert_raises klass do
|
|
24
20
|
yield
|
|
25
21
|
end
|
|
26
22
|
|
|
@@ -29,17 +25,17 @@ describe Minitest::Spec do
|
|
|
29
25
|
msg.gsub!(/(\d\.\d{6})\d+/, '\1xxx') # normalize: ruby version, impl, platform
|
|
30
26
|
msg.gsub!(/:0x[Xa-fA-F0-9]{4,}[ @].+?>/, ":0xXXXXXX@PATH>")
|
|
31
27
|
|
|
32
|
-
|
|
28
|
+
return unless expected
|
|
29
|
+
|
|
30
|
+
@assertion_count += 1
|
|
31
|
+
case expected
|
|
32
|
+
when String then
|
|
33
|
+
assert_equal expected, msg
|
|
34
|
+
when Regexp then
|
|
33
35
|
@assertion_count += 1
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
when Regexp then
|
|
38
|
-
@assertion_count += 1
|
|
39
|
-
assert_match expected, msg
|
|
40
|
-
else
|
|
41
|
-
flunk "Unknown: #{expected.inspect}"
|
|
42
|
-
end
|
|
36
|
+
assert_match expected, msg
|
|
37
|
+
else
|
|
38
|
+
flunk "Unknown: #{expected.inspect}"
|
|
43
39
|
end
|
|
44
40
|
end
|
|
45
41
|
|
|
@@ -112,7 +108,7 @@ describe Minitest::Spec do
|
|
|
112
108
|
end
|
|
113
109
|
|
|
114
110
|
it "needs to catch an expected exception" do
|
|
115
|
-
@assertion_count
|
|
111
|
+
@assertion_count -= 2
|
|
116
112
|
|
|
117
113
|
expect { raise "blah" }.must_raise RuntimeError
|
|
118
114
|
expect { raise Minitest::Assertion }.must_raise Minitest::Assertion
|
|
@@ -152,25 +148,13 @@ describe Minitest::Spec do
|
|
|
152
148
|
it "needs to pattern match" do
|
|
153
149
|
@assertion_count = 1
|
|
154
150
|
|
|
155
|
-
|
|
156
|
-
expect { good_pattern }.must_pattern_match
|
|
157
|
-
else
|
|
158
|
-
assert_raises NotImplementedError do
|
|
159
|
-
expect {}.must_pattern_match
|
|
160
|
-
end
|
|
161
|
-
end
|
|
151
|
+
expect { good_pattern }.must_pattern_match
|
|
162
152
|
end
|
|
163
153
|
|
|
164
154
|
it "needs to error on bad pattern match" do
|
|
165
|
-
skip unless RUBY_VERSION > "3"
|
|
166
|
-
|
|
167
155
|
@assertion_count = 1
|
|
168
156
|
|
|
169
|
-
exp =
|
|
170
|
-
"[1, 2, 3]" # terrible error message!
|
|
171
|
-
else
|
|
172
|
-
/length mismatch/
|
|
173
|
-
end
|
|
157
|
+
exp = /length mismatch/
|
|
174
158
|
|
|
175
159
|
assert_triggered exp do
|
|
176
160
|
expect { bad_pattern }.must_pattern_match
|
|
@@ -196,7 +180,7 @@ describe Minitest::Spec do
|
|
|
196
180
|
methods = Minitest::Expectations.public_instance_methods.grep(/must|wont/)
|
|
197
181
|
methods.map!(&:to_s) if Symbol === methods.first
|
|
198
182
|
|
|
199
|
-
musts, wonts = methods.sort.partition { |m| m
|
|
183
|
+
musts, wonts = methods.sort.partition { |m| m.include? "must" }
|
|
200
184
|
|
|
201
185
|
expected_musts = %w[must_be
|
|
202
186
|
must_be_close_to
|
|
@@ -216,11 +200,12 @@ describe Minitest::Spec do
|
|
|
216
200
|
must_raise
|
|
217
201
|
must_respond_to
|
|
218
202
|
must_throw
|
|
203
|
+
must_verify
|
|
219
204
|
path_must_exist]
|
|
220
205
|
|
|
221
|
-
bad = %w[not raise throw send output be_silent]
|
|
206
|
+
bad = %w[not raise throw send output be_silent verify]
|
|
222
207
|
|
|
223
|
-
expected_wonts = expected_musts.map { |m| m.sub(
|
|
208
|
+
expected_wonts = expected_musts.map { |m| m.sub("must", "wont") }.sort
|
|
224
209
|
expected_wonts.reject! { |m| m =~ /wont_#{Regexp.union(*bad)}/ }
|
|
225
210
|
|
|
226
211
|
_(musts).must_equal expected_musts
|
|
@@ -284,18 +269,14 @@ describe Minitest::Spec do
|
|
|
284
269
|
end
|
|
285
270
|
|
|
286
271
|
it "needs to warn on equality with nil" do
|
|
287
|
-
@assertion_count
|
|
272
|
+
@assertion_count = 3
|
|
273
|
+
@assertion_count += 2 unless error_on_warn? # 2 extra assertions
|
|
288
274
|
|
|
289
|
-
|
|
275
|
+
exp = /.*?test_minitest_\w+.rb:\d+: warning: DEPRECATED: Use assert_nil if expecting nil. This will fail in Minitest 6./
|
|
276
|
+
|
|
277
|
+
assert_deprecation exp do
|
|
290
278
|
assert_success _(nil).must_equal(nil)
|
|
291
279
|
end
|
|
292
|
-
|
|
293
|
-
exp = "DEPRECATED: Use assert_nil if expecting nil from #{__FILE__}:#{__LINE__-3}. " \
|
|
294
|
-
"This will fail in Minitest 6.\n"
|
|
295
|
-
exp = "" if $-w.nil?
|
|
296
|
-
|
|
297
|
-
assert_empty out
|
|
298
|
-
assert_equal exp, err
|
|
299
280
|
end
|
|
300
281
|
|
|
301
282
|
it "needs to verify floats outside a delta" do
|
|
@@ -403,12 +384,12 @@ describe Minitest::Spec do
|
|
|
403
384
|
it "needs to verify instances of a class" do
|
|
404
385
|
assert_success _(42).wont_be_instance_of(String)
|
|
405
386
|
|
|
406
|
-
assert_triggered "Expected 42 to not be a kind of
|
|
407
|
-
_(42).wont_be_kind_of
|
|
387
|
+
assert_triggered "Expected 42 to not be a kind of Integer." do
|
|
388
|
+
_(42).wont_be_kind_of Integer
|
|
408
389
|
end
|
|
409
390
|
|
|
410
|
-
assert_triggered "msg.\nExpected 42 to not be an instance of
|
|
411
|
-
_(42).wont_be_instance_of
|
|
391
|
+
assert_triggered "msg.\nExpected 42 to not be an instance of Integer." do
|
|
392
|
+
_(42).wont_be_instance_of Integer, "msg"
|
|
412
393
|
end
|
|
413
394
|
end
|
|
414
395
|
|
|
@@ -418,26 +399,26 @@ describe Minitest::Spec do
|
|
|
418
399
|
assert_success _(42).wont_be_kind_of(String)
|
|
419
400
|
assert_success _(proc {}).wont_be_kind_of(String)
|
|
420
401
|
|
|
421
|
-
assert_triggered "Expected 42 to not be a kind of
|
|
422
|
-
_(42).wont_be_kind_of
|
|
402
|
+
assert_triggered "Expected 42 to not be a kind of Integer." do
|
|
403
|
+
_(42).wont_be_kind_of Integer
|
|
423
404
|
end
|
|
424
405
|
|
|
425
|
-
assert_triggered "msg.\nExpected 42 to not be a kind of
|
|
426
|
-
_(42).wont_be_kind_of
|
|
406
|
+
assert_triggered "msg.\nExpected 42 to not be a kind of Integer." do
|
|
407
|
+
_(42).wont_be_kind_of Integer, "msg"
|
|
427
408
|
end
|
|
428
409
|
end
|
|
429
410
|
|
|
430
411
|
it "needs to verify kinds of objects" do
|
|
431
412
|
@assertion_count += 3 # extra test
|
|
432
413
|
|
|
433
|
-
assert_success _(6 * 7).must_be_kind_of(
|
|
414
|
+
assert_success _(6 * 7).must_be_kind_of(Integer)
|
|
434
415
|
assert_success _(6 * 7).must_be_kind_of(Numeric)
|
|
435
416
|
|
|
436
|
-
assert_triggered "Expected 42 to be a kind of String, not
|
|
417
|
+
assert_triggered "Expected 42 to be a kind of String, not Integer." do
|
|
437
418
|
_(6 * 7).must_be_kind_of String
|
|
438
419
|
end
|
|
439
420
|
|
|
440
|
-
assert_triggered "msg.\nExpected 42 to be a kind of String, not
|
|
421
|
+
assert_triggered "msg.\nExpected 42 to be a kind of String, not Integer." do
|
|
441
422
|
_(6 * 7).must_be_kind_of String, "msg"
|
|
442
423
|
end
|
|
443
424
|
|
|
@@ -576,7 +557,8 @@ describe Minitest::Spec do
|
|
|
576
557
|
|
|
577
558
|
it "can NOT use must_equal in a thread. It must use expect in a thread" do
|
|
578
559
|
skip "N/A" if ENV["MT_NO_EXPECTATIONS"]
|
|
579
|
-
|
|
560
|
+
|
|
561
|
+
assert_raises RuntimeError, Minitest::UnexpectedWarning do
|
|
580
562
|
capture_io do
|
|
581
563
|
Thread.new { (1 + 1).must_equal 2 }.join
|
|
582
564
|
end
|
|
@@ -586,29 +568,33 @@ describe Minitest::Spec do
|
|
|
586
568
|
it "fails gracefully when expectation used outside of `it`" do
|
|
587
569
|
skip "N/A" if ENV["MT_NO_EXPECTATIONS"]
|
|
588
570
|
|
|
589
|
-
@assertion_count +=
|
|
571
|
+
@assertion_count += 2 # assert_match is compound
|
|
590
572
|
|
|
591
|
-
e = assert_raises RuntimeError do
|
|
573
|
+
e = assert_raises RuntimeError, Minitest::UnexpectedWarning do
|
|
592
574
|
capture_io do
|
|
593
575
|
Thread.new { # forces ctx to be nil
|
|
594
|
-
describe
|
|
576
|
+
describe "woot" do
|
|
595
577
|
(1 + 1).must_equal 2
|
|
596
578
|
end
|
|
597
579
|
}.join
|
|
598
580
|
end
|
|
599
581
|
end
|
|
600
582
|
|
|
601
|
-
|
|
583
|
+
exp = "Calling #must_equal outside of test."
|
|
584
|
+
exp = "DEPRECATED: global use of must_equal from" if error_on_warn?
|
|
585
|
+
|
|
586
|
+
assert_match exp, e.message
|
|
602
587
|
end
|
|
603
588
|
|
|
604
589
|
it "deprecates expectation used without _" do
|
|
605
590
|
skip "N/A" if ENV["MT_NO_EXPECTATIONS"]
|
|
606
591
|
|
|
607
|
-
@assertion_count +=
|
|
592
|
+
@assertion_count += 1
|
|
593
|
+
@assertion_count += 2 unless error_on_warn?
|
|
608
594
|
|
|
609
595
|
exp = /DEPRECATED: global use of must_equal from/
|
|
610
596
|
|
|
611
|
-
|
|
597
|
+
assert_deprecation exp do
|
|
612
598
|
(1 + 1).must_equal 2
|
|
613
599
|
end
|
|
614
600
|
end
|
|
@@ -618,12 +604,13 @@ describe Minitest::Spec do
|
|
|
618
604
|
it "deprecates expectation used without _ with empty backtrace_filter" do
|
|
619
605
|
skip "N/A" if ENV["MT_NO_EXPECTATIONS"]
|
|
620
606
|
|
|
621
|
-
@assertion_count +=
|
|
607
|
+
@assertion_count += 1
|
|
608
|
+
@assertion_count += 2 unless error_on_warn?
|
|
622
609
|
|
|
623
610
|
exp = /DEPRECATED: global use of must_equal from/
|
|
624
611
|
|
|
625
612
|
with_empty_backtrace_filter do
|
|
626
|
-
|
|
613
|
+
assert_deprecation exp do
|
|
627
614
|
(1 + 1).must_equal 2
|
|
628
615
|
end
|
|
629
616
|
end
|
|
@@ -654,9 +641,9 @@ describe Minitest::Spec do
|
|
|
654
641
|
end
|
|
655
642
|
|
|
656
643
|
it "needs to verify types of objects" do
|
|
657
|
-
assert_success _(6 * 7).must_be_instance_of(
|
|
644
|
+
assert_success _(6 * 7).must_be_instance_of(Integer)
|
|
658
645
|
|
|
659
|
-
exp = "Expected 42 to be an instance of String, not
|
|
646
|
+
exp = "Expected 42 to be an instance of String, not Integer."
|
|
660
647
|
|
|
661
648
|
assert_triggered exp do
|
|
662
649
|
_(6 * 7).must_be_instance_of String
|
|
@@ -683,7 +670,7 @@ describe Minitest::Spec do
|
|
|
683
670
|
assert_success _(41).must_be(:<, 42)
|
|
684
671
|
|
|
685
672
|
assert_triggered "Expected 42 to be < 41." do
|
|
686
|
-
_(42).must_be
|
|
673
|
+
_(42).must_be :<, 41
|
|
687
674
|
end
|
|
688
675
|
end
|
|
689
676
|
|
|
@@ -700,19 +687,17 @@ describe Minitest::Spec do
|
|
|
700
687
|
it "needs to verify using respond_to" do
|
|
701
688
|
assert_success _(42).must_respond_to(:+)
|
|
702
689
|
|
|
703
|
-
assert_triggered "Expected 42 (
|
|
690
|
+
assert_triggered "Expected 42 (Integer) to respond to #clear." do
|
|
704
691
|
_(42).must_respond_to :clear
|
|
705
692
|
end
|
|
706
693
|
|
|
707
|
-
assert_triggered "msg.\nExpected 42 (
|
|
694
|
+
assert_triggered "msg.\nExpected 42 (Integer) to respond to #clear." do
|
|
708
695
|
_(42).must_respond_to :clear, "msg"
|
|
709
696
|
end
|
|
710
697
|
end
|
|
711
698
|
end
|
|
712
699
|
|
|
713
700
|
describe Minitest::Spec, :let do
|
|
714
|
-
i_suck_and_my_tests_are_order_dependent!
|
|
715
|
-
|
|
716
701
|
def _count
|
|
717
702
|
$let_count ||= 0
|
|
718
703
|
end
|
|
@@ -723,21 +708,21 @@ describe Minitest::Spec, :let do
|
|
|
723
708
|
end
|
|
724
709
|
|
|
725
710
|
it "is evaluated once per example" do
|
|
726
|
-
|
|
711
|
+
exp = _count + 1
|
|
727
712
|
|
|
728
|
-
_(count).must_equal
|
|
729
|
-
_(count).must_equal
|
|
713
|
+
_(count).must_equal exp
|
|
714
|
+
_(count).must_equal exp
|
|
730
715
|
|
|
731
|
-
_(_count).must_equal
|
|
716
|
+
_(_count).must_equal exp
|
|
732
717
|
end
|
|
733
718
|
|
|
734
719
|
it "is REALLY evaluated once per example" do
|
|
735
|
-
|
|
720
|
+
exp = _count + 1
|
|
736
721
|
|
|
737
|
-
_(count).must_equal
|
|
738
|
-
_(count).must_equal
|
|
722
|
+
_(count).must_equal exp
|
|
723
|
+
_(count).must_equal exp
|
|
739
724
|
|
|
740
|
-
_(_count).must_equal
|
|
725
|
+
_(_count).must_equal exp
|
|
741
726
|
end
|
|
742
727
|
|
|
743
728
|
it 'raises an error if the name begins with "test"' do
|
|
@@ -751,9 +736,9 @@ describe Minitest::Spec, :let do
|
|
|
751
736
|
it "doesn't raise an error if it is just another let" do
|
|
752
737
|
v = proc do
|
|
753
738
|
describe :outer do
|
|
754
|
-
let
|
|
739
|
+
let :bar
|
|
755
740
|
describe :inner do
|
|
756
|
-
let
|
|
741
|
+
let :bar
|
|
757
742
|
end
|
|
758
743
|
end
|
|
759
744
|
:good
|
|
@@ -942,6 +927,16 @@ class TestMeta < MetaMetaMetaTestCase
|
|
|
942
927
|
assert_equal "ExampleB::random_method::addl_context", spec_c.name
|
|
943
928
|
end
|
|
944
929
|
|
|
930
|
+
def test_inspect
|
|
931
|
+
spec_a = describe ExampleA do; end
|
|
932
|
+
spec_b = describe ExampleB, :random_method do; end
|
|
933
|
+
spec_c = describe ExampleB, :random_method, :addl_context do; end
|
|
934
|
+
|
|
935
|
+
assert_equal "ExampleA", spec_a.inspect
|
|
936
|
+
assert_equal "ExampleB::random_method", spec_b.inspect
|
|
937
|
+
assert_equal "ExampleB::random_method::addl_context", spec_c.inspect
|
|
938
|
+
end
|
|
939
|
+
|
|
945
940
|
def test_name2
|
|
946
941
|
assert_equal "NamedExampleA", NamedExampleA.name
|
|
947
942
|
assert_equal "NamedExampleB", NamedExampleB.name
|
|
@@ -954,6 +949,23 @@ class TestMeta < MetaMetaMetaTestCase
|
|
|
954
949
|
assert_equal "ExampleB::random_method", spec_b.name
|
|
955
950
|
end
|
|
956
951
|
|
|
952
|
+
def test_name_inside_class
|
|
953
|
+
spec_a = nil
|
|
954
|
+
spec_b = nil
|
|
955
|
+
inside_class_example = Class.new Minitest::Spec
|
|
956
|
+
Object.const_set :InsideClassExample, inside_class_example
|
|
957
|
+
inside_class_example.class_eval do
|
|
958
|
+
spec_a = describe "a" do
|
|
959
|
+
spec_b = describe "b" do; end
|
|
960
|
+
end
|
|
961
|
+
end
|
|
962
|
+
|
|
963
|
+
assert_equal "InsideClassExample::a", spec_a.name
|
|
964
|
+
assert_equal "InsideClassExample::a::b", spec_b.name
|
|
965
|
+
ensure
|
|
966
|
+
Object.send :remove_const, :InsideClassExample
|
|
967
|
+
end
|
|
968
|
+
|
|
957
969
|
def test_structure
|
|
958
970
|
x, y, z, * = util_structure
|
|
959
971
|
|
|
@@ -1016,8 +1028,9 @@ class TestMeta < MetaMetaMetaTestCase
|
|
|
1016
1028
|
z = describe "second thingy" do end
|
|
1017
1029
|
end
|
|
1018
1030
|
|
|
1019
|
-
test_methods = [
|
|
1020
|
-
|
|
1031
|
+
test_methods = [
|
|
1032
|
+
"test_0001_top level it",
|
|
1033
|
+
"test_0002_не латинские &いった α, β, γ, δ, ε hello!!! world",
|
|
1021
1034
|
].sort
|
|
1022
1035
|
|
|
1023
1036
|
assert_equal test_methods, [x1, x2]
|