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

Don't pass implicit blocks for method_missing stubs #885

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

danielma
Copy link

Switch from send :define_method to class_eval for stubbed methods
that would otherwise by handled by method_missing

With the previous implementation, the block passed to stub is in
scope during define_method, which means that once a method on an
object has been stubbed, subsequent method calls will always receive
that implicit block.

I've added a new test that presents this behavior with the existing
implementation, and works properly with this change.

Switch from `send :define_method` to `class_eval` for stubbed methods
that would otherwise by handled by `method_missing`

With the previous implementation, the block passed to `stub` is in
scope during `define_method`, which means that once a method on an
object has been stubbed, subsequent method calls will always receive
that implicit block.

I've added a new test that presents this behavior with the existing
implementation, and works properly with this change.
@zenspider
Copy link
Collaborator

Why does this matter?

@zenspider zenspider self-assigned this Jan 21, 2023
@danielma
Copy link
Author

It matters because the existing implementation can cause behavior changes to the original class. This change attempts to improve stub cleanup to be more comprehensive

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants