Assert logged events using have_logged_event (simple cases)#11001
Merged
Assert logged events using have_logged_event (simple cases)#11001
Conversation
zachmargolis
approved these changes
Jul 30, 2024
Contributor
zachmargolis
left a comment
There was a problem hiding this comment.
much easier to read as a separate PR, thanks! LGTM
Contributor
Author
|
Actually, I'll need to make some revisions here, since the order of assertions is different, i.e. |
changelog: Internal, Automated Testing, Assert logged events using have_logged_event
Previously, the event only existed by the time the action was called since it was referenced in the stubs setup before the action call. Now the assertion happens after, so the event has to be created elsewise.
73fb779 to
9ef2719
Compare
This was referenced Jul 31, 2024
mitchellhenke
pushed a commit
that referenced
this pull request
Jul 31, 2024
* Assert logged events using have_logged_event changelog: Internal, Automated Testing, Assert logged events using have_logged_event * Reshuffle have_logged_event after action that logs * Remove unnecessary pii_like_keypaths stub expectatino * Fix phone spec stub setup for NewPhoneForm * Ensure event always created before running disavowal specs Previously, the event only existed by the time the action was called since it was referenced in the stubs setup before the action call. Now the assertion happens after, so the event has to be created elsewise. * Restore accidental action removal / shuffle * Document missing analytics properties flagged by FakeAnalytics * Remove redundant conflicting stub on Analytics#track_event * Reshuffle have_logged_event after action that logs * Remove unnecessary allowed_extra_analytics * Remove redundant conflicting stub on Analytics#track_event * Reshuffle have_logged_event after action that logs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🛠 Summary of changes
Updates specs to replace
expect(@analytics).to receive(:track_event).withwith equivalentexpect(@analytics).to have_logged_event.This includes changes which can be ported over easily using simple pattern replacement (+ Rubocop autocorrection).
Pattern:
receive\(:track_event\).(\n\s+)?with\((\n\s+)?('[^']+')Replacement:
have_logged_event($2$3Remaining usage includes negated assertions, and assertions not including a specific event name being logged.
Why?
have_logged_eventincludes a number of additional helpers implemented through theFakeAnalyticsclass:📜 Testing Plan
Verify build passes.