Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Add tests and fix for ruby 3 keyword arguments issues #1407

Merged

Conversation

jhottenstein
Copy link
Contributor

I recently ran into a similar issue to #1396 when upgrading our codebase to ruby 3.

This PR adds tests for both scenarios (receive with a block with kwargs and and_call_original when mocking a method that uses keyword arguments). The tests may be redundant since fixing recorder fixed both tests.

I noticed other spots where define_method is used to intercept method calls (e.g.

define_method(method_name) do |*args, &block|
and
define_method(method) do |*args, &block|
) so this PR may not be sufficient to fix all keyword argument issues

@JonRowe
Copy link
Member

JonRowe commented Jan 25, 2021

Thanks for tackling this, you need to wrap the specs in eval blocks so that they can safely be ignored by legacy Rubies. Theres examples around of this in #1385

@jhottenstein
Copy link
Contributor Author

Thanks for the review and the pointer. I was unsure how rspec handled keyword args and legacy rubies.

Do you want me to add more specs for keyword args in the other spots that I highlighted? Our codebase didn't run into issues with those spots but I'm happy to attempt a reproduction or add more keyword argument tests in general.

@JonRowe
Copy link
Member

JonRowe commented Jan 25, 2021

Do you want me to add more specs for keyword args in the other spots that I highlighted? Our codebase didn't run into issues with those spots but I'm happy to attempt a reproduction or add more keyword argument tests in general.

More keyword specs in examples are welcome, we are lacking that aspect of coverage, although I'd prefer a seperate PR for general keyword examples, and focus this on your fix 👍

@jhottenstein jhottenstein force-pushed the jess/add-kwarg-support-for-any-instance branch from f4ded4a to 585bc7e Compare January 26, 2021 03:09
@JonRowe
Copy link
Member

JonRowe commented Jan 26, 2021

This looks great apart from the JRuby failures, can you investigate?

@jhottenstein jhottenstein force-pushed the jess/add-kwarg-support-for-any-instance branch 2 times, most recently from 71cefb8 to 1bf14e8 Compare January 26, 2021 18:58
@headius
Copy link

headius commented Jan 26, 2021

Was this fix really for JRuby? If we are differing on some language-level behavior compared to an equivalent CRuby, we definitely would like to see a bug report for that.

Edit: referring to 740046b

@jhottenstein
Copy link
Contributor Author

@JonRowe It was a bad test setup. wrapped can be expect/allow or expect_any_instance_of/allow_any_instance_of. A block implementation cannot be shared between those cases when yield_receiver_to_any_instance_implementation_blocks is true.

I set it to false for the test that pass block implementations. I could move the test into the individual blocks (allow(...).to receive/expect(...).to receive/allow_any_instance_of.to receive/expect_any_instance_of.to receive

@jhottenstein
Copy link
Contributor Author

@headius, I can write something up. Let me create a simpler repro.

@JonRowe JonRowe merged commit 4e607c0 into rspec:main Jan 27, 2021
JonRowe added a commit that referenced this pull request Jan 27, 2021
JonRowe added a commit that referenced this pull request Jan 27, 2021
…-any-instance

Add tests and fix for ruby 3 keyword arguments issues
JonRowe added a commit that referenced this pull request Jan 27, 2021
@JonRowe
Copy link
Member

JonRowe commented Jan 27, 2021

Thanks 🙏

@dorner
Copy link
Contributor

dorner commented Jan 28, 2021

@JonRowe can we push a release for this? Currently upgrading to Ruby 3 breaks a whole lot of specs.

@JonRowe
Copy link
Member

JonRowe commented Jan 28, 2021

A release is planned but I have to fix some CI issues first.

@JonRowe
Copy link
Member

JonRowe commented Jan 28, 2021

Released as v3.10.2

@dorner
Copy link
Contributor

dorner commented Jan 29, 2021

Awesome, thanks!

yujinakayama pushed a commit to yujinakayama/rspec-monorepo that referenced this pull request Oct 6, 2021
…ess/add-kwarg-support-for-any-instance

Add tests and fix for ruby 3 keyword arguments issues

---
This commit was imported from rspec/rspec-mocks@4e607c0.
yujinakayama pushed a commit to yujinakayama/rspec-monorepo that referenced this pull request Oct 6, 2021
[skip ci]

---
This commit was imported from rspec/rspec-mocks@ade4efa.
yujinakayama pushed a commit to yujinakayama/rspec-monorepo that referenced this pull request Oct 6, 2021
…ess/add-kwarg-support-for-any-instance

Add tests and fix for ruby 3 keyword arguments issues

---
This commit was imported from rspec/rspec-mocks@d0b96af.
yujinakayama pushed a commit to yujinakayama/rspec-monorepo that referenced this pull request Oct 6, 2021
[skip ci]

---
This commit was imported from rspec/rspec-mocks@675f32e.
pirj pushed a commit that referenced this pull request Nov 1, 2022
pirj pushed a commit that referenced this pull request Nov 1, 2022
pirj pushed a commit that referenced this pull request Nov 1, 2022
JonRowe added a commit that referenced this pull request Nov 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants