From 6445f4ee65d3eb7fd934cdecb70824ef2c5dbe51 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Fri, 28 Feb 2025 10:43:29 -0300 Subject: [PATCH 1/2] fix: explicitly forward keyword arguments when calling {#initialize} for new_instances support --- test/new_instances_test.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/new_instances_test.rb b/test/new_instances_test.rb index 8397ff5..8eef776 100644 --- a/test/new_instances_test.rb +++ b/test/new_instances_test.rb @@ -29,8 +29,10 @@ def self.make class Cat attr_reader :name - def initialize(name, &block) + attr_reader :kw + def initialize(name, **kw, &block) @name = name + @kw = kw block.call(self) if block_given? end end @@ -94,10 +96,11 @@ def test_new_instances_will_pass_args_to_new obj.should_receive(:meow).and_return(:scratch) end x = :not_called - m = Cat.new("Fido") { x = :called } + m = Cat.new("Fido", a: 42) { x = :called } assert_equal :scratch, m.meow assert_equal "Fido", m.name assert_equal :called, x + assert_equal({ a: 42 }, m.kw) end # Some versions of the software had problems invoking the block after a From 57ee0b31161628f3aec3c8d652c9acd196470210 Mon Sep 17 00:00:00 2001 From: Sylvain Joyeux Date: Fri, 28 Feb 2025 13:48:07 +0000 Subject: [PATCH 2/2] chore: fix ruby warnings --- test/extended_should_receive_test.rb | 4 ++-- test/new_instances_test.rb | 4 ++-- test/partial_mock_test.rb | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/test/extended_should_receive_test.rb b/test/extended_should_receive_test.rb index 11094c6..07cf8dd 100644 --- a/test/extended_should_receive_test.rb +++ b/test/extended_should_receive_test.rb @@ -27,8 +27,8 @@ def test_accepts_list_of_methods def test_contraints_apply_to_all_expectations @mock.should_receive(:foo, :bar => :baz).with(1) - ex = assert_raises(check_failed_error) { @obj.foo(2) } - ex = assert_raises(check_failed_error) { @obj.bar(2) } + assert_raises(check_failed_error) { @obj.foo(2) } + assert_raises(check_failed_error) { @obj.bar(2) } assert_equal :baz, @obj.bar(1) end diff --git a/test/new_instances_test.rb b/test/new_instances_test.rb index 8eef776..dd9448f 100644 --- a/test/new_instances_test.rb +++ b/test/new_instances_test.rb @@ -108,13 +108,13 @@ def test_new_instances_will_pass_args_to_new def test_new_gets_block_after_restubbing flexstub(Cat).new_instances { } x = :not_called - m = Cat.new("Fido") { x = :called } + Cat.new("Fido") { x = :called } assert_equal :called, x flexmock_teardown flexstub(Cat).new_instances { } x = :not_called - m = Cat.new("Fido") { x = :called } + Cat.new("Fido") { x = :called } assert_equal :called, x end diff --git a/test/partial_mock_test.rb b/test/partial_mock_test.rb index f2aefac..5e98cf0 100644 --- a/test/partial_mock_test.rb +++ b/test/partial_mock_test.rb @@ -634,7 +634,7 @@ def test_partial_mocks_leaves_NoMethodError_exceptions_raised_by_the_original_me exception = assert_raises(NameError) do obj.mocked_method end - assert_match /undefined method `does_not_exist' for/, exception.message + assert_match(/undefined method `does_not_exist' for/, exception.message) end def test_it_checks_whether_mocks_are_forbidden_before_forwarding_the_call