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

Deprecation warnings for strict keyword argument matching #563

Closed

Conversation

floehopper
Copy link
Member

This will generate a deprecation warning if Ruby >= v2.7, Configuration#strict_keyword_argument_matching? is false, and a hash matcher would stop matching if strict matching were enabled. For example:

mock = mock()
mock.expects(:method).with(:key => 42)
mock.method({ :key => 42 })

Deprecation warning: :key => 42 will stop matching {:key => 42} when strict keyword argument matching is enabled.

mock = mock()
mock.expects(:method).with(1, { :key => 42 }
mock.method(1, :key => 42)

Deprecation warning: {:key => 42} will stop matching :key => 42 when strict keyword argument matching is enabled.

@floehopper
Copy link
Member Author

@wasabigeek What do you think of this?

@floehopper floehopper added this to the 1.16.0 milestone Oct 13, 2022
@floehopper floehopper modified the milestones: 1.16.0, 1.2.0, 2.0.0 Oct 14, 2022
@floehopper floehopper force-pushed the deprecation-warnings-for-strict-keyword-arguments branch from 061453c to a8555d8 Compare October 14, 2022 16:58
Copy link
Contributor

@wasabigeek wasabigeek left a comment

Choose a reason for hiding this comment

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

The code looks good to me, I haven't tested it locally though.

Some minor thoughts but I don't think they're crucial.

@floehopper floehopper force-pushed the deprecation-warnings-for-strict-keyword-arguments branch 2 times, most recently from 776a696 to 40cec7a Compare October 15, 2022 16:03
floehopper added a commit that referenced this pull request Oct 15, 2022
This will generate a deprecation warning if Ruby >= v2.7,
Configuration#strict_keyword_argument_matching? is false, and a hash
matcher would stop matching if strict matching were enabled.

* Example 1:

    mock = mock()
    mock.expects(:method).with(:key => 42)
    mock.method({ :key => 42 })

Expected keyword arguments (:key => 42), but received positional hash
({:key => 42}). These will stop matching when strict keyword argument
matching is enabled. See the documentation for
Mocha::Configuration#strict_keyword_argument_matching=.

* Example 2:

    mock = mock()
    mock.expects(:method).with(1, { :key => 42 }
    mock.method(1, :key => 42)

Expected positional hash ({:key => 42}), but received keyword arguments
(:key => 42). These will stop matching when strict keyword argument
matching is enabled. See the documentation for
Mocha::Configuration#strict_keyword_argument_matching=.

See #563 for discussions about these changes.

Co-authored-by: Nicholas Koh <nicholas.koh@shopify.com>
@floehopper floehopper closed this Oct 15, 2022
@floehopper floehopper force-pushed the deprecation-warnings-for-strict-keyword-arguments branch from 40cec7a to 981c31b Compare October 15, 2022 16:12
@floehopper floehopper deleted the deprecation-warnings-for-strict-keyword-arguments branch October 15, 2022 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants