Accrue.Test.MailerAssertions (accrue v0.3.0)

Copy Markdown View Source

ExUnit-style assertions for Accrue.Mailer.Test intent captures (D6-05). Symmetric with Accrue.Test.PdfAssertions.

Usage

use Accrue.Test.MailerAssertions
# or
import Accrue.Test.MailerAssertions

Matching

  • :type -> email intent type, also accepted as the first argument
  • :to -> assigns[:to] || assigns["to"]
  • :customer_id -> assigns[:customer_id] || assigns["customer_id"]
  • :assigns -> subset match on the provided assign keys
  • :matches -> 1-arity predicate escape hatch on %{type:, assigns:}

All helpers consume {:accrue_email_delivered, type, assigns} tuples sent by Accrue.Mailer.Test.deliver/2. Messages are process-local (no cross-test leakage), so async: true is safe. Cross-process owner or global capture modes are intentionally not the default; if a host test needs them, name that mode explicitly and treat it with the same caution as Mox or Swoosh global mode.

Summary

Functions

Asserts that an email matching type_or_matcher and opts was delivered through Accrue.Mailer.Test.

Asserts exactly expected_count emails are delivered within the 100ms window. Flunks with the actual count on mismatch.

Asserts that no :accrue_email_delivered messages are in the mailbox. Drains any pending message and flunks on the first one found.

Refutes that an email matching type_or_matcher and opts was delivered within timeout (default 100ms).

Functions

assert_email_sent(type_or_matcher, opts \\ [], timeout \\ 100)

(macro)

Asserts that an email matching type_or_matcher and opts was delivered through Accrue.Mailer.Test.

assert_emails_sent(expected_count)

Asserts exactly expected_count emails are delivered within the 100ms window. Flunks with the actual count on mismatch.

assert_no_emails_sent()

Asserts that no :accrue_email_delivered messages are in the mailbox. Drains any pending message and flunks on the first one found.

refute_email_sent(type_or_matcher, opts \\ [], timeout \\ 100)

(macro)

Refutes that an email matching type_or_matcher and opts was delivered within timeout (default 100ms).