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

Possible enhancement for responds_with matcher? #578

Closed
vlad-pisanov opened this issue Oct 21, 2022 · 5 comments
Closed

Possible enhancement for responds_with matcher? #578

vlad-pisanov opened this issue Oct 21, 2022 · 5 comments

Comments

@vlad-pisanov
Copy link

Currently, the matcher responds_with takes 2 params: an attribute and a value, like:

responds_with(:name, 'Joe')

How about introducing a variation of this matcher that takes multiple attribute-value pairs? e.g.

responds_with(name: 'Joe', age: 21, salary: 40_000)

The matcher would succeed if all attributes match. This would give us a compact way of matching complex objects, and the syntax would be symmetrical to the has_entries matcher that we currently have for Hashes:

has_entries(name: 'Joe', age: 21, salary: 40_000)
@floehopper
Copy link
Member

@vlad-pisanov Thanks for the suggestion. At first glance it sounds sensible to me. I'll take a proper look at it early next week.

@floehopper
Copy link
Member

@vlad-pisanov I haven't got much time at the moment, but I managed to find a few minutes to draft this PR. Is that roughly what you had in mind?

@vlad-pisanov
Copy link
Author

@floehopper nice, that's exactly it! I like the idea of using AllOf.new(...) under the hood, very semantic

floehopper added a commit that referenced this issue Nov 2, 2022
This provides a terser syntax for matching an object which responds in a
certain way, e.g.

    object = mock()
    object.expects(:method_1).with(responds_with(:upcase => "FOO", :reverse => "oof"))
    object.method_1("foo")
    # no error raised, because "foo".upcase == "FOO" and "foo".reverse == "oof"

Addresses #578.
floehopper added a commit that referenced this issue Nov 12, 2023
This provides a terser syntax for matching an object which responds in a
certain way, e.g.

    object = mock()
    object.expects(:method_1).with(responds_with(:upcase => "FOO", :reverse => "oof"))
    object.method_1("foo")
    # no error raised, because "foo".upcase == "FOO" and "foo".reverse == "oof"

Addresses #578.
floehopper added a commit that referenced this issue Nov 12, 2023
This provides a terser syntax for matching an object which responds in a
certain way, e.g.

    object = mock()
    object.expects(:method_1).with(responds_with(:upcase => "FOO", :reverse => "oof"))
    object.method_1("foo")
    # no error raised, because "foo".upcase == "FOO" and "foo".reverse == "oof"

Addresses #578.
floehopper added a commit that referenced this issue Nov 12, 2023
This provides a terser syntax for matching an object which responds in a
certain way, e.g.

    object = mock()
    object.expects(:method_1).with(responds_with(:upcase => "FOO", :reverse => "oof"))
    object.method_1("foo")
    # no error raised, because "foo".upcase == "FOO" and "foo".reverse == "oof"

Addresses #578.
@floehopper
Copy link
Member

Closed by #579. Sorry it's taken so long!

@floehopper
Copy link
Member

Released in v2.2.0

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

No branches or pull requests

2 participants