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

match diff output should look like match_array when matching arrays #1432

Open
ghost opened this issue Oct 3, 2023 · 2 comments
Open

match diff output should look like match_array when matching arrays #1432

ghost opened this issue Oct 3, 2023 · 2 comments

Comments

@ghost
Copy link

ghost commented Oct 3, 2023

Subject of the issue

expect(["a", "b", "c"]).to match(["a", "b"]) should print unexpected extra elements in a nice way like expect(["a", "b", "c"]).to match_array(["a", "b"])

Since match checks order while match_array does not, there is no way to get pretty diffs and check order of an array and get a nice diff. For very large matches (like API response matching) this makes the failure message hard to use. See this gist for an example

Your environment

  • Ruby version: 3.1.4
  • rspec-expectations version: 3.12.2

Steps to reproduce

RSpec.describe 'matching arrays' do
  it 'returns a nice diff when there are unexpected extra elements' do
    expect(["a", "b"]).to match(["a"])
  end
end

Expected behavior

expected collection contained:  ["a"]
actual collection contained:    ["a", "b"]
the extra elements were:        ["b"]

Actual behavior

expected ["a", "b", "c"] to match ["a", "b"]

@pirj
Copy link
Member

pirj commented Oct 3, 2023

Does super_diff solve this by any chance?
Would you like to send a PR to improve this otherwise?

@ghost
Copy link
Author

ghost commented Oct 5, 2023

I think super_diff only works if there are no nested matchers.

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

1 participant