diff --git a/Changelog.md b/Changelog.md index 2e7de388e..55ab291de 100644 --- a/Changelog.md +++ b/Changelog.md @@ -9,6 +9,7 @@ Bug Fixes: * Issue `ArgumentError` rather than `TypeError` when unsupported methods on unsupported objects are attempted to be stubbed. (@zhisme, #1357) +* Fix kwargs delegation warning in `and_call_original`. (@pirj, #????) ### 3.10.0 / 2020-10-30 [Full Changelog](http://github.com/rspec/rspec-mocks/compare/v3.9.1...v3.10.0) diff --git a/Gemfile b/Gemfile index 1423ace45..37ee751ea 100644 --- a/Gemfile +++ b/Gemfile @@ -3,7 +3,7 @@ source "https://rubygems.org" gemspec branch = File.read(File.expand_path("../maintenance-branch", __FILE__)).chomp -%w[rspec rspec-core rspec-expectations rspec-support].each do |lib| +%w[rspec rspec-core rspec-expectations].each do |lib| library_path = File.expand_path("../../#{lib}", __FILE__) if File.exist?(library_path) && !ENV['USE_GIT_REPOS'] gem lib, :path => library_path @@ -12,6 +12,8 @@ branch = File.read(File.expand_path("../maintenance-branch", __FILE__)).chomp end end +gem 'rspec-support', github: 'rspec/rspec-support', branch: 'add-proc-kwargs-detection-support' + if ENV['DIFF_LCS_VERSION'] gem 'diff-lcs', ENV['DIFF_LCS_VERSION'] else diff --git a/lib/rspec/mocks/message_expectation.rb b/lib/rspec/mocks/message_expectation.rb index fd0cbe48a..03641ce5c 100644 --- a/lib/rspec/mocks/message_expectation.rb +++ b/lib/rspec/mocks/message_expectation.rb @@ -1,4 +1,5 @@ RSpec::Support.require_rspec_support 'reentrant_mutex' +RSpec::Support.require_rspec_support "with_keywords_when_needed" module RSpec module Mocks @@ -98,7 +99,7 @@ def and_return(first_value, *values) # expect(counter.count).to eq(original_count + 1) def and_call_original wrap_original(__method__) do |original, *args, &block| - original.call(*args, &block) + RSpec::Support::WithKeywordsWhenNeeded.call(original, *args, &block) end end diff --git a/lib/rspec/mocks/verifying_message_expectation.rb b/lib/rspec/mocks/verifying_message_expectation.rb index c1faa5d3c..83b9b5838 100644 --- a/lib/rspec/mocks/verifying_message_expectation.rb +++ b/lib/rspec/mocks/verifying_message_expectation.rb @@ -1,5 +1,3 @@ -RSpec::Support.require_rspec_support 'method_signature_verifier' - module RSpec module Mocks # A message expectation that knows about the real implementation of the diff --git a/spec/rspec/mocks/and_call_original_spec.rb b/spec/rspec/mocks/and_call_original_spec.rb index f4dee7cbc..49b1745c7 100644 --- a/spec/rspec/mocks/and_call_original_spec.rb +++ b/spec/rspec/mocks/and_call_original_spec.rb @@ -12,6 +12,10 @@ def meth_2(x) yield x, :additional_yielded_arg end + def meth_3(a: '') + a + end + def self.new_instance new end @@ -53,6 +57,12 @@ def self.new_instance expect(instance.meth_1).to eq(:original) end + it 'supports keyword arguments' do + expect(instance).to receive(:meth_3).and_call_original + value = instance.meth_3(a: :a) + expect(value).to eq(:a) + end + it 'passes args and blocks through to the original method' do expect(instance).to receive(:meth_2).and_call_original value = instance.meth_2(:submitted_arg) { |a, b| [a, b] }