minitest 5.10.3 → 5.15.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 +5 -5
- checksums.yaml.gz.sig +0 -0
- data/History.rdoc +193 -4
- data/Manifest.txt +1 -0
- data/README.rdoc +87 -14
- data/Rakefile +4 -16
- data/lib/hoe/minitest.rb +0 -4
- data/lib/minitest/assertions.rb +145 -32
- data/lib/minitest/benchmark.rb +34 -3
- data/lib/minitest/expectations.rb +54 -35
- data/lib/minitest/mock.rb +11 -10
- data/lib/minitest/parallel.rb +1 -1
- data/lib/minitest/spec.rb +20 -8
- data/lib/minitest/test.rb +15 -69
- data/lib/minitest.rb +241 -31
- data/test/minitest/metametameta.rb +43 -8
- data/test/minitest/test_minitest_assertions.rb +1588 -0
- data/test/minitest/test_minitest_mock.rb +380 -7
- data/test/minitest/test_minitest_reporter.rb +45 -21
- data/test/minitest/test_minitest_spec.rb +220 -143
- data/test/minitest/test_minitest_test.rb +119 -1120
- data.tar.gz.sig +0 -0
- metadata +34 -24
- metadata.gz.sig +0 -0
@@ -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
|
@@ -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)
|
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)
|
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
|
-
|
95
|
-
|
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
|
-
|
132
|
+
expect { raise StandardError, "woot" }.must_raise RuntimeError
|
110
133
|
end
|
111
134
|
|
112
135
|
assert_triggered "msg.\n#{msg}" do
|
113
|
-
|
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
|
-
|
144
|
+
assert_success expect {}.must_be_silent
|
122
145
|
|
123
146
|
assert_triggered "In stdout.\nExpected: \"\"\n Actual: \"xxx\"" do
|
124
|
-
|
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 =
|
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 =~
|
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(
|
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
|
-
|
193
|
+
expect { 42 }.must_raise RuntimeError
|
168
194
|
end
|
169
195
|
|
170
196
|
assert_triggered "msg.\nRuntimeError expected but nothing was raised." do
|
171
|
-
|
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)
|
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
|
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)
|
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)
|
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)
|
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 =
|
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)
|
282
|
+
assert_success _(24).wont_be_within_epsilon(42)
|
257
283
|
|
258
|
-
x =
|
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 =
|
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)
|
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 =
|
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)
|
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)
|
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)
|
325
|
-
proc {}.wont_equal(42)
|
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)
|
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)
|
352
|
-
proc {}.wont_be_kind_of(String)
|
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)
|
367
|
-
(6 * 7).must_be_kind_of(Numeric)
|
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+/)
|
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
|
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
|
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)
|
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
|
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!)
|
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
|
-
|
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
|
-
|
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
|
-
|
498
|
+
assert_success expect { print "blah" }.must_output("blah")
|
473
499
|
|
474
500
|
assert_triggered "In stdout.\nExpected: \"blah\"\n Actual: \"xxx\"" do
|
475
|
-
|
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+/)
|
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,87 +534,137 @@ 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
|
-
|
512
|
-
|
537
|
+
skip "N/A" if ENV["MT_NO_EXPECTATIONS"]
|
538
|
+
assert_raises RuntimeError do
|
539
|
+
capture_io do
|
540
|
+
Thread.new { (1 + 1).must_equal 2 }.join
|
541
|
+
end
|
542
|
+
end
|
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
|
513
588
|
end
|
514
589
|
end
|
515
590
|
end
|
516
591
|
|
517
592
|
it "needs to verify throw" do
|
518
|
-
@assertion_count +=
|
593
|
+
@assertion_count += 4 # 2 extra tests
|
519
594
|
|
520
|
-
|
595
|
+
assert_nil expect { throw :blah }.must_throw(:blah)
|
596
|
+
assert_equal 42, expect { throw :blah, 42 }.must_throw(:blah)
|
521
597
|
|
522
598
|
assert_triggered "Expected :blah to have been thrown." do
|
523
|
-
|
599
|
+
expect {}.must_throw :blah
|
524
600
|
end
|
525
601
|
|
526
602
|
assert_triggered "Expected :blah to have been thrown, not :xxx." do
|
527
|
-
|
603
|
+
expect { throw :xxx }.must_throw :blah
|
528
604
|
end
|
529
605
|
|
530
606
|
assert_triggered "msg.\nExpected :blah to have been thrown." do
|
531
|
-
|
607
|
+
expect {}.must_throw :blah, "msg"
|
532
608
|
end
|
533
609
|
|
534
610
|
assert_triggered "msg.\nExpected :blah to have been thrown, not :xxx." do
|
535
|
-
|
611
|
+
expect { throw :xxx }.must_throw :blah, "msg"
|
536
612
|
end
|
537
613
|
end
|
538
614
|
|
539
615
|
it "needs to verify types of objects" do
|
540
|
-
(6 * 7).must_be_instance_of(Int)
|
616
|
+
assert_success _(6 * 7).must_be_instance_of(Int)
|
541
617
|
|
542
618
|
exp = "Expected 42 to be an instance of String, not #{Int.name}."
|
543
619
|
|
544
620
|
assert_triggered exp do
|
545
|
-
(6 * 7).must_be_instance_of String
|
621
|
+
_(6 * 7).must_be_instance_of String
|
546
622
|
end
|
547
623
|
|
548
624
|
assert_triggered "msg.\n#{exp}" do
|
549
|
-
(6 * 7).must_be_instance_of String, "msg"
|
625
|
+
_(6 * 7).must_be_instance_of String, "msg"
|
550
626
|
end
|
551
627
|
end
|
552
628
|
|
553
629
|
it "needs to verify using any (negative) predicate" do
|
554
630
|
@assertion_count -= 1 # doesn"t take a message
|
555
631
|
|
556
|
-
"blah".wont_be(:empty?)
|
632
|
+
assert_success _("blah").wont_be(:empty?)
|
557
633
|
|
558
634
|
assert_triggered "Expected \"\" to not be empty?." do
|
559
|
-
"".wont_be :empty?
|
635
|
+
_("").wont_be :empty?
|
560
636
|
end
|
561
637
|
end
|
562
638
|
|
563
639
|
it "needs to verify using any binary operator" do
|
564
640
|
@assertion_count -= 1 # no msg
|
565
641
|
|
566
|
-
41.must_be(:<, 42)
|
642
|
+
assert_success _(41).must_be(:<, 42)
|
567
643
|
|
568
644
|
assert_triggered "Expected 42 to be < 41." do
|
569
|
-
42.must_be(:<, 41)
|
645
|
+
_(42).must_be(:<, 41)
|
570
646
|
end
|
571
647
|
end
|
572
648
|
|
573
649
|
it "needs to verify using any predicate" do
|
574
650
|
@assertion_count -= 1 # no msg
|
575
651
|
|
576
|
-
"".must_be(:empty?)
|
652
|
+
assert_success _("").must_be(:empty?)
|
577
653
|
|
578
654
|
assert_triggered "Expected \"blah\" to be empty?." do
|
579
|
-
"blah".must_be :empty?
|
655
|
+
_("blah").must_be :empty?
|
580
656
|
end
|
581
657
|
end
|
582
658
|
|
583
659
|
it "needs to verify using respond_to" do
|
584
|
-
42.must_respond_to(:+)
|
660
|
+
assert_success _(42).must_respond_to(:+)
|
585
661
|
|
586
662
|
assert_triggered "Expected 42 (#{Int.name}) to respond to #clear." do
|
587
|
-
42.must_respond_to :clear
|
663
|
+
_(42).must_respond_to :clear
|
588
664
|
end
|
589
665
|
|
590
666
|
assert_triggered "msg.\nExpected 42 (#{Int.name}) to respond to #clear." do
|
591
|
-
42.must_respond_to :clear, "msg"
|
667
|
+
_(42).must_respond_to :clear, "msg"
|
592
668
|
end
|
593
669
|
end
|
594
670
|
end
|
@@ -606,33 +682,33 @@ describe Minitest::Spec, :let do
|
|
606
682
|
end
|
607
683
|
|
608
684
|
it "is evaluated once per example" do
|
609
|
-
_count.must_equal 0
|
685
|
+
_(_count).must_equal 0
|
610
686
|
|
611
|
-
count.must_equal 1
|
612
|
-
count.must_equal 1
|
687
|
+
_(count).must_equal 1
|
688
|
+
_(count).must_equal 1
|
613
689
|
|
614
|
-
_count.must_equal 1
|
690
|
+
_(_count).must_equal 1
|
615
691
|
end
|
616
692
|
|
617
693
|
it "is REALLY evaluated once per example" do
|
618
|
-
_count.must_equal 1
|
694
|
+
_(_count).must_equal 1
|
619
695
|
|
620
|
-
count.must_equal 2
|
621
|
-
count.must_equal 2
|
696
|
+
_(count).must_equal 2
|
697
|
+
_(count).must_equal 2
|
622
698
|
|
623
|
-
_count.must_equal 2
|
699
|
+
_(_count).must_equal 2
|
624
700
|
end
|
625
701
|
|
626
702
|
it 'raises an error if the name begins with "test"' do
|
627
|
-
|
703
|
+
expect { self.class.let(:test_value) { true } }.must_raise ArgumentError
|
628
704
|
end
|
629
705
|
|
630
706
|
it "raises an error if the name shadows a normal instance method" do
|
631
|
-
|
707
|
+
expect { self.class.let(:message) { true } }.must_raise ArgumentError
|
632
708
|
end
|
633
709
|
|
634
710
|
it "doesn't raise an error if it is just another let" do
|
635
|
-
proc do
|
711
|
+
v = proc do
|
636
712
|
describe :outer do
|
637
713
|
let(:bar)
|
638
714
|
describe :inner do
|
@@ -640,13 +716,14 @@ describe Minitest::Spec, :let do
|
|
640
716
|
end
|
641
717
|
end
|
642
718
|
:good
|
643
|
-
end.call
|
719
|
+
end.call
|
720
|
+
_(v).must_equal :good
|
644
721
|
end
|
645
722
|
|
646
723
|
it "procs come after dont_flip" do
|
647
724
|
p = proc {}
|
648
725
|
assert_respond_to p, :call
|
649
|
-
p.must_respond_to :call
|
726
|
+
_(p).must_respond_to :call
|
650
727
|
end
|
651
728
|
end
|
652
729
|
|
@@ -660,9 +737,9 @@ describe Minitest::Spec, :subject do
|
|
660
737
|
end
|
661
738
|
|
662
739
|
it "is evaluated once per example" do
|
663
|
-
subject.must_equal 1
|
664
|
-
subject.must_equal 1
|
665
|
-
subject_evaluation_count.must_equal 1
|
740
|
+
_(subject).must_equal 1
|
741
|
+
_(subject).must_equal 1
|
742
|
+
_(subject_evaluation_count).must_equal 1
|
666
743
|
end
|
667
744
|
end
|
668
745
|
|
@@ -720,10 +797,8 @@ class TestMetaStatic < Minitest::Test
|
|
720
797
|
end
|
721
798
|
end
|
722
799
|
|
723
|
-
require "minitest/metametameta"
|
724
|
-
|
725
800
|
class TestMeta < MetaMetaMetaTestCase
|
726
|
-
parallelize_me!
|
801
|
+
# do not call parallelize_me! here because specs use register_spec_type globally
|
727
802
|
|
728
803
|
def util_structure
|
729
804
|
y = z = nil
|
@@ -793,7 +868,7 @@ class TestMeta < MetaMetaMetaTestCase
|
|
793
868
|
def test_bug_dsl_expectations
|
794
869
|
spec_class = Class.new MiniSpecB do
|
795
870
|
it "should work" do
|
796
|
-
0.must_equal 0
|
871
|
+
_(0).must_equal 0
|
797
872
|
end
|
798
873
|
end
|
799
874
|
|
@@ -945,18 +1020,20 @@ class TestSpecInTestCase < MetaMetaMetaTestCase
|
|
945
1020
|
end
|
946
1021
|
|
947
1022
|
def test_expectation
|
948
|
-
@tc.assert_equal true, 1.must_equal(1)
|
1023
|
+
@tc.assert_equal true, _(1).must_equal(1)
|
949
1024
|
end
|
950
1025
|
|
951
1026
|
def test_expectation_triggered
|
952
1027
|
assert_triggered "Expected: 2\n Actual: 1" do
|
953
|
-
1.must_equal 2
|
1028
|
+
_(1).must_equal 2
|
954
1029
|
end
|
955
1030
|
end
|
956
1031
|
|
1032
|
+
include Minitest::Spec::DSL::InstanceMethods
|
1033
|
+
|
957
1034
|
def test_expectation_with_a_message
|
958
1035
|
assert_triggered "woot.\nExpected: 2\n Actual: 1" do
|
959
|
-
1.must_equal 2, "woot"
|
1036
|
+
_(1).must_equal 2, "woot"
|
960
1037
|
end
|
961
1038
|
end
|
962
1039
|
end
|