splitwise / super_diff

A more helpful way to view differences between complex data structures in RSpec.
https://splitwise.github.io/super_diff/
MIT License
982 stars 50 forks source link

When comparing arrays with nil values, NilClass is showing up in diff #86

Open mcmire opened 4 years ago

mcmire commented 4 years ago
Screen Shot 2020-05-23 at 2 38 23 PM
jas14 commented 2 hours ago

We could treat nil and other primitives as un-diffable against the HavingAttributes matcher. I don't particularly like that because nil actually does have attributes {to_s: '', to_i: 0} and so on; SuperDiff would break if you're testing that the actual object matches one of those interfaces.

Even deeper of an issue is that we try to intelligently compare array elements when using the eq expectation between arrays. Per the Ruby docs, arrays are == if when the arrays are the same length and each corresponding element is equal per the == operator. We shouldn't use fuzzy comparison when using the eq matcher, but unfortunately, by the time RSpec calls into SuperDiff, we've lost context on what the failed matcher even was. I'm not sure how to address that.