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

Consolidate logic between deep inspection and diffing #20

Closed mcmire closed 5 years ago

mcmire commented 5 years ago

Currently we use a different algorithm to inspect two complex objects on a single line and then generate a diff of those objects. Here is a good example of this:

Differing objects.

Expected: #<SuperDiff::Test::Player:0x7fcdb0a77440 @handle="martymcfly" @character="mirage" @inventory=["flatline", "purple body shield"] @shields=0.6 @health=0.3 @ultimate=0.8>
  Actual: #<SuperDiff::Test::Player:0x7fcdb0a77300 @handle="docbrown" @character="lifeline" @inventory=["wingman", "mastiff"] @shields=0.6 @health=0.3 @ultimate=0.8>

Diff:

  #<SuperDiff::Test::Player {
-   handle: "martymcfly",
+   handle: "docbrown",
-   character: "mirage",
+   character: "lifeline",
    inventory: [
-     "flatline",
+     "wingman",
-     "purple body shield"
+     "mastiff"
    ],
    shields: 0.6,
    health: 0.3,
    ultimate: 0.8
  }>

In this case, "Expected" vs "Actual" uses deep inspection to generate an inspection of the two objects, whereas the diff uses an entirely different algorithm. Thus, you get SuperDiff::Test::Player:0x7fcdb0a77440 vs SuperDiff::Test::Player. Maybe there's a way we can make use of the pretty printing algorithm to generate a diff?

mcmire commented 5 years ago

Not sure this is really necessary, actually. There's a good reason we don't show the object id in the diff: because they're different between the two objects. Closing for now.

mcmire commented 5 years ago

Well, actually, there is an inconsistency here. As you can see here, when the diff formatter spits out an object, it displays instance variables as though they are attributes. However, the deep inspector shows them more as PrettyPrinter would:

Screen Shot 2019-09-09 at 9 26 24 PM
mcmire commented 5 years ago

Fixed in 89b7b776fd3ce13cc31d0a20dba172dc6b81a411.