minitest 5.11.0 → 5.12.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/History.rdoc +54 -0
- data/Manifest.txt +1 -0
- data/README.rdoc +24 -7
- data/Rakefile +1 -15
- data/lib/minitest.rb +118 -52
- data/lib/minitest/assertions.rb +48 -15
- data/lib/minitest/benchmark.rb +2 -2
- data/lib/minitest/parallel.rb +1 -1
- data/lib/minitest/spec.rb +4 -0
- data/lib/minitest/test.rb +6 -1
- data/test/minitest/metametameta.rb +3 -0
- data/test/minitest/test_minitest_assertions.rb +1389 -0
- data/test/minitest/test_minitest_mock.rb +2 -2
- data/test/minitest/test_minitest_reporter.rb +3 -3
- data/test/minitest/test_minitest_spec.rb +167 -131
- data/test/minitest/test_minitest_test.rb +13 -1093
- metadata +25 -19
- metadata.gz.sig +0 -0
@@ -362,7 +362,7 @@ end
|
|
362
362
|
require "minitest/metametameta"
|
363
363
|
|
364
364
|
class TestMinitestStub < Minitest::Test
|
365
|
-
|
365
|
+
# Do not parallelize since we're calling stub on class methods
|
366
366
|
|
367
367
|
def setup
|
368
368
|
super
|
@@ -374,7 +374,7 @@ class TestMinitestStub < Minitest::Test
|
|
374
374
|
|
375
375
|
def teardown
|
376
376
|
super
|
377
|
-
assert_equal @assertion_count, @tc.assertions
|
377
|
+
assert_equal @assertion_count, @tc.assertions if self.passed?
|
378
378
|
end
|
379
379
|
|
380
380
|
class Time
|
@@ -90,13 +90,13 @@ class TestMinitestReporter < MetaMetaMetaTestCase
|
|
90
90
|
end
|
91
91
|
|
92
92
|
def test_passed_eh_empty
|
93
|
-
|
93
|
+
assert_predicate r, :passed?
|
94
94
|
end
|
95
95
|
|
96
96
|
def test_passed_eh_failure
|
97
97
|
r.results << fail_test
|
98
98
|
|
99
|
-
|
99
|
+
refute_predicate r, :passed?
|
100
100
|
end
|
101
101
|
|
102
102
|
SKIP_MSG = "\n\nYou have skipped tests. Run with --verbose for details."
|
@@ -106,7 +106,7 @@ class TestMinitestReporter < MetaMetaMetaTestCase
|
|
106
106
|
|
107
107
|
r.results << error_test
|
108
108
|
|
109
|
-
|
109
|
+
refute_predicate r, :passed?
|
110
110
|
|
111
111
|
r.report
|
112
112
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require "minitest/
|
2
|
+
require "minitest/metametameta"
|
3
3
|
require "stringio"
|
4
4
|
|
5
5
|
class MiniSpecA < Minitest::Spec; end
|
@@ -56,43 +56,43 @@ describe Minitest::Spec do
|
|
56
56
|
@assertion_count = 1
|
57
57
|
|
58
58
|
assert_triggered "Expected 1 to not be equal to 1." do
|
59
|
-
1.wont_equal 1
|
59
|
+
_(1).wont_equal 1
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
63
|
it "needs to be sensible about must_include order" do
|
64
64
|
@assertion_count += 3 # must_include is 2 assertions
|
65
65
|
|
66
|
-
[1, 2, 3].must_include(2).must_equal true
|
66
|
+
_(_([1, 2, 3]).must_include(2)).must_equal true
|
67
67
|
|
68
68
|
assert_triggered "Expected [1, 2, 3] to include 5." do
|
69
|
-
[1, 2, 3].must_include 5
|
69
|
+
_([1, 2, 3]).must_include 5
|
70
70
|
end
|
71
71
|
|
72
72
|
assert_triggered "msg.\nExpected [1, 2, 3] to include 5." do
|
73
|
-
[1, 2, 3].must_include 5, "msg"
|
73
|
+
_([1, 2, 3]).must_include 5, "msg"
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
77
|
it "needs to be sensible about wont_include order" do
|
78
78
|
@assertion_count += 3 # wont_include is 2 assertions
|
79
79
|
|
80
|
-
[1, 2, 3].wont_include(5).must_equal false
|
80
|
+
_(_([1, 2, 3]).wont_include(5)).must_equal false
|
81
81
|
|
82
82
|
assert_triggered "Expected [1, 2, 3] to not include 2." do
|
83
|
-
[1, 2, 3].wont_include 2
|
83
|
+
_([1, 2, 3]).wont_include 2
|
84
84
|
end
|
85
85
|
|
86
86
|
assert_triggered "msg.\nExpected [1, 2, 3] to not include 2." do
|
87
|
-
[1, 2, 3].wont_include 2, "msg"
|
87
|
+
_([1, 2, 3]).wont_include 2, "msg"
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
91
91
|
it "needs to catch an expected exception" do
|
92
92
|
@assertion_count = 2
|
93
93
|
|
94
|
-
|
95
|
-
|
94
|
+
expect { raise "blah" }.must_raise RuntimeError
|
95
|
+
expect { raise Minitest::Assertion }.must_raise Minitest::Assertion
|
96
96
|
end
|
97
97
|
|
98
98
|
it "needs to catch an unexpected exception" do
|
@@ -106,11 +106,11 @@ describe Minitest::Spec do
|
|
106
106
|
EOM
|
107
107
|
|
108
108
|
assert_triggered msg do
|
109
|
-
|
109
|
+
expect { raise StandardError, "woot" }.must_raise RuntimeError
|
110
110
|
end
|
111
111
|
|
112
112
|
assert_triggered "msg.\n#{msg}" do
|
113
|
-
|
113
|
+
expect { raise StandardError, "woot" }.must_raise RuntimeError, "msg"
|
114
114
|
end
|
115
115
|
end
|
116
116
|
|
@@ -118,14 +118,16 @@ describe Minitest::Spec do
|
|
118
118
|
@assertion_count -= 1 # no msg
|
119
119
|
@assertion_count += 2 # assert_output is 2 assertions
|
120
120
|
|
121
|
-
|
121
|
+
_(expect {}.must_be_silent).must_equal true
|
122
122
|
|
123
123
|
assert_triggered "In stdout.\nExpected: \"\"\n Actual: \"xxx\"" do
|
124
|
-
|
124
|
+
expect { print "xxx" }.must_be_silent
|
125
125
|
end
|
126
126
|
end
|
127
127
|
|
128
128
|
it "needs to have all methods named well" do
|
129
|
+
skip "N/A" if ENV["MT_NO_EXPECTATIONS"]
|
130
|
+
|
129
131
|
@assertion_count = 2
|
130
132
|
|
131
133
|
methods = Object.public_instance_methods.find_all { |n| n =~ /^must|^wont/ }
|
@@ -156,63 +158,63 @@ describe Minitest::Spec do
|
|
156
158
|
expected_wonts = expected_musts.map { |m| m.sub(/^must/, "wont") }
|
157
159
|
expected_wonts.reject! { |m| m =~ /wont_#{Regexp.union(*bad)}/ }
|
158
160
|
|
159
|
-
musts.must_equal expected_musts
|
160
|
-
wonts.must_equal expected_wonts
|
161
|
+
_(musts).must_equal expected_musts
|
162
|
+
_(wonts).must_equal expected_wonts
|
161
163
|
end
|
162
164
|
|
163
165
|
it "needs to raise if an expected exception is not raised" do
|
164
166
|
@assertion_count -= 2 # no positive test
|
165
167
|
|
166
168
|
assert_triggered "RuntimeError expected but nothing was raised." do
|
167
|
-
|
169
|
+
expect { 42 }.must_raise RuntimeError
|
168
170
|
end
|
169
171
|
|
170
172
|
assert_triggered "msg.\nRuntimeError expected but nothing was raised." do
|
171
|
-
|
173
|
+
expect { 42 }.must_raise RuntimeError, "msg"
|
172
174
|
end
|
173
175
|
end
|
174
176
|
|
175
177
|
it "needs to verify binary messages" do
|
176
|
-
42.wont_be(:<, 24).must_equal false
|
178
|
+
_(_(42).wont_be(:<, 24)).must_equal false
|
177
179
|
|
178
180
|
assert_triggered "Expected 24 to not be < 42." do
|
179
|
-
24.wont_be :<, 42
|
181
|
+
_(24).wont_be :<, 42
|
180
182
|
end
|
181
183
|
|
182
184
|
assert_triggered "msg.\nExpected 24 to not be < 42." do
|
183
|
-
24.wont_be :<, 42, "msg"
|
185
|
+
_(24).wont_be :<, 42, "msg"
|
184
186
|
end
|
185
187
|
end
|
186
188
|
|
187
189
|
it "needs to verify emptyness" do
|
188
190
|
@assertion_count += 3 # empty is 2 assertions
|
189
191
|
|
190
|
-
[].must_be_empty.must_equal true
|
192
|
+
_(_([]).must_be_empty).must_equal true
|
191
193
|
|
192
194
|
assert_triggered "Expected [42] to be empty." do
|
193
|
-
[42].must_be_empty
|
195
|
+
_([42]).must_be_empty
|
194
196
|
end
|
195
197
|
|
196
198
|
assert_triggered "msg.\nExpected [42] to be empty." do
|
197
|
-
[42].must_be_empty "msg"
|
199
|
+
_([42]).must_be_empty "msg"
|
198
200
|
end
|
199
201
|
end
|
200
202
|
|
201
203
|
it "needs to verify equality" do
|
202
204
|
@assertion_count += 1
|
203
205
|
|
204
|
-
(6 * 7).must_equal(42).must_equal true
|
206
|
+
_(_(6 * 7).must_equal(42)).must_equal true
|
205
207
|
|
206
208
|
assert_triggered "Expected: 42\n Actual: 54" do
|
207
|
-
(6 * 9).must_equal 42
|
209
|
+
_(6 * 9).must_equal 42
|
208
210
|
end
|
209
211
|
|
210
212
|
assert_triggered "msg.\nExpected: 42\n Actual: 54" do
|
211
|
-
(6 * 9).must_equal 42, "msg"
|
213
|
+
_(6 * 9).must_equal 42, "msg"
|
212
214
|
end
|
213
215
|
|
214
216
|
assert_triggered(/^-42\n\+#<Proc:0xXXXXXX@PATH>\n/) do
|
215
|
-
proc { 42 }.must_equal 42 # proc isn't called, so expectation fails
|
217
|
+
_(proc { 42 }).must_equal 42 # proc isn't called, so expectation fails
|
216
218
|
end
|
217
219
|
end
|
218
220
|
|
@@ -220,7 +222,7 @@ describe Minitest::Spec do
|
|
220
222
|
@assertion_count += 1 # extra test
|
221
223
|
|
222
224
|
out, err = capture_io do
|
223
|
-
nil.must_equal(nil).must_equal true
|
225
|
+
_(_(nil).must_equal(nil)).must_equal true
|
224
226
|
end
|
225
227
|
|
226
228
|
exp = "DEPRECATED: Use assert_nil if expecting nil from #{__FILE__}:#{__LINE__-3}. " \
|
@@ -234,259 +236,259 @@ describe Minitest::Spec do
|
|
234
236
|
it "needs to verify floats outside a delta" do
|
235
237
|
@assertion_count += 1 # extra test
|
236
238
|
|
237
|
-
24.wont_be_close_to(42).must_equal false
|
239
|
+
_(_(24).wont_be_close_to(42)).must_equal false
|
238
240
|
|
239
241
|
assert_triggered "Expected |42 - 42.0| (0.0) to not be <= 0.001." do
|
240
|
-
(6 * 7.0).wont_be_close_to 42
|
242
|
+
_(6 * 7.0).wont_be_close_to 42
|
241
243
|
end
|
242
244
|
|
243
245
|
x = maglev? ? "1.0000000000000001e-05" : "1.0e-05"
|
244
246
|
assert_triggered "Expected |42 - 42.0| (0.0) to not be <= #{x}." do
|
245
|
-
(6 * 7.0).wont_be_close_to 42, 0.00001
|
247
|
+
_(6 * 7.0).wont_be_close_to 42, 0.00001
|
246
248
|
end
|
247
249
|
|
248
250
|
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"
|
251
|
+
_(6 * 7.0).wont_be_close_to 42, 0.00001, "msg"
|
250
252
|
end
|
251
253
|
end
|
252
254
|
|
253
255
|
it "needs to verify floats outside an epsilon" do
|
254
256
|
@assertion_count += 1 # extra test
|
255
257
|
|
256
|
-
24.wont_be_within_epsilon(42).must_equal false
|
258
|
+
_(_(24).wont_be_within_epsilon(42)).must_equal false
|
257
259
|
|
258
260
|
x = maglev? ? "0.042000000000000003" : "0.042"
|
259
261
|
assert_triggered "Expected |42 - 42.0| (0.0) to not be <= #{x}." do
|
260
|
-
(6 * 7.0).wont_be_within_epsilon 42
|
262
|
+
_(6 * 7.0).wont_be_within_epsilon 42
|
261
263
|
end
|
262
264
|
|
263
265
|
x = maglev? ? "0.00042000000000000002" : "0.00042"
|
264
266
|
assert_triggered "Expected |42 - 42.0| (0.0) to not be <= #{x}." do
|
265
|
-
(6 * 7.0).wont_be_within_epsilon 42, 0.00001
|
267
|
+
_(6 * 7.0).wont_be_within_epsilon 42, 0.00001
|
266
268
|
end
|
267
269
|
|
268
270
|
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"
|
271
|
+
_(6 * 7.0).wont_be_within_epsilon 42, 0.00001, "msg"
|
270
272
|
end
|
271
273
|
end
|
272
274
|
|
273
275
|
it "needs to verify floats within a delta" do
|
274
276
|
@assertion_count += 1 # extra test
|
275
277
|
|
276
|
-
(6.0 * 7).must_be_close_to(42.0).must_equal true
|
278
|
+
_(_(6.0 * 7).must_be_close_to(42.0)).must_equal true
|
277
279
|
|
278
280
|
assert_triggered "Expected |0.0 - 0.01| (0.01) to be <= 0.001." do
|
279
|
-
(1.0 / 100).must_be_close_to 0.0
|
281
|
+
_(1.0 / 100).must_be_close_to 0.0
|
280
282
|
end
|
281
283
|
|
282
284
|
x = maglev? ? "9.9999999999999995e-07" : "1.0e-06"
|
283
285
|
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
|
286
|
+
_(1.0 / 1000).must_be_close_to 0.0, 0.000001
|
285
287
|
end
|
286
288
|
|
287
289
|
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"
|
290
|
+
_(1.0 / 1000).must_be_close_to 0.0, 0.000001, "msg"
|
289
291
|
end
|
290
292
|
end
|
291
293
|
|
292
294
|
it "needs to verify floats within an epsilon" do
|
293
295
|
@assertion_count += 1 # extra test
|
294
296
|
|
295
|
-
(6.0 * 7).must_be_within_epsilon(42.0).must_equal true
|
297
|
+
_(_(6.0 * 7).must_be_within_epsilon(42.0)).must_equal true
|
296
298
|
|
297
299
|
assert_triggered "Expected |0.0 - 0.01| (0.01) to be <= 0.0." do
|
298
|
-
(1.0 / 100).must_be_within_epsilon 0.0
|
300
|
+
_(1.0 / 100).must_be_within_epsilon 0.0
|
299
301
|
end
|
300
302
|
|
301
303
|
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
|
304
|
+
_(1.0 / 1000).must_be_within_epsilon 0.0, 0.000001
|
303
305
|
end
|
304
306
|
|
305
307
|
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"
|
308
|
+
_(1.0 / 1000).must_be_within_epsilon 0.0, 0.000001, "msg"
|
307
309
|
end
|
308
310
|
end
|
309
311
|
|
310
312
|
it "needs to verify identity" do
|
311
|
-
1.must_be_same_as(1).must_equal true
|
313
|
+
_(_(1).must_be_same_as(1)).must_equal true
|
312
314
|
|
313
315
|
assert_triggered "Expected 1 (oid=N) to be the same as 2 (oid=N)." do
|
314
|
-
1.must_be_same_as 2
|
316
|
+
_(1).must_be_same_as 2
|
315
317
|
end
|
316
318
|
|
317
319
|
assert_triggered "msg.\nExpected 1 (oid=N) to be the same as 2 (oid=N)." do
|
318
|
-
1.must_be_same_as 2, "msg"
|
320
|
+
_(1).must_be_same_as 2, "msg"
|
319
321
|
end
|
320
322
|
end
|
321
323
|
|
322
324
|
it "needs to verify inequality" do
|
323
325
|
@assertion_count += 2
|
324
|
-
42.wont_equal(6 * 9).must_equal false
|
325
|
-
proc {}.wont_equal(42).must_equal false
|
326
|
+
_(_(42).wont_equal(6 * 9)).must_equal false
|
327
|
+
_(_(proc {}).wont_equal(42)).must_equal false
|
326
328
|
|
327
329
|
assert_triggered "Expected 1 to not be equal to 1." do
|
328
|
-
1.wont_equal 1
|
330
|
+
_(1).wont_equal 1
|
329
331
|
end
|
330
332
|
|
331
333
|
assert_triggered "msg.\nExpected 1 to not be equal to 1." do
|
332
|
-
1.wont_equal 1, "msg"
|
334
|
+
_(1).wont_equal 1, "msg"
|
333
335
|
end
|
334
336
|
end
|
335
337
|
|
336
338
|
it "needs to verify instances of a class" do
|
337
|
-
42.wont_be_instance_of(String).must_equal false
|
339
|
+
_(_(42).wont_be_instance_of(String)).must_equal false
|
338
340
|
|
339
341
|
assert_triggered "Expected 42 to not be a kind of #{Int.name}." do
|
340
|
-
42.wont_be_kind_of Int
|
342
|
+
_(42).wont_be_kind_of Int
|
341
343
|
end
|
342
344
|
|
343
345
|
assert_triggered "msg.\nExpected 42 to not be an instance of #{Int.name}." do
|
344
|
-
42.wont_be_instance_of Int, "msg"
|
346
|
+
_(42).wont_be_instance_of Int, "msg"
|
345
347
|
end
|
346
348
|
end
|
347
349
|
|
348
350
|
it "needs to verify kinds of a class" do
|
349
351
|
@assertion_count += 2
|
350
352
|
|
351
|
-
42.wont_be_kind_of(String).must_equal false
|
352
|
-
proc {}.wont_be_kind_of(String).must_equal false
|
353
|
+
_(_(42).wont_be_kind_of(String)).must_equal false
|
354
|
+
_(_(proc {}).wont_be_kind_of(String)).must_equal false
|
353
355
|
|
354
356
|
assert_triggered "Expected 42 to not be a kind of #{Int.name}." do
|
355
|
-
42.wont_be_kind_of Int
|
357
|
+
_(42).wont_be_kind_of Int
|
356
358
|
end
|
357
359
|
|
358
360
|
assert_triggered "msg.\nExpected 42 to not be a kind of #{Int.name}." do
|
359
|
-
42.wont_be_kind_of Int, "msg"
|
361
|
+
_(42).wont_be_kind_of Int, "msg"
|
360
362
|
end
|
361
363
|
end
|
362
364
|
|
363
365
|
it "needs to verify kinds of objects" do
|
364
366
|
@assertion_count += 3 # extra test
|
365
367
|
|
366
|
-
(6 * 7).must_be_kind_of(Int).must_equal true
|
367
|
-
(6 * 7).must_be_kind_of(Numeric).must_equal true
|
368
|
+
_(_(6 * 7).must_be_kind_of(Int)).must_equal true
|
369
|
+
_(_(6 * 7).must_be_kind_of(Numeric)).must_equal true
|
368
370
|
|
369
371
|
assert_triggered "Expected 42 to be a kind of String, not #{Int.name}." do
|
370
|
-
(6 * 7).must_be_kind_of String
|
372
|
+
_(6 * 7).must_be_kind_of String
|
371
373
|
end
|
372
374
|
|
373
375
|
assert_triggered "msg.\nExpected 42 to be a kind of String, not #{Int.name}." do
|
374
|
-
(6 * 7).must_be_kind_of String, "msg"
|
376
|
+
_(6 * 7).must_be_kind_of String, "msg"
|
375
377
|
end
|
376
378
|
|
377
379
|
exp = "Expected #<Proc:0xXXXXXX@PATH> to be a kind of String, not Proc."
|
378
380
|
assert_triggered exp do
|
379
|
-
proc {}.must_be_kind_of String
|
381
|
+
_(proc {}).must_be_kind_of String
|
380
382
|
end
|
381
383
|
end
|
382
384
|
|
383
385
|
it "needs to verify mismatch" do
|
384
386
|
@assertion_count += 3 # match is 2
|
385
387
|
|
386
|
-
"blah".wont_match(/\d+/).must_equal false
|
388
|
+
_(_("blah").wont_match(/\d+/)).must_equal false
|
387
389
|
|
388
390
|
assert_triggered "Expected /\\w+/ to not match \"blah\"." do
|
389
|
-
"blah".wont_match(/\w+/)
|
391
|
+
_("blah").wont_match(/\w+/)
|
390
392
|
end
|
391
393
|
|
392
394
|
assert_triggered "msg.\nExpected /\\w+/ to not match \"blah\"." do
|
393
|
-
"blah".wont_match(/\w+/, "msg")
|
395
|
+
_("blah").wont_match(/\w+/, "msg")
|
394
396
|
end
|
395
397
|
end
|
396
398
|
|
397
399
|
it "needs to verify nil" do
|
398
|
-
nil.must_be_nil.must_equal true
|
400
|
+
_(_(nil).must_be_nil).must_equal true
|
399
401
|
|
400
402
|
assert_triggered "Expected 42 to be nil." do
|
401
|
-
42.must_be_nil
|
403
|
+
_(42).must_be_nil
|
402
404
|
end
|
403
405
|
|
404
406
|
assert_triggered "msg.\nExpected 42 to be nil." do
|
405
|
-
42.must_be_nil "msg"
|
407
|
+
_(42).must_be_nil "msg"
|
406
408
|
end
|
407
409
|
end
|
408
410
|
|
409
411
|
it "needs to verify non-emptyness" do
|
410
412
|
@assertion_count += 3 # empty is 2 assertions
|
411
413
|
|
412
|
-
["some item"].wont_be_empty.must_equal false
|
414
|
+
_(_(["some item"]).wont_be_empty).must_equal false
|
413
415
|
|
414
416
|
assert_triggered "Expected [] to not be empty." do
|
415
|
-
[].wont_be_empty
|
417
|
+
_([]).wont_be_empty
|
416
418
|
end
|
417
419
|
|
418
420
|
assert_triggered "msg.\nExpected [] to not be empty." do
|
419
|
-
[].wont_be_empty "msg"
|
421
|
+
_([]).wont_be_empty "msg"
|
420
422
|
end
|
421
423
|
end
|
422
424
|
|
423
425
|
it "needs to verify non-identity" do
|
424
|
-
1.wont_be_same_as(2).must_equal false
|
426
|
+
_(_(1).wont_be_same_as(2)).must_equal false
|
425
427
|
|
426
428
|
assert_triggered "Expected 1 (oid=N) to not be the same as 1 (oid=N)." do
|
427
|
-
1.wont_be_same_as 1
|
429
|
+
_(1).wont_be_same_as 1
|
428
430
|
end
|
429
431
|
|
430
432
|
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"
|
433
|
+
_(1).wont_be_same_as 1, "msg"
|
432
434
|
end
|
433
435
|
end
|
434
436
|
|
435
437
|
it "needs to verify non-nil" do
|
436
|
-
42.wont_be_nil.must_equal false
|
438
|
+
_(_(42).wont_be_nil).must_equal false
|
437
439
|
|
438
440
|
assert_triggered "Expected nil to not be nil." do
|
439
|
-
nil.wont_be_nil
|
441
|
+
_(nil).wont_be_nil
|
440
442
|
end
|
441
443
|
|
442
444
|
assert_triggered "msg.\nExpected nil to not be nil." do
|
443
|
-
nil.wont_be_nil "msg"
|
445
|
+
_(nil).wont_be_nil "msg"
|
444
446
|
end
|
445
447
|
end
|
446
448
|
|
447
449
|
it "needs to verify objects not responding to a message" do
|
448
|
-
"".wont_respond_to(:woot!).must_equal false
|
450
|
+
_(_("").wont_respond_to(:woot!)).must_equal false
|
449
451
|
|
450
452
|
assert_triggered "Expected \"\" to not respond to to_s." do
|
451
|
-
"".wont_respond_to :to_s
|
453
|
+
_("").wont_respond_to :to_s
|
452
454
|
end
|
453
455
|
|
454
456
|
assert_triggered "msg.\nExpected \"\" to not respond to to_s." do
|
455
|
-
"".wont_respond_to :to_s, "msg"
|
457
|
+
_("").wont_respond_to :to_s, "msg"
|
456
458
|
end
|
457
459
|
end
|
458
460
|
|
459
461
|
it "needs to verify output in stderr" do
|
460
462
|
@assertion_count -= 1 # no msg
|
461
463
|
|
462
|
-
|
464
|
+
_(expect { $stderr.print "blah" }.must_output(nil, "blah")).must_equal true
|
463
465
|
|
464
466
|
assert_triggered "In stderr.\nExpected: \"blah\"\n Actual: \"xxx\"" do
|
465
|
-
|
467
|
+
expect { $stderr.print "xxx" }.must_output(nil, "blah")
|
466
468
|
end
|
467
469
|
end
|
468
470
|
|
469
471
|
it "needs to verify output in stdout" do
|
470
472
|
@assertion_count -= 1 # no msg
|
471
473
|
|
472
|
-
|
474
|
+
_(expect { print "blah" }.must_output("blah")).must_equal true
|
473
475
|
|
474
476
|
assert_triggered "In stdout.\nExpected: \"blah\"\n Actual: \"xxx\"" do
|
475
|
-
|
477
|
+
expect { print "xxx" }.must_output("blah")
|
476
478
|
end
|
477
479
|
end
|
478
480
|
|
479
481
|
it "needs to verify regexp matches" do
|
480
482
|
@assertion_count += 3 # must_match is 2 assertions
|
481
483
|
|
482
|
-
"blah".must_match(/\w+/).must_equal true
|
484
|
+
_(_("blah").must_match(/\w+/)).must_equal true
|
483
485
|
|
484
486
|
assert_triggered "Expected /\\d+/ to match \"blah\"." do
|
485
|
-
"blah".must_match(/\d+/)
|
487
|
+
_("blah").must_match(/\d+/)
|
486
488
|
end
|
487
489
|
|
488
490
|
assert_triggered "msg.\nExpected /\\d+/ to match \"blah\"." do
|
489
|
-
"blah".must_match(/\d+/, "msg")
|
491
|
+
_("blah").must_match(/\d+/, "msg")
|
490
492
|
end
|
491
493
|
end
|
492
494
|
|
@@ -508,8 +510,41 @@ describe Minitest::Spec do
|
|
508
510
|
end
|
509
511
|
|
510
512
|
it "can NOT use must_equal in a thread. It must use expect in a thread" do
|
511
|
-
|
512
|
-
|
513
|
+
skip "N/A" if ENV["MT_NO_EXPECTATIONS"]
|
514
|
+
assert_raises RuntimeError do
|
515
|
+
capture_io do
|
516
|
+
Thread.new { (1 + 1).must_equal 2 }.join
|
517
|
+
end
|
518
|
+
end
|
519
|
+
end
|
520
|
+
|
521
|
+
it "fails gracefully when expectation used outside of `it`" do
|
522
|
+
skip "N/A" if ENV["MT_NO_EXPECTATIONS"]
|
523
|
+
|
524
|
+
@assertion_count += 1
|
525
|
+
|
526
|
+
e = assert_raises RuntimeError do
|
527
|
+
capture_io do
|
528
|
+
Thread.new { # forces ctx to be nil
|
529
|
+
describe("woot") do
|
530
|
+
(1 + 1).must_equal 2
|
531
|
+
end
|
532
|
+
}.join
|
533
|
+
end
|
534
|
+
end
|
535
|
+
|
536
|
+
assert_equal "Calling #must_equal outside of test.", e.message
|
537
|
+
end
|
538
|
+
|
539
|
+
it "deprecates expectation used without _" do
|
540
|
+
skip "N/A" if ENV["MT_NO_EXPECTATIONS"]
|
541
|
+
|
542
|
+
@assertion_count += 3
|
543
|
+
|
544
|
+
exp = /DEPRECATED: global use of must_equal from/
|
545
|
+
|
546
|
+
assert_output "", exp do
|
547
|
+
(1 + 1).must_equal 2
|
513
548
|
end
|
514
549
|
end
|
515
550
|
end
|
@@ -517,78 +552,78 @@ describe Minitest::Spec do
|
|
517
552
|
it "needs to verify throw" do
|
518
553
|
@assertion_count += 2 # 2 extra tests
|
519
554
|
|
520
|
-
|
555
|
+
_(expect { throw :blah }.must_throw(:blah)).must_equal true
|
521
556
|
|
522
557
|
assert_triggered "Expected :blah to have been thrown." do
|
523
|
-
|
558
|
+
expect {}.must_throw :blah
|
524
559
|
end
|
525
560
|
|
526
561
|
assert_triggered "Expected :blah to have been thrown, not :xxx." do
|
527
|
-
|
562
|
+
expect { throw :xxx }.must_throw :blah
|
528
563
|
end
|
529
564
|
|
530
565
|
assert_triggered "msg.\nExpected :blah to have been thrown." do
|
531
|
-
|
566
|
+
expect {}.must_throw :blah, "msg"
|
532
567
|
end
|
533
568
|
|
534
569
|
assert_triggered "msg.\nExpected :blah to have been thrown, not :xxx." do
|
535
|
-
|
570
|
+
expect { throw :xxx }.must_throw :blah, "msg"
|
536
571
|
end
|
537
572
|
end
|
538
573
|
|
539
574
|
it "needs to verify types of objects" do
|
540
|
-
(6 * 7).must_be_instance_of(Int).must_equal true
|
575
|
+
_(_(6 * 7).must_be_instance_of(Int)).must_equal true
|
541
576
|
|
542
577
|
exp = "Expected 42 to be an instance of String, not #{Int.name}."
|
543
578
|
|
544
579
|
assert_triggered exp do
|
545
|
-
(6 * 7).must_be_instance_of String
|
580
|
+
_(6 * 7).must_be_instance_of String
|
546
581
|
end
|
547
582
|
|
548
583
|
assert_triggered "msg.\n#{exp}" do
|
549
|
-
(6 * 7).must_be_instance_of String, "msg"
|
584
|
+
_(6 * 7).must_be_instance_of String, "msg"
|
550
585
|
end
|
551
586
|
end
|
552
587
|
|
553
588
|
it "needs to verify using any (negative) predicate" do
|
554
589
|
@assertion_count -= 1 # doesn"t take a message
|
555
590
|
|
556
|
-
"blah".wont_be(:empty?).must_equal false
|
591
|
+
_(_("blah").wont_be(:empty?)).must_equal false
|
557
592
|
|
558
593
|
assert_triggered "Expected \"\" to not be empty?." do
|
559
|
-
"".wont_be :empty?
|
594
|
+
_("").wont_be :empty?
|
560
595
|
end
|
561
596
|
end
|
562
597
|
|
563
598
|
it "needs to verify using any binary operator" do
|
564
599
|
@assertion_count -= 1 # no msg
|
565
600
|
|
566
|
-
41.must_be(:<, 42).must_equal true
|
601
|
+
_(_(41).must_be(:<, 42)).must_equal true
|
567
602
|
|
568
603
|
assert_triggered "Expected 42 to be < 41." do
|
569
|
-
42.must_be(:<, 41)
|
604
|
+
_(42).must_be(:<, 41)
|
570
605
|
end
|
571
606
|
end
|
572
607
|
|
573
608
|
it "needs to verify using any predicate" do
|
574
609
|
@assertion_count -= 1 # no msg
|
575
610
|
|
576
|
-
"".must_be(:empty?).must_equal true
|
611
|
+
_(_("").must_be(:empty?)).must_equal true
|
577
612
|
|
578
613
|
assert_triggered "Expected \"blah\" to be empty?." do
|
579
|
-
"blah".must_be :empty?
|
614
|
+
_("blah").must_be :empty?
|
580
615
|
end
|
581
616
|
end
|
582
617
|
|
583
618
|
it "needs to verify using respond_to" do
|
584
|
-
42.must_respond_to(:+).must_equal true
|
619
|
+
_(_(42).must_respond_to(:+)).must_equal true
|
585
620
|
|
586
621
|
assert_triggered "Expected 42 (#{Int.name}) to respond to #clear." do
|
587
|
-
42.must_respond_to :clear
|
622
|
+
_(42).must_respond_to :clear
|
588
623
|
end
|
589
624
|
|
590
625
|
assert_triggered "msg.\nExpected 42 (#{Int.name}) to respond to #clear." do
|
591
|
-
42.must_respond_to :clear, "msg"
|
626
|
+
_(42).must_respond_to :clear, "msg"
|
592
627
|
end
|
593
628
|
end
|
594
629
|
end
|
@@ -606,33 +641,33 @@ describe Minitest::Spec, :let do
|
|
606
641
|
end
|
607
642
|
|
608
643
|
it "is evaluated once per example" do
|
609
|
-
_count.must_equal 0
|
644
|
+
_(_count).must_equal 0
|
610
645
|
|
611
|
-
count.must_equal 1
|
612
|
-
count.must_equal 1
|
646
|
+
_(count).must_equal 1
|
647
|
+
_(count).must_equal 1
|
613
648
|
|
614
|
-
_count.must_equal 1
|
649
|
+
_(_count).must_equal 1
|
615
650
|
end
|
616
651
|
|
617
652
|
it "is REALLY evaluated once per example" do
|
618
|
-
_count.must_equal 1
|
653
|
+
_(_count).must_equal 1
|
619
654
|
|
620
|
-
count.must_equal 2
|
621
|
-
count.must_equal 2
|
655
|
+
_(count).must_equal 2
|
656
|
+
_(count).must_equal 2
|
622
657
|
|
623
|
-
_count.must_equal 2
|
658
|
+
_(_count).must_equal 2
|
624
659
|
end
|
625
660
|
|
626
661
|
it 'raises an error if the name begins with "test"' do
|
627
|
-
|
662
|
+
expect { self.class.let(:test_value) { true } }.must_raise ArgumentError
|
628
663
|
end
|
629
664
|
|
630
665
|
it "raises an error if the name shadows a normal instance method" do
|
631
|
-
|
666
|
+
expect { self.class.let(:message) { true } }.must_raise ArgumentError
|
632
667
|
end
|
633
668
|
|
634
669
|
it "doesn't raise an error if it is just another let" do
|
635
|
-
proc do
|
670
|
+
v = proc do
|
636
671
|
describe :outer do
|
637
672
|
let(:bar)
|
638
673
|
describe :inner do
|
@@ -640,13 +675,14 @@ describe Minitest::Spec, :let do
|
|
640
675
|
end
|
641
676
|
end
|
642
677
|
:good
|
643
|
-
end.call
|
678
|
+
end.call
|
679
|
+
_(v).must_equal :good
|
644
680
|
end
|
645
681
|
|
646
682
|
it "procs come after dont_flip" do
|
647
683
|
p = proc {}
|
648
684
|
assert_respond_to p, :call
|
649
|
-
p.must_respond_to :call
|
685
|
+
_(p).must_respond_to :call
|
650
686
|
end
|
651
687
|
end
|
652
688
|
|
@@ -660,9 +696,9 @@ describe Minitest::Spec, :subject do
|
|
660
696
|
end
|
661
697
|
|
662
698
|
it "is evaluated once per example" do
|
663
|
-
subject.must_equal 1
|
664
|
-
subject.must_equal 1
|
665
|
-
subject_evaluation_count.must_equal 1
|
699
|
+
_(subject).must_equal 1
|
700
|
+
_(subject).must_equal 1
|
701
|
+
_(subject_evaluation_count).must_equal 1
|
666
702
|
end
|
667
703
|
end
|
668
704
|
|
@@ -720,10 +756,8 @@ class TestMetaStatic < Minitest::Test
|
|
720
756
|
end
|
721
757
|
end
|
722
758
|
|
723
|
-
require "minitest/metametameta"
|
724
|
-
|
725
759
|
class TestMeta < MetaMetaMetaTestCase
|
726
|
-
parallelize_me!
|
760
|
+
# do not call parallelize_me! here because specs use register_spec_type globally
|
727
761
|
|
728
762
|
def util_structure
|
729
763
|
y = z = nil
|
@@ -793,7 +827,7 @@ class TestMeta < MetaMetaMetaTestCase
|
|
793
827
|
def test_bug_dsl_expectations
|
794
828
|
spec_class = Class.new MiniSpecB do
|
795
829
|
it "should work" do
|
796
|
-
0.must_equal 0
|
830
|
+
_(0).must_equal 0
|
797
831
|
end
|
798
832
|
end
|
799
833
|
|
@@ -945,18 +979,20 @@ class TestSpecInTestCase < MetaMetaMetaTestCase
|
|
945
979
|
end
|
946
980
|
|
947
981
|
def test_expectation
|
948
|
-
@tc.assert_equal true, 1.must_equal(1)
|
982
|
+
@tc.assert_equal true, _(1).must_equal(1)
|
949
983
|
end
|
950
984
|
|
951
985
|
def test_expectation_triggered
|
952
986
|
assert_triggered "Expected: 2\n Actual: 1" do
|
953
|
-
1.must_equal 2
|
987
|
+
_(1).must_equal 2
|
954
988
|
end
|
955
989
|
end
|
956
990
|
|
991
|
+
include Minitest::Spec::DSL::InstanceMethods
|
992
|
+
|
957
993
|
def test_expectation_with_a_message
|
958
994
|
assert_triggered "woot.\nExpected: 2\n Actual: 1" do
|
959
|
-
1.must_equal 2, "woot"
|
995
|
+
_(1).must_equal 2, "woot"
|
960
996
|
end
|
961
997
|
end
|
962
998
|
end
|