minitest 5.20.0 → 5.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +4 -4
- data/History.rdoc +206 -3
- data/Manifest.txt +3 -0
- data/README.rdoc +30 -17
- data/Rakefile +24 -2
- data/design_rationale.rb +21 -19
- data/lib/hoe/minitest.rb +4 -2
- data/lib/minitest/assertions.rb +92 -100
- data/lib/minitest/autorun.rb +4 -11
- data/lib/minitest/benchmark.rb +8 -11
- data/lib/minitest/compress.rb +94 -0
- data/lib/minitest/error_on_warning.rb +11 -0
- data/lib/minitest/expectations.rb +2 -2
- data/lib/minitest/hell.rb +1 -1
- data/lib/minitest/manual_plugins.rb +16 -0
- data/lib/minitest/mock.rb +44 -44
- data/lib/minitest/parallel.rb +7 -5
- data/lib/minitest/pride.rb +1 -1
- data/lib/minitest/pride_plugin.rb +17 -24
- data/lib/minitest/spec.rb +22 -18
- data/lib/minitest/test.rb +19 -29
- data/lib/minitest/test_task.rb +45 -23
- data/lib/minitest/unit.rb +1 -1
- data/lib/minitest.rb +289 -160
- data/test/minitest/metametameta.rb +32 -18
- data/test/minitest/test_minitest_assertions.rb +173 -197
- data/test/minitest/test_minitest_benchmark.rb +1 -1
- data/test/minitest/test_minitest_mock.rb +156 -89
- data/test/minitest/test_minitest_reporter.rb +120 -24
- data/test/minitest/test_minitest_spec.rb +95 -82
- data/test/minitest/test_minitest_test.rb +212 -120
- data/test/minitest/test_minitest_test_task.rb +18 -7
- data.tar.gz.sig +0 -0
- metadata +36 -22
- metadata.gz.sig +0 -0
|
@@ -10,8 +10,9 @@ end
|
|
|
10
10
|
|
|
11
11
|
class TestMinitestMock < Minitest::Test
|
|
12
12
|
def setup
|
|
13
|
-
@mock = Minitest::Mock.new
|
|
14
|
-
|
|
13
|
+
@mock = Minitest::Mock.new
|
|
14
|
+
.expect(:foo, nil)
|
|
15
|
+
.expect(:meaning_of_life, 42)
|
|
15
16
|
end
|
|
16
17
|
|
|
17
18
|
def test_create_stub_method
|
|
@@ -25,7 +26,7 @@ class TestMinitestMock < Minitest::Test
|
|
|
25
26
|
def test_blow_up_if_not_called
|
|
26
27
|
@mock.foo
|
|
27
28
|
|
|
28
|
-
util_verify_bad "
|
|
29
|
+
util_verify_bad "Expected meaning_of_life() => 42"
|
|
29
30
|
end
|
|
30
31
|
|
|
31
32
|
def test_not_blow_up_if_everything_called
|
|
@@ -36,22 +37,22 @@ class TestMinitestMock < Minitest::Test
|
|
|
36
37
|
end
|
|
37
38
|
|
|
38
39
|
def test_allow_expectations_to_be_added_after_creation
|
|
39
|
-
@mock.expect
|
|
40
|
+
@mock.expect :bar, true
|
|
40
41
|
assert @mock.bar
|
|
41
42
|
end
|
|
42
43
|
|
|
43
44
|
def test_not_verify_if_new_expected_method_is_not_called
|
|
44
45
|
@mock.foo
|
|
45
46
|
@mock.meaning_of_life
|
|
46
|
-
@mock.expect
|
|
47
|
+
@mock.expect :bar, true
|
|
47
48
|
|
|
48
|
-
util_verify_bad "
|
|
49
|
+
util_verify_bad "Expected bar() => true"
|
|
49
50
|
end
|
|
50
51
|
|
|
51
52
|
def test_blow_up_on_wrong_number_of_arguments
|
|
52
53
|
@mock.foo
|
|
53
54
|
@mock.meaning_of_life
|
|
54
|
-
@mock.expect
|
|
55
|
+
@mock.expect :sum, 3, [1, 2]
|
|
55
56
|
|
|
56
57
|
e = assert_raises ArgumentError do
|
|
57
58
|
@mock.sum
|
|
@@ -63,7 +64,7 @@ class TestMinitestMock < Minitest::Test
|
|
|
63
64
|
def test_return_mock_does_not_raise
|
|
64
65
|
retval = Minitest::Mock.new
|
|
65
66
|
mock = Minitest::Mock.new
|
|
66
|
-
mock.expect
|
|
67
|
+
mock.expect :foo, retval
|
|
67
68
|
mock.foo
|
|
68
69
|
|
|
69
70
|
assert_mock mock
|
|
@@ -72,8 +73,8 @@ class TestMinitestMock < Minitest::Test
|
|
|
72
73
|
def test_mock_args_does_not_raise
|
|
73
74
|
arg = Minitest::Mock.new
|
|
74
75
|
mock = Minitest::Mock.new
|
|
75
|
-
mock.expect
|
|
76
|
-
mock.foo
|
|
76
|
+
mock.expect :foo, nil, [arg]
|
|
77
|
+
mock.foo arg
|
|
77
78
|
|
|
78
79
|
assert_mock mock
|
|
79
80
|
end
|
|
@@ -113,8 +114,6 @@ class TestMinitestMock < Minitest::Test
|
|
|
113
114
|
end
|
|
114
115
|
|
|
115
116
|
def test_expectations_can_be_satisfied_via_public_send
|
|
116
|
-
skip "Doesn't run on 1.8" if RUBY_VERSION < "1.9"
|
|
117
|
-
|
|
118
117
|
@mock.public_send :foo
|
|
119
118
|
@mock.public_send :meaning_of_life
|
|
120
119
|
|
|
@@ -124,10 +123,10 @@ class TestMinitestMock < Minitest::Test
|
|
|
124
123
|
def test_blow_up_on_wrong_arguments
|
|
125
124
|
@mock.foo
|
|
126
125
|
@mock.meaning_of_life
|
|
127
|
-
@mock.expect
|
|
126
|
+
@mock.expect :sum, 3, [1, 2]
|
|
128
127
|
|
|
129
128
|
e = assert_raises MockExpectationError do
|
|
130
|
-
@mock.sum
|
|
129
|
+
@mock.sum 2, 4
|
|
131
130
|
end
|
|
132
131
|
|
|
133
132
|
exp = "mocked method :sum called with unexpected arguments [2, 4]"
|
|
@@ -163,8 +162,8 @@ class TestMinitestMock < Minitest::Test
|
|
|
163
162
|
a = Minitest::Mock.new
|
|
164
163
|
b = Minitest::Mock.new
|
|
165
164
|
|
|
166
|
-
a.expect
|
|
167
|
-
b.expect
|
|
165
|
+
a.expect :foo, :a
|
|
166
|
+
b.expect :foo, :b
|
|
168
167
|
|
|
169
168
|
assert_equal :a, a.foo
|
|
170
169
|
assert_equal :b, b.foo
|
|
@@ -172,7 +171,7 @@ class TestMinitestMock < Minitest::Test
|
|
|
172
171
|
|
|
173
172
|
def test_do_not_create_stub_method_on_new_mocks
|
|
174
173
|
a = Minitest::Mock.new
|
|
175
|
-
a.expect
|
|
174
|
+
a.expect :foo, :a
|
|
176
175
|
|
|
177
176
|
assert !Minitest::Mock.new.respond_to?(:foo)
|
|
178
177
|
end
|
|
@@ -181,10 +180,77 @@ class TestMinitestMock < Minitest::Test
|
|
|
181
180
|
@mock.expect :kind_of?, true, [String]
|
|
182
181
|
@mock.expect :==, true, [1]
|
|
183
182
|
|
|
184
|
-
assert @mock.kind_of?(String), "didn't mock :kind_of
|
|
183
|
+
assert @mock.kind_of?(String), "didn't mock :kind_of?"
|
|
185
184
|
assert @mock == 1, "didn't mock :=="
|
|
186
185
|
end
|
|
187
186
|
|
|
187
|
+
def test_assert_mock__pass
|
|
188
|
+
mock = Minitest::Mock.new
|
|
189
|
+
mock.expect :loose_expectation, true, [Integer]
|
|
190
|
+
mock.loose_expectation 1
|
|
191
|
+
|
|
192
|
+
result = assert_mock mock
|
|
193
|
+
|
|
194
|
+
assert_equal true, result
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
def assert_bad_mock klass, msg
|
|
198
|
+
mock = Minitest::Mock.new
|
|
199
|
+
mock.expect :foo, nil, [:bar]
|
|
200
|
+
mock.expect :foo, nil, [:baz]
|
|
201
|
+
|
|
202
|
+
mock.foo :bar
|
|
203
|
+
|
|
204
|
+
e = assert_raises klass do
|
|
205
|
+
yield mock
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
assert_equal msg, e.message
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
def test_verify__error
|
|
212
|
+
exp = "Expected foo(:baz) => nil, got [foo(:bar) => nil]"
|
|
213
|
+
assert_bad_mock MockExpectationError, exp do |mock|
|
|
214
|
+
mock.verify
|
|
215
|
+
end
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
def test_assert_mock__fail
|
|
219
|
+
exp = "Expected foo(:baz) => nil, got [foo(:bar) => nil]."
|
|
220
|
+
assert_bad_mock Minitest::Assertion, exp do |mock|
|
|
221
|
+
assert_mock mock
|
|
222
|
+
end
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
def test_assert_mock__fail_msg
|
|
226
|
+
exp = "BLAH.\nExpected foo(:baz) => nil, got [foo(:bar) => nil]."
|
|
227
|
+
assert_bad_mock Minitest::Assertion, exp do |mock|
|
|
228
|
+
assert_mock mock, "BLAH"
|
|
229
|
+
end
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
def test_assert_mock__fail_exp
|
|
233
|
+
exp = "Expected foo(:baz) => nil, got [foo(:bar) => nil]."
|
|
234
|
+
assert_bad_mock Minitest::Assertion, exp do |mock|
|
|
235
|
+
describe "X" do
|
|
236
|
+
it "y" do
|
|
237
|
+
_(mock).must_verify
|
|
238
|
+
end
|
|
239
|
+
end.new(:blah).send(:test_0001_y)
|
|
240
|
+
end
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
def test_assert_mock__fail_exp_msg
|
|
244
|
+
exp = "BLAH.\nExpected foo(:baz) => nil, got [foo(:bar) => nil]."
|
|
245
|
+
assert_bad_mock Minitest::Assertion, exp do |mock|
|
|
246
|
+
describe "X" do
|
|
247
|
+
it "y" do
|
|
248
|
+
_(mock).must_verify "BLAH"
|
|
249
|
+
end
|
|
250
|
+
end.new(:blah).send(:test_0001_y)
|
|
251
|
+
end
|
|
252
|
+
end
|
|
253
|
+
|
|
188
254
|
def test_verify_allows_called_args_to_be_loosely_specified
|
|
189
255
|
mock = Minitest::Mock.new
|
|
190
256
|
mock.expect :loose_expectation, true, [Integer]
|
|
@@ -239,7 +305,7 @@ class TestMinitestMock < Minitest::Test
|
|
|
239
305
|
|
|
240
306
|
e = assert_raises(MockExpectationError) { mock.verify }
|
|
241
307
|
|
|
242
|
-
exp = "
|
|
308
|
+
exp = "Expected foo(:baz) => nil, got [foo(:bar) => nil]"
|
|
243
309
|
|
|
244
310
|
assert_equal exp, e.message
|
|
245
311
|
end
|
|
@@ -253,7 +319,7 @@ class TestMinitestMock < Minitest::Test
|
|
|
253
319
|
|
|
254
320
|
e = assert_raises(MockExpectationError) { mock.verify }
|
|
255
321
|
|
|
256
|
-
exp = "
|
|
322
|
+
exp = "Expected foo(:bar) => nil, got [foo(:bar) => nil]"
|
|
257
323
|
|
|
258
324
|
assert_equal exp, e.message
|
|
259
325
|
end
|
|
@@ -277,9 +343,10 @@ class TestMinitestMock < Minitest::Test
|
|
|
277
343
|
|
|
278
344
|
e = assert_raises(MockExpectationError) { mock.verify }
|
|
279
345
|
|
|
280
|
-
exp = "
|
|
346
|
+
exp = "Expected foo(%p) => nil, got [foo(%p) => nil]" \
|
|
347
|
+
% [{ :kw => false }, { :kw => true }]
|
|
281
348
|
|
|
282
|
-
assert_equal exp, e.message
|
|
349
|
+
assert_equal exp.delete("{}"), e.message
|
|
283
350
|
end
|
|
284
351
|
|
|
285
352
|
def test_verify_passes_when_mock_block_returns_true
|
|
@@ -301,11 +368,7 @@ class TestMinitestMock < Minitest::Test
|
|
|
301
368
|
end
|
|
302
369
|
|
|
303
370
|
assert_silent do
|
|
304
|
-
|
|
305
|
-
mock.foo arg1, arg2, arg3
|
|
306
|
-
else
|
|
307
|
-
mock.foo arg1, arg2, **arg3 # oddity just for ruby 2.7
|
|
308
|
-
end
|
|
371
|
+
mock.foo arg1, arg2, arg3
|
|
309
372
|
end
|
|
310
373
|
|
|
311
374
|
assert_mock mock
|
|
@@ -318,7 +381,7 @@ class TestMinitestMock < Minitest::Test
|
|
|
318
381
|
k1 == arg1 && k2 == arg2 && k3 == arg3
|
|
319
382
|
end
|
|
320
383
|
|
|
321
|
-
mock.foo
|
|
384
|
+
mock.foo k1: arg1, k2: arg2, k3: arg3
|
|
322
385
|
|
|
323
386
|
assert_mock mock
|
|
324
387
|
end
|
|
@@ -331,11 +394,11 @@ class TestMinitestMock < Minitest::Test
|
|
|
331
394
|
end
|
|
332
395
|
|
|
333
396
|
e = assert_raises ArgumentError do
|
|
334
|
-
mock.foo
|
|
397
|
+
mock.foo k1: arg1, k2: arg2
|
|
335
398
|
end
|
|
336
399
|
|
|
337
|
-
# basically testing ruby
|
|
338
|
-
assert_match(/missing keyword:
|
|
400
|
+
# basically testing ruby
|
|
401
|
+
assert_match(/missing keyword: :k3/, e.message)
|
|
339
402
|
end
|
|
340
403
|
|
|
341
404
|
def test_mock_block_is_passed_keyword_args__block_bad_extra
|
|
@@ -346,11 +409,10 @@ class TestMinitestMock < Minitest::Test
|
|
|
346
409
|
end
|
|
347
410
|
|
|
348
411
|
e = assert_raises ArgumentError do
|
|
349
|
-
mock.foo
|
|
412
|
+
mock.foo k1: arg1, k2: arg2, k3: arg3
|
|
350
413
|
end
|
|
351
414
|
|
|
352
|
-
|
|
353
|
-
assert_match(/unknown keyword: :?k3/, e.message)
|
|
415
|
+
assert_match(/unknown keyword: :k3/, e.message)
|
|
354
416
|
end
|
|
355
417
|
|
|
356
418
|
def test_mock_block_is_passed_keyword_args__block_bad_value
|
|
@@ -361,10 +423,12 @@ class TestMinitestMock < Minitest::Test
|
|
|
361
423
|
end
|
|
362
424
|
|
|
363
425
|
e = assert_raises MockExpectationError do
|
|
364
|
-
mock.foo
|
|
426
|
+
mock.foo k1: arg1, k2: arg2, k3: :BAD!
|
|
365
427
|
end
|
|
366
428
|
|
|
367
|
-
exp = "mocked method :foo failed block w/ []
|
|
429
|
+
exp = "mocked method :foo failed block w/ [] %p" \
|
|
430
|
+
% [{ :k1 => :bar, :k2 => [1, 2, 3], :k3 => :BAD! }]
|
|
431
|
+
|
|
368
432
|
assert_equal exp, e.message
|
|
369
433
|
end
|
|
370
434
|
|
|
@@ -373,7 +437,7 @@ class TestMinitestMock < Minitest::Test
|
|
|
373
437
|
mock = Minitest::Mock.new
|
|
374
438
|
mock.expect :foo, nil, k1: arg1, k2: arg2, k3: arg3
|
|
375
439
|
|
|
376
|
-
mock.foo
|
|
440
|
+
mock.foo k1: arg1, k2: arg2, k3: arg3
|
|
377
441
|
|
|
378
442
|
assert_mock mock
|
|
379
443
|
end
|
|
@@ -397,10 +461,10 @@ class TestMinitestMock < Minitest::Test
|
|
|
397
461
|
def test_mock_block_is_passed_keyword_args__args__old_style_bad
|
|
398
462
|
arg1, arg2, arg3 = :bar, [1, 2, 3], { :a => "a" }
|
|
399
463
|
mock = Minitest::Mock.new
|
|
400
|
-
mock.expect :foo, nil, [{k1: arg1, k2: arg2, k3: arg3}]
|
|
464
|
+
mock.expect :foo, nil, [{ k1: arg1, k2: arg2, k3: arg3 }]
|
|
401
465
|
|
|
402
466
|
e = assert_raises ArgumentError do
|
|
403
|
-
mock.foo
|
|
467
|
+
mock.foo k1: arg1, k2: arg2, k3: arg3
|
|
404
468
|
end
|
|
405
469
|
|
|
406
470
|
assert_equal "mocked method :foo expects 1 arguments, got []", e.message
|
|
@@ -410,9 +474,9 @@ class TestMinitestMock < Minitest::Test
|
|
|
410
474
|
with_kwargs_env do
|
|
411
475
|
arg1, arg2, arg3 = :bar, [1, 2, 3], { :a => "a" }
|
|
412
476
|
mock = Minitest::Mock.new
|
|
413
|
-
mock.expect :foo, nil, [{k1: arg1, k2: arg2, k3: arg3}]
|
|
477
|
+
mock.expect :foo, nil, [{ k1: arg1, k2: arg2, k3: arg3 }]
|
|
414
478
|
|
|
415
|
-
mock.foo
|
|
479
|
+
mock.foo k1: arg1, k2: arg2, k3: arg3
|
|
416
480
|
|
|
417
481
|
assert_mock mock
|
|
418
482
|
end
|
|
@@ -423,10 +487,12 @@ class TestMinitestMock < Minitest::Test
|
|
|
423
487
|
arg1, arg2, arg3 = :bar, [1, 2, 3], { :a => "a" }
|
|
424
488
|
mock = Minitest::Mock.new
|
|
425
489
|
|
|
426
|
-
|
|
490
|
+
assert_deprecation(/Using MT_KWARGS_HAC. yet passing kwargs/) do
|
|
427
491
|
mock.expect :foo, nil, [{}], k1: arg1, k2: arg2, k3: arg3
|
|
428
492
|
end
|
|
429
493
|
|
|
494
|
+
skip "-Werror" if error_on_warn? # mock above raised, so this is dead
|
|
495
|
+
|
|
430
496
|
mock.foo({}, k1: arg1, k2: arg2, k3: arg3)
|
|
431
497
|
|
|
432
498
|
assert_mock mock
|
|
@@ -439,10 +505,10 @@ class TestMinitestMock < Minitest::Test
|
|
|
439
505
|
mock.expect :foo, nil, k1: arg1, k2: arg2, k3: arg3
|
|
440
506
|
|
|
441
507
|
e = assert_raises ArgumentError do
|
|
442
|
-
mock.foo
|
|
508
|
+
mock.foo k1: arg1, k2: arg2
|
|
443
509
|
end
|
|
444
510
|
|
|
445
|
-
assert_equal "mocked method :foo expects 3 keyword arguments, got %p" % {k1: arg1, k2: arg2}, e.message
|
|
511
|
+
assert_equal "mocked method :foo expects 3 keyword arguments, got %p" % { k1: arg1, k2: arg2 }, e.message
|
|
446
512
|
end
|
|
447
513
|
|
|
448
514
|
def test_mock_block_is_passed_keyword_args__args_bad_extra
|
|
@@ -451,10 +517,10 @@ class TestMinitestMock < Minitest::Test
|
|
|
451
517
|
mock.expect :foo, nil, k1: arg1, k2: arg2
|
|
452
518
|
|
|
453
519
|
e = assert_raises ArgumentError do
|
|
454
|
-
mock.foo
|
|
520
|
+
mock.foo k1: arg1, k2: arg2, k3: arg3
|
|
455
521
|
end
|
|
456
522
|
|
|
457
|
-
assert_equal "mocked method :foo expects 2 keyword arguments, got %p" % {k1: arg1, k2: arg2, k3: arg3}, e.message
|
|
523
|
+
assert_equal "mocked method :foo expects 2 keyword arguments, got %p" % { k1: arg1, k2: arg2, k3: arg3 }, e.message
|
|
458
524
|
end
|
|
459
525
|
|
|
460
526
|
def test_mock_block_is_passed_keyword_args__args_bad_key
|
|
@@ -463,7 +529,7 @@ class TestMinitestMock < Minitest::Test
|
|
|
463
529
|
mock.expect :foo, nil, k1: arg1, k2: arg2, k3: arg3
|
|
464
530
|
|
|
465
531
|
e = assert_raises MockExpectationError do
|
|
466
|
-
mock.foo
|
|
532
|
+
mock.foo k1: arg1, k2: arg2, BAD: arg3
|
|
467
533
|
end
|
|
468
534
|
|
|
469
535
|
assert_includes e.message, "unexpected keywords [:k1, :k2, :k3]"
|
|
@@ -476,18 +542,18 @@ class TestMinitestMock < Minitest::Test
|
|
|
476
542
|
mock.expect :foo, nil, k1: arg1, k2: arg2, k3: arg3
|
|
477
543
|
|
|
478
544
|
e = assert_raises MockExpectationError do
|
|
479
|
-
mock.foo
|
|
545
|
+
mock.foo k1: arg1, k2: :BAD!, k3: arg3
|
|
480
546
|
end
|
|
481
547
|
|
|
482
|
-
|
|
548
|
+
bad = { :k2 => :BAD! }.inspect.delete "{}"
|
|
549
|
+
assert_match(/unexpected keyword arguments.* vs .*#{bad}/, e.message)
|
|
483
550
|
end
|
|
484
551
|
|
|
485
552
|
def test_mock_block_is_passed_function_block
|
|
486
553
|
mock = Minitest::Mock.new
|
|
487
554
|
block = proc { "bar" }
|
|
488
555
|
mock.expect :foo, nil do |arg, &blk|
|
|
489
|
-
arg == "foo" &&
|
|
490
|
-
blk == block
|
|
556
|
+
arg == "foo" && blk == block
|
|
491
557
|
end
|
|
492
558
|
mock.foo "foo", &block
|
|
493
559
|
assert_mock mock
|
|
@@ -495,8 +561,8 @@ class TestMinitestMock < Minitest::Test
|
|
|
495
561
|
|
|
496
562
|
def test_mock_forward_keyword_arguments
|
|
497
563
|
mock = Minitest::Mock.new
|
|
498
|
-
mock.expect(:foo, nil) { |bar:| bar ==
|
|
499
|
-
mock.foo
|
|
564
|
+
mock.expect(:foo, nil) { |bar:| bar == "bar" }
|
|
565
|
+
mock.foo bar: "bar"
|
|
500
566
|
assert_mock mock
|
|
501
567
|
end
|
|
502
568
|
|
|
@@ -515,7 +581,7 @@ class TestMinitestMock < Minitest::Test
|
|
|
515
581
|
def test_mock_block_raises_if_args_passed
|
|
516
582
|
mock = Minitest::Mock.new
|
|
517
583
|
|
|
518
|
-
e = assert_raises
|
|
584
|
+
e = assert_raises ArgumentError do
|
|
519
585
|
mock.expect :foo, nil, [:a, :b, :c] do
|
|
520
586
|
true
|
|
521
587
|
end
|
|
@@ -529,8 +595,8 @@ class TestMinitestMock < Minitest::Test
|
|
|
529
595
|
def test_mock_block_raises_if_kwargs_passed
|
|
530
596
|
mock = Minitest::Mock.new
|
|
531
597
|
|
|
532
|
-
e = assert_raises
|
|
533
|
-
mock.expect :foo, nil, kwargs:1 do
|
|
598
|
+
e = assert_raises ArgumentError do
|
|
599
|
+
mock.expect :foo, nil, kwargs: 1 do
|
|
534
600
|
true
|
|
535
601
|
end
|
|
536
602
|
end
|
|
@@ -542,7 +608,7 @@ class TestMinitestMock < Minitest::Test
|
|
|
542
608
|
|
|
543
609
|
def test_mock_returns_retval_when_called_with_block
|
|
544
610
|
mock = Minitest::Mock.new
|
|
545
|
-
mock.expect
|
|
611
|
+
mock.expect :foo, 32 do
|
|
546
612
|
true
|
|
547
613
|
end
|
|
548
614
|
|
|
@@ -561,7 +627,7 @@ class TestMinitestMock < Minitest::Test
|
|
|
561
627
|
|
|
562
628
|
def test_mock_called_via_send
|
|
563
629
|
mock = Minitest::Mock.new
|
|
564
|
-
mock.expect
|
|
630
|
+
mock.expect :foo, true
|
|
565
631
|
|
|
566
632
|
mock.send :foo
|
|
567
633
|
assert_mock mock
|
|
@@ -569,7 +635,7 @@ class TestMinitestMock < Minitest::Test
|
|
|
569
635
|
|
|
570
636
|
def test_mock_called_via___send__
|
|
571
637
|
mock = Minitest::Mock.new
|
|
572
|
-
mock.expect
|
|
638
|
+
mock.expect :foo, true
|
|
573
639
|
|
|
574
640
|
mock.__send__ :foo
|
|
575
641
|
assert_mock mock
|
|
@@ -577,15 +643,15 @@ class TestMinitestMock < Minitest::Test
|
|
|
577
643
|
|
|
578
644
|
def test_mock_called_via_send_with_args
|
|
579
645
|
mock = Minitest::Mock.new
|
|
580
|
-
mock.expect
|
|
646
|
+
mock.expect :foo, true, [1, 2, 3]
|
|
581
647
|
|
|
582
|
-
mock.send
|
|
648
|
+
mock.send :foo, 1, 2, 3
|
|
583
649
|
assert_mock mock
|
|
584
650
|
end
|
|
585
651
|
|
|
586
652
|
end
|
|
587
653
|
|
|
588
|
-
|
|
654
|
+
require_relative "metametameta"
|
|
589
655
|
|
|
590
656
|
class TestMinitestStub < Minitest::Test
|
|
591
657
|
# Do not parallelize since we're calling stub on class methods
|
|
@@ -655,7 +721,7 @@ class TestMinitestStub < Minitest::Test
|
|
|
655
721
|
end
|
|
656
722
|
end
|
|
657
723
|
|
|
658
|
-
def
|
|
724
|
+
def test_stub_value__literal
|
|
659
725
|
assert_stub 42
|
|
660
726
|
end
|
|
661
727
|
|
|
@@ -686,7 +752,7 @@ class TestMinitestStub < Minitest::Test
|
|
|
686
752
|
end
|
|
687
753
|
|
|
688
754
|
def test_stub_yield_self
|
|
689
|
-
obj = "foo"
|
|
755
|
+
obj = +"foo"
|
|
690
756
|
|
|
691
757
|
val = obj.stub :to_s, "bar" do |s|
|
|
692
758
|
s.to_s
|
|
@@ -712,7 +778,7 @@ class TestMinitestStub < Minitest::Test
|
|
|
712
778
|
end
|
|
713
779
|
end
|
|
714
780
|
|
|
715
|
-
val = dynamic.stub
|
|
781
|
+
val = dynamic.stub :found, true do |s|
|
|
716
782
|
s.found
|
|
717
783
|
end
|
|
718
784
|
|
|
@@ -727,14 +793,17 @@ class TestMinitestStub < Minitest::Test
|
|
|
727
793
|
end
|
|
728
794
|
end
|
|
729
795
|
|
|
730
|
-
exp = jruby?
|
|
731
|
-
|
|
796
|
+
exp = if jruby? then
|
|
797
|
+
/Undefined method nope_nope_nope for '#{self.class}::Time'/
|
|
798
|
+
else
|
|
799
|
+
/undefined method [`']nope_nope_nope' for( class)? [`']#{self.class}::Time'/
|
|
800
|
+
end
|
|
732
801
|
assert_match exp, e.message
|
|
733
802
|
end
|
|
734
803
|
|
|
735
804
|
def test_mock_with_yield
|
|
736
805
|
mock = Minitest::Mock.new
|
|
737
|
-
mock.expect
|
|
806
|
+
mock.expect :write, true do
|
|
738
807
|
true
|
|
739
808
|
end
|
|
740
809
|
rs = nil
|
|
@@ -751,7 +820,7 @@ class TestMinitestStub < Minitest::Test
|
|
|
751
820
|
mock = Minitest::Mock.new
|
|
752
821
|
rs = nil
|
|
753
822
|
|
|
754
|
-
File.stub :open, true, mock, kw:42 do
|
|
823
|
+
File.stub :open, true, mock, kw: 42 do
|
|
755
824
|
File.open "foo.txt", "r" do |f, kw:|
|
|
756
825
|
rs = kw
|
|
757
826
|
end
|
|
@@ -760,8 +829,6 @@ class TestMinitestStub < Minitest::Test
|
|
|
760
829
|
@tc.assert_equal 42, rs
|
|
761
830
|
end
|
|
762
831
|
|
|
763
|
-
alias test_stub_value__old test_stub_value # TODO: remove/rename
|
|
764
|
-
|
|
765
832
|
## Permutation Sets:
|
|
766
833
|
|
|
767
834
|
# [:value, :lambda]
|
|
@@ -816,7 +883,7 @@ class TestMinitestStub < Minitest::Test
|
|
|
816
883
|
# [:value, :block_call, :args] => N/A
|
|
817
884
|
|
|
818
885
|
class Bar
|
|
819
|
-
def call
|
|
886
|
+
def call &_ # to ignore unused block
|
|
820
887
|
puts "hi"
|
|
821
888
|
end
|
|
822
889
|
end
|
|
@@ -834,7 +901,7 @@ class TestMinitestStub < Minitest::Test
|
|
|
834
901
|
end
|
|
835
902
|
|
|
836
903
|
class Keywords
|
|
837
|
-
def self.args req, kw1:, kw2:24
|
|
904
|
+
def self.args req, kw1:, kw2: 24
|
|
838
905
|
[req, kw1, kw2]
|
|
839
906
|
end
|
|
840
907
|
end
|
|
@@ -848,7 +915,7 @@ class TestMinitestStub < Minitest::Test
|
|
|
848
915
|
def test_stub__hash_as_last_real_arg
|
|
849
916
|
with_kwargs_env do
|
|
850
917
|
token = Object.new
|
|
851
|
-
def token.create_with_retry
|
|
918
|
+
def token.create_with_retry _u, _p; raise "shouldn't see this"; end
|
|
852
919
|
|
|
853
920
|
controller = Object.new
|
|
854
921
|
controller.define_singleton_method :create do |u, p|
|
|
@@ -956,7 +1023,7 @@ class TestMinitestStub < Minitest::Test
|
|
|
956
1023
|
def test_stub_lambda_block_call_5
|
|
957
1024
|
@assertion_count += 1
|
|
958
1025
|
rs = nil
|
|
959
|
-
io = StringIO.new
|
|
1026
|
+
io = StringIO.new(+"", "w")
|
|
960
1027
|
File.stub5 :open, lambda { |p, m, &blk| blk and blk.call io } do
|
|
961
1028
|
File.open "foo.txt", "r" do |f|
|
|
962
1029
|
rs = f && f.write("woot")
|
|
@@ -971,10 +1038,10 @@ class TestMinitestStub < Minitest::Test
|
|
|
971
1038
|
|
|
972
1039
|
@assertion_count += 1
|
|
973
1040
|
rs = nil
|
|
974
|
-
io = StringIO.new
|
|
1041
|
+
io = StringIO.new(+"", "w")
|
|
975
1042
|
File.stub6 :open, lambda { |p, m, &blk| blk.call io } do
|
|
976
1043
|
File.open "foo.txt", "r" do |f|
|
|
977
|
-
rs = f.write
|
|
1044
|
+
rs = f.write "woot"
|
|
978
1045
|
end
|
|
979
1046
|
end
|
|
980
1047
|
@tc.assert_equal 4, rs
|
|
@@ -984,10 +1051,10 @@ class TestMinitestStub < Minitest::Test
|
|
|
984
1051
|
def test_stub_lambda_block_call_args_5
|
|
985
1052
|
@assertion_count += 1
|
|
986
1053
|
rs = nil
|
|
987
|
-
io = StringIO.new
|
|
1054
|
+
io = StringIO.new(+"", "w")
|
|
988
1055
|
File.stub5(:open, lambda { |p, m, &blk| blk and blk.call io }, :WTF?) do
|
|
989
1056
|
File.open "foo.txt", "r" do |f|
|
|
990
|
-
rs = f.write
|
|
1057
|
+
rs = f.write "woot"
|
|
991
1058
|
end
|
|
992
1059
|
end
|
|
993
1060
|
@tc.assert_equal 4, rs
|
|
@@ -999,10 +1066,10 @@ class TestMinitestStub < Minitest::Test
|
|
|
999
1066
|
|
|
1000
1067
|
@assertion_count += 1
|
|
1001
1068
|
rs = nil
|
|
1002
|
-
io = StringIO.new
|
|
1069
|
+
io = StringIO.new(+"", "w")
|
|
1003
1070
|
File.stub6(:open, lambda { |p, m, &blk| blk.call io }, :WTF?) do
|
|
1004
1071
|
File.open "foo.txt", "r" do |f|
|
|
1005
|
-
rs = f.write
|
|
1072
|
+
rs = f.write "woot"
|
|
1006
1073
|
end
|
|
1007
1074
|
end
|
|
1008
1075
|
@tc.assert_equal 4, rs
|
|
@@ -1014,11 +1081,11 @@ class TestMinitestStub < Minitest::Test
|
|
|
1014
1081
|
|
|
1015
1082
|
@assertion_count += 2
|
|
1016
1083
|
rs = nil
|
|
1017
|
-
io = StringIO.new
|
|
1084
|
+
io = StringIO.new(+"", "w")
|
|
1018
1085
|
@tc.assert_raises ArgumentError do
|
|
1019
1086
|
File.stub6_2(:open, lambda { |p, m, &blk| blk.call io }, :WTF?) do
|
|
1020
1087
|
File.open "foo.txt", "r" do |f|
|
|
1021
|
-
rs = f.write
|
|
1088
|
+
rs = f.write "woot"
|
|
1022
1089
|
end
|
|
1023
1090
|
end
|
|
1024
1091
|
end
|
|
@@ -1064,10 +1131,10 @@ class TestMinitestStub < Minitest::Test
|
|
|
1064
1131
|
def test_stub_value_block_args_5
|
|
1065
1132
|
@assertion_count += 2
|
|
1066
1133
|
rs = nil
|
|
1067
|
-
io = StringIO.new
|
|
1134
|
+
io = StringIO.new(+"", "w")
|
|
1068
1135
|
File.stub5 :open, :value, io do
|
|
1069
1136
|
result = File.open "foo.txt", "r" do |f|
|
|
1070
|
-
rs = f.write
|
|
1137
|
+
rs = f.write "woot"
|
|
1071
1138
|
end
|
|
1072
1139
|
@tc.assert_equal :value, result
|
|
1073
1140
|
end
|
|
@@ -1083,7 +1150,7 @@ class TestMinitestStub < Minitest::Test
|
|
|
1083
1150
|
end
|
|
1084
1151
|
end
|
|
1085
1152
|
end
|
|
1086
|
-
exp = /undefined method `write' for nil/
|
|
1153
|
+
exp = /undefined method [`']write' for nil/
|
|
1087
1154
|
assert_match exp, e.message
|
|
1088
1155
|
end
|
|
1089
1156
|
|
|
@@ -1092,11 +1159,11 @@ class TestMinitestStub < Minitest::Test
|
|
|
1092
1159
|
|
|
1093
1160
|
@assertion_count += 2
|
|
1094
1161
|
rs = nil
|
|
1095
|
-
io = StringIO.new
|
|
1162
|
+
io = StringIO.new(+"", "w")
|
|
1096
1163
|
assert_deprecated do
|
|
1097
1164
|
File.stub6 :open, :value, io do
|
|
1098
1165
|
result = File.open "foo.txt", "r" do |f|
|
|
1099
|
-
rs = f.write
|
|
1166
|
+
rs = f.write "woot"
|
|
1100
1167
|
end
|
|
1101
1168
|
@tc.assert_equal :value, result
|
|
1102
1169
|
end
|
|
@@ -1110,7 +1177,7 @@ class TestMinitestStub < Minitest::Test
|
|
|
1110
1177
|
|
|
1111
1178
|
@assertion_count += 2
|
|
1112
1179
|
rs = nil
|
|
1113
|
-
io = StringIO.new
|
|
1180
|
+
io = StringIO.new(+"", "w")
|
|
1114
1181
|
@tc.assert_raises ArgumentError do
|
|
1115
1182
|
File.stub6_2 :open, :value, io do
|
|
1116
1183
|
result = File.open "foo.txt", "r" do |f|
|