Skip to content

Commit

Permalink
Don't convert keywords to hash in #send for verifying doubles on Ruby…
Browse files Browse the repository at this point in the history
… 3 (#1520)

* Don't convert keywords to hash in #send for verifying doubles on Ruby 3

Co-authored-by: Charlie Honig <chonig@panoramaed.com>
  • Loading branch information
2 people authored and JonRowe committed Jan 10, 2023
1 parent 183b50b commit 9e8cf14
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
### Development
[Full Changelog](http://github.com/rspec/rspec-mocks/compare/v3.12.1...3-12-maintenance)

Bug Fixes:

* Fix keyword delegation in `send` for verifying doubles on Ruby 3.
(Charlie Honig, #1485)

### 3.12.2 / 2023-01-07
[Full Changelog](http://github.com/rspec/rspec-mocks/compare/v3.12.1...v3.12.2)

Expand Down
2 changes: 2 additions & 0 deletions lib/rspec/mocks/verifying_double.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@ def __send__(name, *args, &block)
ensure
@__sending_message = nil
end
ruby2_keywords :__send__ if respond_to?(:ruby2_keywords, true)
$VERBOSE = old

def send(name, *args, &block)
__send__(name, *args, &block)
end
ruby2_keywords :send if respond_to?(:ruby2_keywords, true)

def initialize(doubled_module, *args)
@doubled_module = doubled_module
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,15 @@ module Mocks
dbl.kw_args_method(1, {:required_arg => 2, :optional_arg => 3})
end
end

context "when using `send`" do
let(:dbl) { instance_double(Class.new { eval "def m(k:); end" }) }

it "matches against keyword arguments" do
expect(dbl).to receive(:m).with(:k => 1)
dbl.send(:m, :k => 1)
end
end
end
end
end
Expand Down

0 comments on commit 9e8cf14

Please sign in to comment.