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

Improve Hash formatting in EnglishPhrasing.list #1193

Merged
merged 1 commit into from
Jun 14, 2020

Conversation

reshleman
Copy link
Contributor

@reshleman reshleman commented Jun 11, 2020

We're currently treating all Enumerables as an Array in this method,
resulting in a Hash being formatted as a list of two-element key-value
arrays.

This results in unexpected formatting in the default failure message for
a custom matcher when the expected value is a Hash.

This commit updates EnglishPhrasing.list to no longer format a Hash as
if it were an Array.

Fixes #1192.

Before:

Failure/Error: expect(nil).to custom_match({a: 1, foo: 'bar', bang: Object.new})
  expected nil to custom match [:a, 1], [:foo, "bar"], and [:bang, #<Object:0x00007fb89542bad0>]

After:

Failure/Error: expect(nil).to custom_match({a: 1, foo: 'bar', bang: Object.new})
  expected nil to custom match {:a=>1, :bang=>#<Object:0x00007f9f363b0b28>, :foo=>"bar"}

We're currently treating all Enumerables as an Array in this method,
resulting in a Hash being formatted as a list of two-element key-value
arrays.

This results in unexpected formatting in the default failure message for
a custom matcher when the `expected` value is a Hash.

This commit updates `EnglishPhrasing.list` to no longer format a Hash as
if it were an Array.

Fixes rspec#1192.
Copy link
Member

@pirj pirj left a comment

Choose a reason for hiding this comment

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

Looks good!
Nothing seems to be broken, well-aimed shot 👍

@pirj pirj requested a review from JonRowe June 12, 2020 08:13
@JonRowe JonRowe merged commit 8f475d8 into rspec:master Jun 14, 2020
JonRowe added a commit that referenced this pull request Jun 14, 2020
JonRowe added a commit that referenced this pull request Jun 14, 2020
Improve Hash formatting in `EnglishPhrasing.list`
JonRowe added a commit that referenced this pull request Jun 14, 2020
@pirj
Copy link
Member

pirj commented Jun 14, 2020

Thank you!
You're on the wall of fame now.

@reshleman reshleman deleted the re-expected-hash branch June 15, 2020 14:08
yujinakayama pushed a commit to yujinakayama/rspec-monorepo that referenced this pull request Oct 6, 2021
…reshleman/re-expected-hash

Improve Hash formatting in `EnglishPhrasing.list`

---
This commit was imported from rspec/rspec-expectations@08d44a3.
yujinakayama pushed a commit to yujinakayama/rspec-monorepo that referenced this pull request Oct 6, 2021
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.

Default failure message for custom matcher incorrectly formats expected hashes
3 participants