Make analytics event matcher show a diff#7252
Conversation
[skip changelog]
aduth
left a comment
There was a problem hiding this comment.
This'll be a really handy feature for debugging!
| message += " got: #{actual}\n\n" | ||
| message += "Diff:#{differ.diff(actual, expected)}" | ||
| message | ||
| elsif matching_events&.length == 1 && attributes.instance_of?(RSpec::Matchers::BuiltIn::Include) |
There was a problem hiding this comment.
Hopefully a side-effect of this feature is to encourage the use of these matchers for partial matchers, in support of a ticket created a while back to change the default behavior of the hash-based matching.
There was a problem hiding this comment.
Yeah, and at least it'll be easier to implement that ticket now since the diffs of any existing tests that end up broken will be easier to parse
There was a problem hiding this comment.
Yeah, and at least it'll be easier to implement that ticket now since the diffs of any existing tests that end up broken will be easier to parse
Yep, though realistically the only way I see that ticket actually getting implemented is with a mass-conversion of existing hash assertions to equivalent include(...).
There was a problem hiding this comment.
what if we renamed this matcher have_logged_event_including and create a new have_logged_event_exactly and start encouraging that?
🛠 Summary of changes
Updates our
have_logged_eventcustom matcher to show diffs of unexpected analytics eventsI only implemented diffs when we can tell that the expected event occurred exactly once but the attributes are different than expected. This will show diffs for cases when we do a direct comparison of the event's attributes to a hash (example) and when we use an
includematcher (example). Other scenarios will fall back to the existing failure messageThis is just a change to our tests. No changes to application code
👀 Screenshots
Example of rspec's built-in diff for hashes:
Current way that have_logged_event displays diffs:
Updated diff for hash comparison:
Updated diff for comparing to an include matcher:
[skip changelog]