# config/environments/test.rb
config.action_mailer.delivery_method = :test
config.action_mailer.default_url_options = { host: "example.com" }
# spec/support/action_mailer.rb
RSpec.configure do |config|
config.before(:each) do
ActionMailer::Base.deliveries.clear
end
end
# spec/support/mailer_helpers.rb
module MailerHelpers
def emails
ActionMailer::Base.deliveries
end
def last_email
emails.last
end
end
RSpec.configure do |config|
config.include MailerHelpers, type: :mailer
end
Here is an example from an article by thoughtbot: