class Amber::Mailer::MemoryAdapter

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.cr

Class Method Summary

Instance Method Summary

Instance methods inherited from class Amber::Mailer::DeliveryAdapter

deliver(email : Email) : DeliveryResult deliver

Class Method Detail

def self.clear : Nil #

Clears all stored deliveries.

Should be called in test setup or teardown to ensure a clean state.


[View source]
def self.count : Int32 #

Returns the number of emails that have been delivered.


[View source]
def self.deliveries : Array(Email) #

Returns all emails that have been delivered through this adapter.


[View source]
def self.last : Email | Nil #

Returns the most recently delivered email, or nil if none have been delivered.


[View source]

Instance Method Detail

def deliver(email : Email) : DeliveryResult #

Delivers an email by storing it in the in-memory deliveries array.

Always returns a successful delivery result.


[View source]