minitest 5.16.1 → 5.16.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 852c6d118d767dd9a858cdb30033835fadb147806baf17b8212fd2adb73563f6
4
- data.tar.gz: a6b8773230001afcd126bec405ffa06324a2cf3a5d52588ba44e8c0a0750aef2
3
+ metadata.gz: f8a4c5be93a57704279d69e9de71e39a726d553e5f8e75ef98fca8606b5543bf
4
+ data.tar.gz: e821d2c514f6fdc21698c3b6f1c1dbba39de57817c1c7710881082cdce382371
5
5
  SHA512:
6
- metadata.gz: e7059905b9c55d737ce9d92c066fcd38080deb7a60535a142b528d91d97fc1be87726261725cf14c8dd6540c1d274da8ebbc860f9bea957bbd2e7f6a078381f6
7
- data.tar.gz: 8beb3623acb42c1a5fe640cbdbe99833181f90e4d9e52bcf297cfd471d86785c186291911e94e00d5b54cb56870ae1f1d97be16207c7c6381fc31bb56596e2aa
6
+ metadata.gz: 35335793acd5044353c3fae7e59f62c15ed321f8637e20aef8fa82269c1e2d1670f2ef92363cd94c56708e2eae50d95e7b22fed3a35219c2010f4c6a40748f9c
7
+ data.tar.gz: 41540290647a9fd33739b43f99bff035c4371f0f0d3e4021e8e2502fd4c02f0e10efb787ca48e31276a59c64e627a837515bbeb9e6795bb48e6f89b704c007a8
checksums.yaml.gz.sig CHANGED
Binary file
data/History.rdoc CHANGED
@@ -1,3 +1,12 @@
1
+ === 5.16.2 / 2022-07-03
2
+
3
+ * 4 bug fixes:
4
+
5
+ * Added MT_KWARGS_HACK kludge for stub to deal with ruby 2.7 kwargs nastiness. (tsugimoto)
6
+ * In #expect, pop Hash class from args if $MT_KWARGS_HACK. (casperisfine)
7
+ * In above scenario, set expected kwargs (as Objects) based on actual kwargs.
8
+ * Nuke ivars if exception fails to marshal twice (eg better_errors). (irphilli)
9
+
1
10
  === 5.16.1 / 2022-06-20
2
11
 
3
12
  * 2 bug fixes:
data/lib/minitest/mock.rb CHANGED
@@ -98,7 +98,8 @@ module Minitest # :nodoc:
98
98
  else
99
99
  raise ArgumentError, "args must be an array" unless Array === args
100
100
 
101
- if ENV["MT_KWARGS_HAC\K"] && Hash === args.last then
101
+ if ENV["MT_KWARGS_HAC\K"] && (Hash === args.last ||
102
+ Hash == args.last) then
102
103
  if kwargs.empty? then
103
104
  kwargs = args.pop
104
105
  else
@@ -167,6 +168,9 @@ module Minitest # :nodoc:
167
168
  expected_args, expected_kwargs, retval, val_block =
168
169
  expected_call.values_at(:args, :kwargs, :retval, :block)
169
170
 
171
+ expected_kwargs = kwargs.map { |ak, av| [ak, Object] }.to_h if
172
+ Hash == expected_kwargs
173
+
170
174
  if val_block then
171
175
  # keep "verify" happy
172
176
  @actual_calls[sym] << expected_call
@@ -280,22 +284,33 @@ class Object
280
284
 
281
285
  metaclass.send :alias_method, new_name, name
282
286
 
283
- metaclass.send :define_method, name do |*args, **kwargs, &blk|
284
- if val_or_callable.respond_to? :call then
285
- if kwargs.empty? then # FIX: drop this after 2.7 dead
287
+ if ENV["MT_KWARGS_HAC\K"] then
288
+ metaclass.send :define_method, name do |*args, &blk|
289
+ if val_or_callable.respond_to? :call then
286
290
  val_or_callable.call(*args, &blk)
287
291
  else
288
- val_or_callable.call(*args, **kwargs, &blk)
292
+ blk.call(*block_args, **block_kwargs) if blk
293
+ val_or_callable
289
294
  end
290
- else
291
- if blk then
292
- if block_kwargs.empty? then # FIX: drop this after 2.7 dead
293
- blk.call(*block_args)
295
+ end
296
+ else
297
+ metaclass.send :define_method, name do |*args, **kwargs, &blk|
298
+ if val_or_callable.respond_to? :call then
299
+ if kwargs.empty? then # FIX: drop this after 2.7 dead
300
+ val_or_callable.call(*args, &blk)
294
301
  else
295
- blk.call(*block_args, **block_kwargs)
302
+ val_or_callable.call(*args, **kwargs, &blk)
303
+ end
304
+ else
305
+ if blk then
306
+ if block_kwargs.empty? then # FIX: drop this after 2.7 dead
307
+ blk.call(*block_args)
308
+ else
309
+ blk.call(*block_args, **block_kwargs)
310
+ end
296
311
  end
312
+ val_or_callable
297
313
  end
298
- val_or_callable
299
314
  end
300
315
  end
301
316
 
data/lib/minitest/test.rb CHANGED
@@ -216,12 +216,19 @@ module Minitest
216
216
  rescue TypeError
217
217
  msg.prepend "Neutered Exception #{e.class}: "
218
218
 
219
- new_exception RuntimeError, msg, bt # but if this raises, we die
219
+ new_exception RuntimeError, msg, bt, true # but if this raises, we die
220
220
  end
221
221
 
222
- def new_exception klass, msg, bt
222
+ def new_exception klass, msg, bt, kill = false
223
223
  ne = klass.new msg
224
224
  ne.set_backtrace bt
225
+
226
+ if kill then
227
+ ne.instance_variables.each do |v|
228
+ ne.remove_instance_variable v
229
+ end
230
+ end
231
+
225
232
  Marshal.dump ne # can raise TypeError
226
233
  ne
227
234
  end
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.1" # :nodoc:
12
+ VERSION = "5.16.2" # :nodoc:
13
13
 
14
14
  @@installed_at_exit ||= false
15
15
  @@after_run = []
@@ -1,5 +1,13 @@
1
1
  require "minitest/autorun"
2
2
 
3
+ def with_kwargs_env
4
+ ENV["MT_KWARGS_HAC\K"] = "1"
5
+
6
+ yield
7
+ ensure
8
+ ENV.delete "MT_KWARGS_HAC\K"
9
+ end
10
+
3
11
  class TestMinitestMock < Minitest::Test
4
12
  parallelize_me!
5
13
 
@@ -363,12 +371,20 @@ class TestMinitestMock < Minitest::Test
363
371
  assert_mock mock
364
372
  end
365
373
 
366
- def with_kwargs_env
367
- ENV["MT_KWARGS_HAC\K"] = "1"
374
+ def test_mock_allow_all_kwargs__old_style_env
375
+ with_kwargs_env do
376
+ mock = Minitest::Mock.new
377
+ mock.expect :foo, true, [Hash]
378
+ assert_equal true, mock.foo(bar: 42)
379
+ end
380
+ end
368
381
 
369
- yield
370
- ensure
371
- ENV.delete "MT_KWARGS_HAC\K"
382
+ def test_mock_allow_all_kwargs__old_style_env__rewrite
383
+ with_kwargs_env do
384
+ mock = Minitest::Mock.new
385
+ mock.expect :foo, true, [], bar: Integer
386
+ assert_equal true, mock.foo(bar: 42)
387
+ end
372
388
  end
373
389
 
374
390
  def test_mock_block_is_passed_keyword_args__args__old_style_bad
@@ -822,6 +838,26 @@ class TestMinitestStub < Minitest::Test
822
838
  end
823
839
  end
824
840
 
841
+ def test_stub__hash_as_last_real_arg
842
+ with_kwargs_env do
843
+ token = Object.new
844
+ def token.create_with_retry u, p; raise "shouldn't see this"; end
845
+
846
+ controller = Object.new
847
+ controller.define_singleton_method :create do |u, p|
848
+ token.create_with_retry u, p
849
+ end
850
+
851
+ params = Object.new
852
+ def params.to_hash; raise "nah"; end
853
+
854
+ token.stub(:create_with_retry, ->(u, p) { 42 }) do
855
+ act = controller.create :u, params
856
+ @tc.assert_equal 42, act
857
+ end
858
+ end
859
+ end
860
+
825
861
  def test_stub_callable_block_5 # from tenderlove
826
862
  @assertion_count += 1
827
863
  Foo.stub5 :blocking, Bar.new do
@@ -786,6 +786,13 @@ class TestMinitestUnitOrder < MetaMetaMetaTestCase
786
786
  end
787
787
  end
788
788
 
789
+ class BetterError < RuntimeError # like better_error w/o infecting RuntimeError
790
+ def set_backtrace bt
791
+ super
792
+ @bad_ivar = binding
793
+ end
794
+ end
795
+
789
796
  class TestMinitestRunnable < Minitest::Test
790
797
  def setup_marshal klass
791
798
  tc = klass.new "whatever"
@@ -895,6 +902,46 @@ class TestMinitestRunnable < Minitest::Test
895
902
  assert_equal @tc.failures, over_the_wire.failures
896
903
  assert_equal @tc.klass, over_the_wire.klass
897
904
  end
905
+
906
+ def with_runtime_error klass
907
+ old_runtime = RuntimeError
908
+ Object.send :remove_const, :RuntimeError
909
+ Object.const_set :RuntimeError, klass
910
+ yield
911
+ ensure
912
+ Object.send :remove_const, :RuntimeError
913
+ Object.const_set :RuntimeError, old_runtime
914
+ end
915
+
916
+ def test_spec_marshal_with_exception__better_error_typeerror
917
+ klass = describe("whatever") {
918
+ it("raises with binding") {
919
+ raise BetterError, "boom"
920
+ }
921
+ }
922
+
923
+ rm = klass.runnable_methods.first
924
+
925
+ # Run the test
926
+ @tc = with_runtime_error BetterError do
927
+ klass.new(rm).run
928
+ end
929
+
930
+ assert_kind_of Minitest::Result, @tc
931
+ assert_instance_of Minitest::UnexpectedError, @tc.failure
932
+
933
+ msg = @tc.failure.error.message
934
+ assert_equal "Neutered Exception BetterError: boom", msg
935
+
936
+ # Pass it over the wire
937
+ over_the_wire = Marshal.load Marshal.dump @tc
938
+
939
+ assert_equal @tc.time, over_the_wire.time
940
+ assert_equal @tc.name, over_the_wire.name
941
+ assert_equal @tc.assertions, over_the_wire.assertions
942
+ assert_equal @tc.failures, over_the_wire.failures
943
+ assert_equal @tc.klass, over_the_wire.klass
944
+ end
898
945
  end
899
946
 
900
947
  class TestMinitestTest < TestMinitestRunnable
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.1
4
+ version: 5.16.2
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-20 00:00:00.000000000 Z
32
+ date: 2022-07-03 00:00:00.000000000 Z
33
33
  dependencies:
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: rdoc
@@ -57,14 +57,14 @@ dependencies:
57
57
  requirements:
58
58
  - - "~>"
59
59
  - !ruby/object:Gem::Version
60
- version: '3.23'
60
+ version: '3.24'
61
61
  type: :development
62
62
  prerelease: false
63
63
  version_requirements: !ruby/object:Gem::Requirement
64
64
  requirements:
65
65
  - - "~>"
66
66
  - !ruby/object:Gem::Version
67
- version: '3.23'
67
+ version: '3.24'
68
68
  description: |-
69
69
  minitest provides a complete suite of testing facilities supporting
70
70
  TDD, BDD, mocking, and benchmarking.
metadata.gz.sig CHANGED
Binary file