-
-
Notifications
You must be signed in to change notification settings - Fork 103
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
arrays_match? is not indifferent to array order #568
Comments
I'd expect
|
This is a private api, and I'd expect your example to fail anyway, closing here but if you can demonstrate an issue with the upstream api's that we agree is broken I'll reconsider |
@JonRowe Gotcha. I'll take the example of |
It looks like |
I'm not clear on what your original issue was:
Will only match:
Where
If you're using a matcher e.g.
Then the ordering here is still the same, it should only pass with:
Dence why I closed this, argument order is always dependent and your example should fail because you're matching things in the wrong order. By default Ruby matches literal arrays, (e.g. if If you use a matcher like
Again this is all by design because usually array order is important and we use Ruby for literal matching wherever possible so the ordering has to match, or we provide matchers for when you want a derivative to pass or a subset to pass. |
Just for clarity, the original issue is something like this (proprietary info removed):
I'm surprised that array order is normally regarded as important in Ruby since it's such a common place for flaky tests to appear in many companies I've worked at, but I'll record that |
Arrays have order, thats just how they are, I agree its common to see them being a source of flaky tests, but its often because people have forgotten to properly order a query rather than the arrays themselves at fault. |
Subject of the issue
Support::FuzzyMatcher.arrays_match? is not indifferent to array ordering. This affects a number of things upstream that depend on it such as constructions like
expect(SomeClass).to receive(:method).with(..., some_array)
that developers might use, unaware that ifsome_array
is different than whatSomeClass
might receive in test.Normally we would prevent this by using a Rubocop rule like MatchArray but I think this example will go undetected.
Attempted fixes
return true if (expected_list - actual_list).empty?
toarrays_match?
This works until object hashes are different (as in the below example).
This doesn't work when there is no order comparison between types, also in below example.
This also fails with different object hashes.
Your environment
Steps to reproduce
Example of failing test
Expected behavior
Devs at my current company are clearly expecting
a1
to matcha2
when they write a.with
expression that ultimately ends up calling FuzzyMatcher.Actual behavior
FuzzyMatcher zips both arrays together (where the order dependency comes in) and then fuzzy matches recursively on the elements.
The text was updated successfully, but these errors were encountered: