Skip to content

Spec helpers for asserting delivered emails - #3002

Open
mroderick wants to merge 1 commit into
codebar:masterfrom
mroderick:test/email-assertion-helpers
Open

mroderick wants to merge 1 commit into
codebar:masterfrom
mroderick:test/email-assertion-helpers

Conversation

@mroderick

@mroderick mroderick commented Oct 9, 2026 •

Copy link
Copy Markdown
Collaborator

This PR was motivated by trying to harvest knowledge from a recent agent session and turn it into something that is actively used, rather than stuffing it into the AGENTS.md file, where it can deteriorate over time.


Adds a spec helper pair that encodes how delivered emails are asserted in this repo, so the knowledge lives in code next to a canary instead of relying on individual specs re-deriving it.

What each piece does

spec/support/helpers/email_helpers.rb

  • delivered_emails_to(member_or_address) — the test queue adapter is delayed_job with delay_jobs = false in test, so deliver_later delivers immediately into ActionMailer::Base.deliveries. This helper is the single place that selects by recipient.
  • email_html(mail) — the invitation mailers send multipart/mixed > multipart/alternative > text/html, so
    the root mail.body.decoded is empty and the html part must be read directly. premailer-rails inlines
    CSS on delivery as part of that restructuring.

spec/shared_contexts/email_helpers_spec.rb — a canary in the spirit of the existing 'with forgery
protection enforced' canary. It delivers a real WorkshopInvitationMailer.attending email and exercises
both helpers. If the mailer's part structure or the delivery path changes, the canary fails there instead
of silently weakening every email assertion that uses them.

spec/controllers/workshop_invitation_controller_spec.rb is refactored to consume the helpers: its local html_body definition and inline deliveries.find go away.

Review notes
  • Included globally via config.include EmailHelpers (mirrors config.include LoginHelpers in the same file); the method names are email-scoped enough to avoid clashes.
  • The canary had to live in spec/shared_contexts/, not next to the helper: rails_helper requires spec/support/** and RSpec then discovers the file again, running each example twice.
  • Asserting on the delivered html body is intentionally broad ('been confirmed'); the exact promoted copy is asserted where the waiting-list flag matters.
  • Left for follow-up: behaves_like_sending_workshop_emails could consume delivered_emails_to too, but it asserts counts and recipients today, so it was left untouched.

@mroderick
mroderick marked this pull request as ready for review October 9, 2026 07:37
@mroderick
mroderick requested a review from olleolleolle October 9, 2026 07:37

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant