Rails includes a way to see what an e-mail will look like.
Integration to RSpec
All you need to do is implement a preview-class in spec/mailers/previews/notifier_preview.rb
:
class NotifierPreview < ActionMailer::Preview
def welcome
Notifier.welcome(User.first)
end
end
And adapt the preview load path in your application.rb
:
config.action_mailer.preview_path = "#{Rails.root}/spec/mailers/previews" # this is already set as default by Rails
Then a preview will be available in the browser at http://localhost:3000/rails/mailers/notifier/welcome
as well as a list of previews at http://localhost:3000/rails/mailers
.
Rails <4.1
You could use Mailcatcher.
See also
- You can preview mails directly in your local mail client
- You might want to add specs for your mailer preview too
Posted to makandra dev (2015-01-12 13:33)