You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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"]
The text was updated successfully, but these errors were encountered:
Subject of the issue
expect(["a", "b", "c"]).to match(["a", "b"])
should print unexpected extra elements in a nice way likeexpect(["a", "b", "c"]).to match_array(["a", "b"])
Since
match
checks order whilematch_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 exampleYour environment
Steps to reproduce
Expected behavior
Actual behavior
expected ["a", "b", "c"] to match ["a", "b"]
The text was updated successfully, but these errors were encountered: