Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use capture_emails helper to improve email assertions in specs #29245

Merged
merged 2 commits into from Feb 19, 2024

Conversation

mjankowski
Copy link
Contributor

Related changes here:

  • Add ActionMailer::TestHelper to spec config, to make this helper method available
  • Remove before/after where we were explicitly resetting the deliveries collection
  • Wrap the code that we expect to generate emails with the capture_emails helper
  • Update the assertions to be on this set of captured emails
  • In a few cases where we were just checking for emails at all, expand coverage a bit more to specify the to recipient and the subject

Main benefit here is increased confidence that the emails we are asserting against came from where we expected them. I think there's a small but nice readability improvement on the assertions as well. Possible future improvements here:

  • The auth/sessions block where we exceed the 2FA rate limit is a little awkward/repetitive, might be good to extract methods here at some point
  • We are using the email_spec gem helpers in our mailer specs, but not in these controller specs. I did not do this here because I recall some issue with them not being fully chainable -- but this might be good future improvement as well.

Copy link

codecov bot commented Feb 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (86500e3) 85.01% compared to head (a769d54) 85.01%.
Report is 96 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #29245      +/-   ##
==========================================
- Coverage   85.01%   85.01%   -0.01%     
==========================================
  Files        1059     1060       +1     
  Lines       28277    28314      +37     
  Branches     4538     4542       +4     
==========================================
+ Hits        24040    24071      +31     
- Misses       3074     3077       +3     
- Partials     1163     1166       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ClearlyClaire
Copy link
Contributor

Will actually review next week, but that sounds like a great improvement!

@renchap renchap added testing Automated lint and test suites ruby Pull requests that update Ruby code labels Feb 16, 2024
@mjankowski
Copy link
Contributor Author

Pushed commit to restore the email count checks.

@ClearlyClaire ClearlyClaire added this pull request to the merge queue Feb 19, 2024
Merged via the queue into mastodon:main with commit 64f9939 Feb 19, 2024
28 checks passed
@mjankowski mjankowski deleted the emails-number-one-ok branch February 19, 2024 16:16
skerit pushed a commit to 11ways/mastodon that referenced this pull request Feb 27, 2024
Ember-ruby pushed a commit to Ember-ruby/mastodon-glitch that referenced this pull request Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ruby Pull requests that update Ruby code testing Automated lint and test suites
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants