Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix kwargs delegation warning in and_call_original #1383

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion lib/rspec/mocks/message_expectation.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
RSpec::Support.require_rspec_support 'reentrant_mutex'
RSpec::Support.require_rspec_support "with_keywords_when_needed"

module RSpec
module Mocks
Expand Down Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can't be used, it causes problems with arguments that implement to_hash and this module is being phased out for removal in RSpec 4.

end
end

Expand Down
2 changes: 0 additions & 2 deletions lib/rspec/mocks/verifying_message_expectation.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
10 changes: 10 additions & 0 deletions spec/rspec/mocks/and_call_original_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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] }
Expand Down