Assert Two Arrays Have The Same Items With RSpec
Methods that return arrays of values with inconsistent orderings can be annoying to test with the #eq
matcher. To keep your test from fickering, you'd have to ensure the comparison is the same every time.
It'd be better if we could keep our test focused and simple. If sort order isn't something we care about, then it shouldn't be part of our test. RSpec has a matcher for this kind of scenario -- #match_array
.
This allows us to ensure that each side of the comparison has the same set values, irrespective of ordering.
Last updated