minitest 5.16.0 → 5.16.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9253f08ed8cc9ec5b362ff80aee1be1b0b0d7873fea50c97893d2e62ef013fd2
4
- data.tar.gz: e674a1a6f27a4bb130b735585f31658efdec0bb4eae4140e63f1bc30a5d59779
3
+ metadata.gz: 852c6d118d767dd9a858cdb30033835fadb147806baf17b8212fd2adb73563f6
4
+ data.tar.gz: a6b8773230001afcd126bec405ffa06324a2cf3a5d52588ba44e8c0a0750aef2
5
5
  SHA512:
6
- metadata.gz: 925355cd00438e04a789b67a4c79796c590d4d18a2e0bedf33592d471a6c3586a77aec61fec8882099ab3980ccb4e9be87de7dd31c6ae9d938f39a13188788f7
7
- data.tar.gz: 48e0507f508e989bf2a6dbe137114377b4cb552041d52a1cf232feb062ab6bcfb43097e551f061c23a35fce074093ddbe5259c9a51dbee7e88d10843c15db2f8
6
+ metadata.gz: e7059905b9c55d737ce9d92c066fcd38080deb7a60535a142b528d91d97fc1be87726261725cf14c8dd6540c1d274da8ebbc860f9bea957bbd2e7f6a078381f6
7
+ data.tar.gz: 8beb3623acb42c1a5fe640cbdbe99833181f90e4d9e52bcf297cfd471d86785c186291911e94e00d5b54cb56870ae1f1d97be16207c7c6381fc31bb56596e2aa
checksums.yaml.gz.sig CHANGED
Binary file
data/History.rdoc CHANGED
@@ -1,3 +1,11 @@
1
+ === 5.16.1 / 2022-06-20
2
+
3
+ * 2 bug fixes:
4
+
5
+ * Apparently adding real kwarg support to mocks/stubs broke some code. Fixed.
6
+ * Use `MT_KWARGS_HACK=1` to activate the kludgy kwargs support w/ caveats.
7
+ * Clarified some doco wrt the block on #stub.
8
+
1
9
  === 5.16.0 / 2022-06-14
2
10
 
3
11
  * 2 major enhancements:
data/lib/minitest/mock.rb CHANGED
@@ -51,6 +51,8 @@ module Minitest # :nodoc:
51
51
  @actual_calls = Hash.new { |calls, name| calls[name] = [] }
52
52
  end
53
53
 
54
+ @@KW_WARNED = false # :nodoc:
55
+
54
56
  ##
55
57
  # Expect that method +name+ is called, optionally with +args+ (and
56
58
  # +kwargs+ or a +blk+, and returns +retval+.
@@ -91,10 +93,25 @@ module Minitest # :nodoc:
91
93
 
92
94
  if block_given?
93
95
  raise ArgumentError, "args ignored when block given" unless args.empty?
96
+ raise ArgumentError, "kwargs ignored when block given" unless kwargs.empty?
94
97
  @expected_calls[name] << { :retval => retval, :block => blk }
95
98
  else
96
99
  raise ArgumentError, "args must be an array" unless Array === args
97
- @expected_calls[name] << { :retval => retval, :args => args, :kwargs => kwargs }
100
+
101
+ if ENV["MT_KWARGS_HAC\K"] && Hash === args.last then
102
+ if kwargs.empty? then
103
+ kwargs = args.pop
104
+ else
105
+ unless @@KW_WARNED then
106
+ from = caller.first
107
+ warn "Using MT_KWARGS_HAC\K yet passing kwargs. From #{from}"
108
+ @@KW_WARNED = true
109
+ end
110
+ end
111
+ end
112
+
113
+ @expected_calls[name] <<
114
+ { :retval => retval, :args => args, :kwargs => kwargs }
98
115
  end
99
116
  self
100
117
  end
@@ -250,7 +267,7 @@ class Object
250
267
  # NOTE: keyword args in callables are NOT checked for correctness
251
268
  # against the existing method. Too many edge cases to be worth it.
252
269
 
253
- def stub name, val_or_callable, *block_args, **block_kwargs
270
+ def stub name, val_or_callable, *block_args, **block_kwargs, &block
254
271
  new_name = "__minitest_stub__#{name}"
255
272
 
256
273
  metaclass = class << self; self; end
@@ -282,7 +299,7 @@ class Object
282
299
  end
283
300
  end
284
301
 
285
- yield self
302
+ block[self]
286
303
  ensure
287
304
  metaclass.send :undef_method, name
288
305
  metaclass.send :alias_method, name, new_name
data/lib/minitest.rb CHANGED
@@ -9,7 +9,7 @@ require "etc"
9
9
  # :include: README.rdoc
10
10
 
11
11
  module Minitest
12
- VERSION = "5.16.0" # :nodoc:
12
+ VERSION = "5.16.1" # :nodoc:
13
13
 
14
14
  @@installed_at_exit ||= false
15
15
  @@after_run = []
@@ -363,6 +363,53 @@ class TestMinitestMock < Minitest::Test
363
363
  assert_mock mock
364
364
  end
365
365
 
366
+ def with_kwargs_env
367
+ ENV["MT_KWARGS_HAC\K"] = "1"
368
+
369
+ yield
370
+ ensure
371
+ ENV.delete "MT_KWARGS_HAC\K"
372
+ end
373
+
374
+ def test_mock_block_is_passed_keyword_args__args__old_style_bad
375
+ arg1, arg2, arg3 = :bar, [1, 2, 3], { :a => "a" }
376
+ mock = Minitest::Mock.new
377
+ mock.expect :foo, nil, [{k1: arg1, k2: arg2, k3: arg3}]
378
+
379
+ e = assert_raises ArgumentError do
380
+ mock.foo(k1: arg1, k2: arg2, k3: arg3)
381
+ end
382
+
383
+ assert_equal "mocked method :foo expects 1 arguments, got []", e.message
384
+ end
385
+
386
+ def test_mock_block_is_passed_keyword_args__args__old_style_env
387
+ with_kwargs_env do
388
+ arg1, arg2, arg3 = :bar, [1, 2, 3], { :a => "a" }
389
+ mock = Minitest::Mock.new
390
+ mock.expect :foo, nil, [{k1: arg1, k2: arg2, k3: arg3}]
391
+
392
+ mock.foo(k1: arg1, k2: arg2, k3: arg3)
393
+
394
+ assert_mock mock
395
+ end
396
+ end
397
+
398
+ def test_mock_block_is_passed_keyword_args__args__old_style_both
399
+ with_kwargs_env do
400
+ arg1, arg2, arg3 = :bar, [1, 2, 3], { :a => "a" }
401
+ mock = Minitest::Mock.new
402
+
403
+ assert_output nil, /Using MT_KWARGS_HAC. yet passing kwargs/ do
404
+ mock.expect :foo, nil, [{}], k1: arg1, k2: arg2, k3: arg3
405
+ end
406
+
407
+ mock.foo({}, k1: arg1, k2: arg2, k3: arg3)
408
+
409
+ assert_mock mock
410
+ end
411
+ end
412
+
366
413
  def test_mock_block_is_passed_keyword_args__args_bad_missing
367
414
  arg1, arg2, arg3 = :bar, [1, 2, 3], { :a => "a" }
368
415
  mock = Minitest::Mock.new
@@ -442,7 +489,7 @@ class TestMinitestMock < Minitest::Test
442
489
  assert_equal exp, e.message
443
490
  end
444
491
 
445
- def test_mock_block_throws_if_args_passed
492
+ def test_mock_block_raises_if_args_passed
446
493
  mock = Minitest::Mock.new
447
494
 
448
495
  e = assert_raises(ArgumentError) do
@@ -456,6 +503,20 @@ class TestMinitestMock < Minitest::Test
456
503
  assert_match exp, e.message
457
504
  end
458
505
 
506
+ def test_mock_block_raises_if_kwargs_passed
507
+ mock = Minitest::Mock.new
508
+
509
+ e = assert_raises(ArgumentError) do
510
+ mock.expect :foo, nil, kwargs:1 do
511
+ true
512
+ end
513
+ end
514
+
515
+ exp = "kwargs ignored when block given"
516
+
517
+ assert_match exp, e.message
518
+ end
519
+
459
520
  def test_mock_returns_retval_when_called_with_block
460
521
  mock = Minitest::Mock.new
461
522
  mock.expect(:foo, 32) do
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minitest
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.16.0
4
+ version: 5.16.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Davis
@@ -29,7 +29,7 @@ cert_chain:
29
29
  JFmxn4h9YO/pVdB962BdBNNDia0kgIjI3ENnkLq0dKpYU3+F3KhEuTksLO0L6X/V
30
30
  YsuyUzsMz6GQA4khyaMgKNSD
31
31
  -----END CERTIFICATE-----
32
- date: 2022-06-15 00:00:00.000000000 Z
32
+ date: 2022-06-20 00:00:00.000000000 Z
33
33
  dependencies:
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: rdoc
metadata.gz.sig CHANGED
Binary file