minitest 5.11.3 → 5.14.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
- require "minitest/autorun"
2
+ require "minitest/metametameta"
3
3
  require "stringio"
4
4
 
5
5
  class MiniSpecA < Minitest::Spec; end
@@ -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
@@ -56,43 +59,63 @@ describe Minitest::Spec do
56
59
  @assertion_count = 1
57
60
 
58
61
  assert_triggered "Expected 1 to not be equal to 1." do
59
- 1.wont_equal 1
62
+ _(1).wont_equal 1
63
+ end
64
+ end
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
60
83
  end
61
84
  end
62
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
- [1, 2, 3].must_include 5
92
+ _([1, 2, 3]).must_include 5
70
93
  end
71
94
 
72
95
  assert_triggered "msg.\nExpected [1, 2, 3] to include 5." do
73
- [1, 2, 3].must_include 5, "msg"
96
+ _([1, 2, 3]).must_include 5, "msg"
74
97
  end
75
98
  end
76
99
 
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
- [1, 2, 3].wont_include 2
106
+ _([1, 2, 3]).wont_include 2
84
107
  end
85
108
 
86
109
  assert_triggered "msg.\nExpected [1, 2, 3] to not include 2." do
87
- [1, 2, 3].wont_include 2, "msg"
110
+ _([1, 2, 3]).wont_include 2, "msg"
88
111
  end
89
112
  end
90
113
 
91
114
  it "needs to catch an expected exception" do
92
115
  @assertion_count = 2
93
116
 
94
- proc { raise "blah" }.must_raise RuntimeError
95
- proc { raise Minitest::Assertion }.must_raise Minitest::Assertion
117
+ expect { raise "blah" }.must_raise RuntimeError
118
+ expect { raise Minitest::Assertion }.must_raise Minitest::Assertion
96
119
  end
97
120
 
98
121
  it "needs to catch an unexpected exception" do
@@ -106,11 +129,11 @@ describe Minitest::Spec do
106
129
  EOM
107
130
 
108
131
  assert_triggered msg do
109
- proc { raise StandardError, "woot" }.must_raise RuntimeError
132
+ expect { raise StandardError, "woot" }.must_raise RuntimeError
110
133
  end
111
134
 
112
135
  assert_triggered "msg.\n#{msg}" do
113
- proc { raise StandardError, "woot" }.must_raise RuntimeError, "msg"
136
+ expect { raise StandardError, "woot" }.must_raise RuntimeError, "msg"
114
137
  end
115
138
  end
116
139
 
@@ -118,20 +141,22 @@ describe Minitest::Spec do
118
141
  @assertion_count -= 1 # no msg
119
142
  @assertion_count += 2 # assert_output is 2 assertions
120
143
 
121
- proc {}.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
- proc { print "xxx" }.must_be_silent
147
+ expect { print "xxx" }.must_be_silent
125
148
  end
126
149
  end
127
150
 
128
151
  it "needs to have all methods named well" do
152
+ skip "N/A" if ENV["MT_NO_EXPECTATIONS"]
153
+
129
154
  @assertion_count = 2
130
155
 
131
- methods = Object.public_instance_methods.find_all { |n| n =~ /^must|^wont/ }
156
+ methods = Minitest::Expectations.public_instance_methods.grep(/must|wont/)
132
157
  methods.map!(&:to_s) if Symbol === methods.first
133
158
 
134
- musts, wonts = methods.sort.partition { |m| m =~ /^must/ }
159
+ musts, wonts = methods.sort.partition { |m| m =~ /must/ }
135
160
 
136
161
  expected_musts = %w[must_be
137
162
  must_be_close_to
@@ -149,70 +174,71 @@ describe Minitest::Spec do
149
174
  must_output
150
175
  must_raise
151
176
  must_respond_to
152
- must_throw]
177
+ must_throw
178
+ path_must_exist]
153
179
 
154
180
  bad = %w[not raise throw send output be_silent]
155
181
 
156
- expected_wonts = expected_musts.map { |m| m.sub(/^must/, "wont") }
182
+ expected_wonts = expected_musts.map { |m| m.sub(/must/, "wont") }.sort
157
183
  expected_wonts.reject! { |m| m =~ /wont_#{Regexp.union(*bad)}/ }
158
184
 
159
- musts.must_equal expected_musts
160
- wonts.must_equal expected_wonts
185
+ _(musts).must_equal expected_musts
186
+ _(wonts).must_equal expected_wonts
161
187
  end
162
188
 
163
189
  it "needs to raise if an expected exception is not raised" do
164
190
  @assertion_count -= 2 # no positive test
165
191
 
166
192
  assert_triggered "RuntimeError expected but nothing was raised." do
167
- proc { 42 }.must_raise RuntimeError
193
+ expect { 42 }.must_raise RuntimeError
168
194
  end
169
195
 
170
196
  assert_triggered "msg.\nRuntimeError expected but nothing was raised." do
171
- proc { 42 }.must_raise RuntimeError, "msg"
197
+ expect { 42 }.must_raise RuntimeError, "msg"
172
198
  end
173
199
  end
174
200
 
175
201
  it "needs to verify binary messages" do
176
- 42.wont_be(:<, 24).must_equal false
202
+ assert_success _(42).wont_be(:<, 24)
177
203
 
178
204
  assert_triggered "Expected 24 to not be < 42." do
179
- 24.wont_be :<, 42
205
+ _(24).wont_be :<, 42
180
206
  end
181
207
 
182
208
  assert_triggered "msg.\nExpected 24 to not be < 42." do
183
- 24.wont_be :<, 42, "msg"
209
+ _(24).wont_be :<, 42, "msg"
184
210
  end
185
211
  end
186
212
 
187
213
  it "needs to verify emptyness" do
188
214
  @assertion_count += 3 # empty is 2 assertions
189
215
 
190
- [].must_be_empty.must_equal true
216
+ assert_success _([]).must_be_empty
191
217
 
192
218
  assert_triggered "Expected [42] to be empty." do
193
- [42].must_be_empty
219
+ _([42]).must_be_empty
194
220
  end
195
221
 
196
222
  assert_triggered "msg.\nExpected [42] to be empty." do
197
- [42].must_be_empty "msg"
223
+ _([42]).must_be_empty "msg"
198
224
  end
199
225
  end
200
226
 
201
227
  it "needs to verify equality" do
202
228
  @assertion_count += 1
203
229
 
204
- (6 * 7).must_equal(42).must_equal true
230
+ assert_success _(6 * 7).must_equal(42)
205
231
 
206
232
  assert_triggered "Expected: 42\n Actual: 54" do
207
- (6 * 9).must_equal 42
233
+ _(6 * 9).must_equal 42
208
234
  end
209
235
 
210
236
  assert_triggered "msg.\nExpected: 42\n Actual: 54" do
211
- (6 * 9).must_equal 42, "msg"
237
+ _(6 * 9).must_equal 42, "msg"
212
238
  end
213
239
 
214
- assert_triggered(/^-42\n\+#<Proc:0xXXXXXX@PATH>\n/) do
215
- proc { 42 }.must_equal 42 # proc isn't called, so expectation fails
240
+ assert_triggered(/^-42\n\+#<Proc:0xXXXXXX[ @]PATH>\n/) do
241
+ _(proc { 42 }).must_equal 42 # proc isn't called, so expectation fails
216
242
  end
217
243
  end
218
244
 
@@ -220,7 +246,7 @@ describe Minitest::Spec do
220
246
  @assertion_count += 1 # extra test
221
247
 
222
248
  out, err = capture_io do
223
- nil.must_equal(nil).must_equal true
249
+ assert_success _(nil).must_equal(nil)
224
250
  end
225
251
 
226
252
  exp = "DEPRECATED: Use assert_nil if expecting nil from #{__FILE__}:#{__LINE__-3}. " \
@@ -234,259 +260,259 @@ describe Minitest::Spec do
234
260
  it "needs to verify floats outside a delta" do
235
261
  @assertion_count += 1 # extra test
236
262
 
237
- 24.wont_be_close_to(42).must_equal false
263
+ assert_success _(24).wont_be_close_to(42)
238
264
 
239
265
  assert_triggered "Expected |42 - 42.0| (0.0) to not be <= 0.001." do
240
- (6 * 7.0).wont_be_close_to 42
266
+ _(6 * 7.0).wont_be_close_to 42
241
267
  end
242
268
 
243
- x = maglev? ? "1.0000000000000001e-05" : "1.0e-05"
269
+ x = "1.0e-05"
244
270
  assert_triggered "Expected |42 - 42.0| (0.0) to not be <= #{x}." do
245
- (6 * 7.0).wont_be_close_to 42, 0.00001
271
+ _(6 * 7.0).wont_be_close_to 42, 0.00001
246
272
  end
247
273
 
248
274
  assert_triggered "msg.\nExpected |42 - 42.0| (0.0) to not be <= #{x}." do
249
- (6 * 7.0).wont_be_close_to 42, 0.00001, "msg"
275
+ _(6 * 7.0).wont_be_close_to 42, 0.00001, "msg"
250
276
  end
251
277
  end
252
278
 
253
279
  it "needs to verify floats outside an epsilon" do
254
280
  @assertion_count += 1 # extra test
255
281
 
256
- 24.wont_be_within_epsilon(42).must_equal false
282
+ assert_success _(24).wont_be_within_epsilon(42)
257
283
 
258
- x = maglev? ? "0.042000000000000003" : "0.042"
284
+ x = "0.042"
259
285
  assert_triggered "Expected |42 - 42.0| (0.0) to not be <= #{x}." do
260
- (6 * 7.0).wont_be_within_epsilon 42
286
+ _(6 * 7.0).wont_be_within_epsilon 42
261
287
  end
262
288
 
263
- x = maglev? ? "0.00042000000000000002" : "0.00042"
289
+ x = "0.00042"
264
290
  assert_triggered "Expected |42 - 42.0| (0.0) to not be <= #{x}." do
265
- (6 * 7.0).wont_be_within_epsilon 42, 0.00001
291
+ _(6 * 7.0).wont_be_within_epsilon 42, 0.00001
266
292
  end
267
293
 
268
294
  assert_triggered "msg.\nExpected |42 - 42.0| (0.0) to not be <= #{x}." do
269
- (6 * 7.0).wont_be_within_epsilon 42, 0.00001, "msg"
295
+ _(6 * 7.0).wont_be_within_epsilon 42, 0.00001, "msg"
270
296
  end
271
297
  end
272
298
 
273
299
  it "needs to verify floats within a delta" do
274
300
  @assertion_count += 1 # extra test
275
301
 
276
- (6.0 * 7).must_be_close_to(42.0).must_equal true
302
+ assert_success _(6.0 * 7).must_be_close_to(42.0)
277
303
 
278
304
  assert_triggered "Expected |0.0 - 0.01| (0.01) to be <= 0.001." do
279
- (1.0 / 100).must_be_close_to 0.0
305
+ _(1.0 / 100).must_be_close_to 0.0
280
306
  end
281
307
 
282
- x = maglev? ? "9.9999999999999995e-07" : "1.0e-06"
308
+ x = "1.0e-06"
283
309
  assert_triggered "Expected |0.0 - 0.001| (0.001) to be <= #{x}." do
284
- (1.0 / 1000).must_be_close_to 0.0, 0.000001
310
+ _(1.0 / 1000).must_be_close_to 0.0, 0.000001
285
311
  end
286
312
 
287
313
  assert_triggered "msg.\nExpected |0.0 - 0.001| (0.001) to be <= #{x}." do
288
- (1.0 / 1000).must_be_close_to 0.0, 0.000001, "msg"
314
+ _(1.0 / 1000).must_be_close_to 0.0, 0.000001, "msg"
289
315
  end
290
316
  end
291
317
 
292
318
  it "needs to verify floats within an epsilon" do
293
319
  @assertion_count += 1 # extra test
294
320
 
295
- (6.0 * 7).must_be_within_epsilon(42.0).must_equal true
321
+ assert_success _(6.0 * 7).must_be_within_epsilon(42.0)
296
322
 
297
323
  assert_triggered "Expected |0.0 - 0.01| (0.01) to be <= 0.0." do
298
- (1.0 / 100).must_be_within_epsilon 0.0
324
+ _(1.0 / 100).must_be_within_epsilon 0.0
299
325
  end
300
326
 
301
327
  assert_triggered "Expected |0.0 - 0.001| (0.001) to be <= 0.0." do
302
- (1.0 / 1000).must_be_within_epsilon 0.0, 0.000001
328
+ _(1.0 / 1000).must_be_within_epsilon 0.0, 0.000001
303
329
  end
304
330
 
305
331
  assert_triggered "msg.\nExpected |0.0 - 0.001| (0.001) to be <= 0.0." do
306
- (1.0 / 1000).must_be_within_epsilon 0.0, 0.000001, "msg"
332
+ _(1.0 / 1000).must_be_within_epsilon 0.0, 0.000001, "msg"
307
333
  end
308
334
  end
309
335
 
310
336
  it "needs to verify identity" do
311
- 1.must_be_same_as(1).must_equal true
337
+ assert_success _(1).must_be_same_as(1)
312
338
 
313
339
  assert_triggered "Expected 1 (oid=N) to be the same as 2 (oid=N)." do
314
- 1.must_be_same_as 2
340
+ _(1).must_be_same_as 2
315
341
  end
316
342
 
317
343
  assert_triggered "msg.\nExpected 1 (oid=N) to be the same as 2 (oid=N)." do
318
- 1.must_be_same_as 2, "msg"
344
+ _(1).must_be_same_as 2, "msg"
319
345
  end
320
346
  end
321
347
 
322
348
  it "needs to verify inequality" do
323
349
  @assertion_count += 2
324
- 42.wont_equal(6 * 9).must_equal false
325
- proc {}.wont_equal(42).must_equal false
350
+ assert_success _(42).wont_equal(6 * 9)
351
+ assert_success _(proc {}).wont_equal(42)
326
352
 
327
353
  assert_triggered "Expected 1 to not be equal to 1." do
328
- 1.wont_equal 1
354
+ _(1).wont_equal 1
329
355
  end
330
356
 
331
357
  assert_triggered "msg.\nExpected 1 to not be equal to 1." do
332
- 1.wont_equal 1, "msg"
358
+ _(1).wont_equal 1, "msg"
333
359
  end
334
360
  end
335
361
 
336
362
  it "needs to verify instances of a class" do
337
- 42.wont_be_instance_of(String).must_equal false
363
+ assert_success _(42).wont_be_instance_of(String)
338
364
 
339
365
  assert_triggered "Expected 42 to not be a kind of #{Int.name}." do
340
- 42.wont_be_kind_of Int
366
+ _(42).wont_be_kind_of Int
341
367
  end
342
368
 
343
369
  assert_triggered "msg.\nExpected 42 to not be an instance of #{Int.name}." do
344
- 42.wont_be_instance_of Int, "msg"
370
+ _(42).wont_be_instance_of Int, "msg"
345
371
  end
346
372
  end
347
373
 
348
374
  it "needs to verify kinds of a class" do
349
375
  @assertion_count += 2
350
376
 
351
- 42.wont_be_kind_of(String).must_equal false
352
- 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)
353
379
 
354
380
  assert_triggered "Expected 42 to not be a kind of #{Int.name}." do
355
- 42.wont_be_kind_of Int
381
+ _(42).wont_be_kind_of Int
356
382
  end
357
383
 
358
384
  assert_triggered "msg.\nExpected 42 to not be a kind of #{Int.name}." do
359
- 42.wont_be_kind_of Int, "msg"
385
+ _(42).wont_be_kind_of Int, "msg"
360
386
  end
361
387
  end
362
388
 
363
389
  it "needs to verify kinds of objects" do
364
390
  @assertion_count += 3 # extra test
365
391
 
366
- (6 * 7).must_be_kind_of(Int).must_equal true
367
- (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)
368
394
 
369
395
  assert_triggered "Expected 42 to be a kind of String, not #{Int.name}." do
370
- (6 * 7).must_be_kind_of String
396
+ _(6 * 7).must_be_kind_of String
371
397
  end
372
398
 
373
399
  assert_triggered "msg.\nExpected 42 to be a kind of String, not #{Int.name}." do
374
- (6 * 7).must_be_kind_of String, "msg"
400
+ _(6 * 7).must_be_kind_of String, "msg"
375
401
  end
376
402
 
377
403
  exp = "Expected #<Proc:0xXXXXXX@PATH> to be a kind of String, not Proc."
378
404
  assert_triggered exp do
379
- proc {}.must_be_kind_of String
405
+ _(proc {}).must_be_kind_of String
380
406
  end
381
407
  end
382
408
 
383
409
  it "needs to verify mismatch" do
384
410
  @assertion_count += 3 # match is 2
385
411
 
386
- "blah".wont_match(/\d+/).must_equal false
412
+ assert_success _("blah").wont_match(/\d+/)
387
413
 
388
414
  assert_triggered "Expected /\\w+/ to not match \"blah\"." do
389
- "blah".wont_match(/\w+/)
415
+ _("blah").wont_match(/\w+/)
390
416
  end
391
417
 
392
418
  assert_triggered "msg.\nExpected /\\w+/ to not match \"blah\"." do
393
- "blah".wont_match(/\w+/, "msg")
419
+ _("blah").wont_match(/\w+/, "msg")
394
420
  end
395
421
  end
396
422
 
397
423
  it "needs to verify nil" do
398
- nil.must_be_nil.must_equal true
424
+ assert_success _(nil).must_be_nil
399
425
 
400
426
  assert_triggered "Expected 42 to be nil." do
401
- 42.must_be_nil
427
+ _(42).must_be_nil
402
428
  end
403
429
 
404
430
  assert_triggered "msg.\nExpected 42 to be nil." do
405
- 42.must_be_nil "msg"
431
+ _(42).must_be_nil "msg"
406
432
  end
407
433
  end
408
434
 
409
435
  it "needs to verify non-emptyness" do
410
436
  @assertion_count += 3 # empty is 2 assertions
411
437
 
412
- ["some item"].wont_be_empty.must_equal false
438
+ assert_success _(["some item"]).wont_be_empty
413
439
 
414
440
  assert_triggered "Expected [] to not be empty." do
415
- [].wont_be_empty
441
+ _([]).wont_be_empty
416
442
  end
417
443
 
418
444
  assert_triggered "msg.\nExpected [] to not be empty." do
419
- [].wont_be_empty "msg"
445
+ _([]).wont_be_empty "msg"
420
446
  end
421
447
  end
422
448
 
423
449
  it "needs to verify non-identity" do
424
- 1.wont_be_same_as(2).must_equal false
450
+ assert_success _(1).wont_be_same_as(2)
425
451
 
426
452
  assert_triggered "Expected 1 (oid=N) to not be the same as 1 (oid=N)." do
427
- 1.wont_be_same_as 1
453
+ _(1).wont_be_same_as 1
428
454
  end
429
455
 
430
456
  assert_triggered "msg.\nExpected 1 (oid=N) to not be the same as 1 (oid=N)." do
431
- 1.wont_be_same_as 1, "msg"
457
+ _(1).wont_be_same_as 1, "msg"
432
458
  end
433
459
  end
434
460
 
435
461
  it "needs to verify non-nil" do
436
- 42.wont_be_nil.must_equal false
462
+ assert_success _(42).wont_be_nil
437
463
 
438
464
  assert_triggered "Expected nil to not be nil." do
439
- nil.wont_be_nil
465
+ _(nil).wont_be_nil
440
466
  end
441
467
 
442
468
  assert_triggered "msg.\nExpected nil to not be nil." do
443
- nil.wont_be_nil "msg"
469
+ _(nil).wont_be_nil "msg"
444
470
  end
445
471
  end
446
472
 
447
473
  it "needs to verify objects not responding to a message" do
448
- "".wont_respond_to(:woot!).must_equal false
474
+ assert_success _("").wont_respond_to(:woot!)
449
475
 
450
476
  assert_triggered "Expected \"\" to not respond to to_s." do
451
- "".wont_respond_to :to_s
477
+ _("").wont_respond_to :to_s
452
478
  end
453
479
 
454
480
  assert_triggered "msg.\nExpected \"\" to not respond to to_s." do
455
- "".wont_respond_to :to_s, "msg"
481
+ _("").wont_respond_to :to_s, "msg"
456
482
  end
457
483
  end
458
484
 
459
485
  it "needs to verify output in stderr" do
460
486
  @assertion_count -= 1 # no msg
461
487
 
462
- proc { $stderr.print "blah" }.must_output(nil, "blah").must_equal true
488
+ assert_success expect { $stderr.print "blah" }.must_output(nil, "blah")
463
489
 
464
490
  assert_triggered "In stderr.\nExpected: \"blah\"\n Actual: \"xxx\"" do
465
- proc { $stderr.print "xxx" }.must_output(nil, "blah")
491
+ expect { $stderr.print "xxx" }.must_output(nil, "blah")
466
492
  end
467
493
  end
468
494
 
469
495
  it "needs to verify output in stdout" do
470
496
  @assertion_count -= 1 # no msg
471
497
 
472
- proc { print "blah" }.must_output("blah").must_equal true
498
+ assert_success expect { print "blah" }.must_output("blah")
473
499
 
474
500
  assert_triggered "In stdout.\nExpected: \"blah\"\n Actual: \"xxx\"" do
475
- proc { print "xxx" }.must_output("blah")
501
+ expect { print "xxx" }.must_output("blah")
476
502
  end
477
503
  end
478
504
 
479
505
  it "needs to verify regexp matches" do
480
506
  @assertion_count += 3 # must_match is 2 assertions
481
507
 
482
- "blah".must_match(/\w+/).must_equal true
508
+ assert_success _("blah").must_match(/\w+/)
483
509
 
484
510
  assert_triggered "Expected /\\d+/ to match \"blah\"." do
485
- "blah".must_match(/\d+/)
511
+ _("blah").must_match(/\d+/)
486
512
  end
487
513
 
488
514
  assert_triggered "msg.\nExpected /\\d+/ to match \"blah\"." do
489
- "blah".must_match(/\d+/, "msg")
515
+ _("blah").must_match(/\d+/, "msg")
490
516
  end
491
517
  end
492
518
 
@@ -508,89 +534,136 @@ describe Minitest::Spec do
508
534
  end
509
535
 
510
536
  it "can NOT use must_equal in a thread. It must use expect in a thread" do
511
- assert_raises NoMethodError do
537
+ skip "N/A" if ENV["MT_NO_EXPECTATIONS"]
538
+ assert_raises RuntimeError do
512
539
  capture_io do
513
540
  Thread.new { (1 + 1).must_equal 2 }.join
514
541
  end
515
542
  end
516
543
  end
544
+
545
+ it "fails gracefully when expectation used outside of `it`" do
546
+ skip "N/A" if ENV["MT_NO_EXPECTATIONS"]
547
+
548
+ @assertion_count += 1
549
+
550
+ e = assert_raises RuntimeError do
551
+ capture_io do
552
+ Thread.new { # forces ctx to be nil
553
+ describe("woot") do
554
+ (1 + 1).must_equal 2
555
+ end
556
+ }.join
557
+ end
558
+ end
559
+
560
+ assert_equal "Calling #must_equal outside of test.", e.message
561
+ end
562
+
563
+ it "deprecates expectation used without _" do
564
+ skip "N/A" if ENV["MT_NO_EXPECTATIONS"]
565
+
566
+ @assertion_count += 3
567
+
568
+ exp = /DEPRECATED: global use of must_equal from/
569
+
570
+ assert_output "", exp do
571
+ (1 + 1).must_equal 2
572
+ end
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
517
590
  end
518
591
 
519
592
  it "needs to verify throw" do
520
593
  @assertion_count += 2 # 2 extra tests
521
594
 
522
- proc { throw :blah }.must_throw(:blah).must_equal true
595
+ assert_success expect { throw :blah }.must_throw(:blah)
523
596
 
524
597
  assert_triggered "Expected :blah to have been thrown." do
525
- proc {}.must_throw :blah
598
+ expect {}.must_throw :blah
526
599
  end
527
600
 
528
601
  assert_triggered "Expected :blah to have been thrown, not :xxx." do
529
- proc { throw :xxx }.must_throw :blah
602
+ expect { throw :xxx }.must_throw :blah
530
603
  end
531
604
 
532
605
  assert_triggered "msg.\nExpected :blah to have been thrown." do
533
- proc {}.must_throw :blah, "msg"
606
+ expect {}.must_throw :blah, "msg"
534
607
  end
535
608
 
536
609
  assert_triggered "msg.\nExpected :blah to have been thrown, not :xxx." do
537
- proc { throw :xxx }.must_throw :blah, "msg"
610
+ expect { throw :xxx }.must_throw :blah, "msg"
538
611
  end
539
612
  end
540
613
 
541
614
  it "needs to verify types of objects" do
542
- (6 * 7).must_be_instance_of(Int).must_equal true
615
+ assert_success _(6 * 7).must_be_instance_of(Int)
543
616
 
544
617
  exp = "Expected 42 to be an instance of String, not #{Int.name}."
545
618
 
546
619
  assert_triggered exp do
547
- (6 * 7).must_be_instance_of String
620
+ _(6 * 7).must_be_instance_of String
548
621
  end
549
622
 
550
623
  assert_triggered "msg.\n#{exp}" do
551
- (6 * 7).must_be_instance_of String, "msg"
624
+ _(6 * 7).must_be_instance_of String, "msg"
552
625
  end
553
626
  end
554
627
 
555
628
  it "needs to verify using any (negative) predicate" do
556
629
  @assertion_count -= 1 # doesn"t take a message
557
630
 
558
- "blah".wont_be(:empty?).must_equal false
631
+ assert_success _("blah").wont_be(:empty?)
559
632
 
560
633
  assert_triggered "Expected \"\" to not be empty?." do
561
- "".wont_be :empty?
634
+ _("").wont_be :empty?
562
635
  end
563
636
  end
564
637
 
565
638
  it "needs to verify using any binary operator" do
566
639
  @assertion_count -= 1 # no msg
567
640
 
568
- 41.must_be(:<, 42).must_equal true
641
+ assert_success _(41).must_be(:<, 42)
569
642
 
570
643
  assert_triggered "Expected 42 to be < 41." do
571
- 42.must_be(:<, 41)
644
+ _(42).must_be(:<, 41)
572
645
  end
573
646
  end
574
647
 
575
648
  it "needs to verify using any predicate" do
576
649
  @assertion_count -= 1 # no msg
577
650
 
578
- "".must_be(:empty?).must_equal true
651
+ assert_success _("").must_be(:empty?)
579
652
 
580
653
  assert_triggered "Expected \"blah\" to be empty?." do
581
- "blah".must_be :empty?
654
+ _("blah").must_be :empty?
582
655
  end
583
656
  end
584
657
 
585
658
  it "needs to verify using respond_to" do
586
- 42.must_respond_to(:+).must_equal true
659
+ assert_success _(42).must_respond_to(:+)
587
660
 
588
661
  assert_triggered "Expected 42 (#{Int.name}) to respond to #clear." do
589
- 42.must_respond_to :clear
662
+ _(42).must_respond_to :clear
590
663
  end
591
664
 
592
665
  assert_triggered "msg.\nExpected 42 (#{Int.name}) to respond to #clear." do
593
- 42.must_respond_to :clear, "msg"
666
+ _(42).must_respond_to :clear, "msg"
594
667
  end
595
668
  end
596
669
  end
@@ -608,33 +681,33 @@ describe Minitest::Spec, :let do
608
681
  end
609
682
 
610
683
  it "is evaluated once per example" do
611
- _count.must_equal 0
684
+ _(_count).must_equal 0
612
685
 
613
- count.must_equal 1
614
- count.must_equal 1
686
+ _(count).must_equal 1
687
+ _(count).must_equal 1
615
688
 
616
- _count.must_equal 1
689
+ _(_count).must_equal 1
617
690
  end
618
691
 
619
692
  it "is REALLY evaluated once per example" do
620
- _count.must_equal 1
693
+ _(_count).must_equal 1
621
694
 
622
- count.must_equal 2
623
- count.must_equal 2
695
+ _(count).must_equal 2
696
+ _(count).must_equal 2
624
697
 
625
- _count.must_equal 2
698
+ _(_count).must_equal 2
626
699
  end
627
700
 
628
701
  it 'raises an error if the name begins with "test"' do
629
- proc { self.class.let(:test_value) { true } }.must_raise ArgumentError
702
+ expect { self.class.let(:test_value) { true } }.must_raise ArgumentError
630
703
  end
631
704
 
632
705
  it "raises an error if the name shadows a normal instance method" do
633
- proc { self.class.let(:message) { true } }.must_raise ArgumentError
706
+ expect { self.class.let(:message) { true } }.must_raise ArgumentError
634
707
  end
635
708
 
636
709
  it "doesn't raise an error if it is just another let" do
637
- proc do
710
+ v = proc do
638
711
  describe :outer do
639
712
  let(:bar)
640
713
  describe :inner do
@@ -642,13 +715,14 @@ describe Minitest::Spec, :let do
642
715
  end
643
716
  end
644
717
  :good
645
- end.call.must_equal :good
718
+ end.call
719
+ _(v).must_equal :good
646
720
  end
647
721
 
648
722
  it "procs come after dont_flip" do
649
723
  p = proc {}
650
724
  assert_respond_to p, :call
651
- p.must_respond_to :call
725
+ _(p).must_respond_to :call
652
726
  end
653
727
  end
654
728
 
@@ -662,9 +736,9 @@ describe Minitest::Spec, :subject do
662
736
  end
663
737
 
664
738
  it "is evaluated once per example" do
665
- subject.must_equal 1
666
- subject.must_equal 1
667
- subject_evaluation_count.must_equal 1
739
+ _(subject).must_equal 1
740
+ _(subject).must_equal 1
741
+ _(subject_evaluation_count).must_equal 1
668
742
  end
669
743
  end
670
744
 
@@ -722,10 +796,8 @@ class TestMetaStatic < Minitest::Test
722
796
  end
723
797
  end
724
798
 
725
- require "minitest/metametameta"
726
-
727
799
  class TestMeta < MetaMetaMetaTestCase
728
- parallelize_me!
800
+ # do not call parallelize_me! here because specs use register_spec_type globally
729
801
 
730
802
  def util_structure
731
803
  y = z = nil
@@ -795,7 +867,7 @@ class TestMeta < MetaMetaMetaTestCase
795
867
  def test_bug_dsl_expectations
796
868
  spec_class = Class.new MiniSpecB do
797
869
  it "should work" do
798
- 0.must_equal 0
870
+ _(0).must_equal 0
799
871
  end
800
872
  end
801
873
 
@@ -947,18 +1019,20 @@ class TestSpecInTestCase < MetaMetaMetaTestCase
947
1019
  end
948
1020
 
949
1021
  def test_expectation
950
- @tc.assert_equal true, 1.must_equal(1)
1022
+ @tc.assert_equal true, _(1).must_equal(1)
951
1023
  end
952
1024
 
953
1025
  def test_expectation_triggered
954
1026
  assert_triggered "Expected: 2\n Actual: 1" do
955
- 1.must_equal 2
1027
+ _(1).must_equal 2
956
1028
  end
957
1029
  end
958
1030
 
1031
+ include Minitest::Spec::DSL::InstanceMethods
1032
+
959
1033
  def test_expectation_with_a_message
960
1034
  assert_triggered "woot.\nExpected: 2\n Actual: 1" do
961
- 1.must_equal 2, "woot"
1035
+ _(1).must_equal 2, "woot"
962
1036
  end
963
1037
  end
964
1038
  end