class
Amber::Mailer::MemoryAdapter
- Amber::Mailer::MemoryAdapter
- Amber::Mailer::DeliveryAdapter
- Reference
- Object
Overview
In-memory delivery adapter for testing and development.
Stores all delivered emails in a thread-safe class-level array instead of actually sending them. This allows tests to verify that emails were sent with the correct content, recipients, and structure.
Usage in Tests
# Clear any previously stored emails
Amber::Mailer::MemoryAdapter.clear
# Deliver an email
WelcomeMailer.new("Alice", "[email protected]")
.to("[email protected]")
.subject("Welcome!")
.deliver
# Verify delivery
Amber::Mailer::MemoryAdapter.count.should eq 1
Amber::Mailer::MemoryAdapter.last.not_nil!.subject.should eq "Welcome!"
Thread Safety
All access to the deliveries array is synchronized through a Mutex, making this adapter safe for use in concurrent test environments.
Defined in:
amber/mailer/memory_adapter.crClass Method Summary
-
.clear : Nil
Clears all stored deliveries.
-
.count : Int32
Returns the number of emails that have been delivered.
-
.deliveries : Array(Email)
Returns all emails that have been delivered through this adapter.
-
.last : Email | Nil
Returns the most recently delivered email, or nil if none have been delivered.
Instance Method Summary
-
#deliver(email : Email) : DeliveryResult
Delivers an email by storing it in the in-memory deliveries array.
Instance methods inherited from class Amber::Mailer::DeliveryAdapter
deliver(email : Email) : DeliveryResult
deliver
Class Method Detail
Clears all stored deliveries.
Should be called in test setup or teardown to ensure a clean state.
Returns all emails that have been delivered through this adapter.
Returns the most recently delivered email, or nil if none have been delivered.
Instance Method Detail
Delivers an email by storing it in the in-memory deliveries array.
Always returns a successful delivery result.