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