Last active
December 16, 2015 01:59
-
-
Save mattvanhorn/5359374 to your computer and use it in GitHub Desktop.
Fast tests for your mailers in Rails
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# test/unit/mailers/my_mailer_test.rb | |
require 'minitest/spec' | |
require 'minitest/autorun' | |
require "minitest-matchers" | |
require 'action_mailer' | |
require "email_spec" | |
# IF WE'VE ALREADY LOADED RAILS, | |
# WE DON'T HAVE TO WORRY ABOUT HAML OR MAILER CONFIG | |
unless Object.const_defined? 'Rails' | |
# ONLY NECESSARY TO RECOGNIZE HAML TEMPLATES | |
# IF YOU ONLY USE ERB, YOU CAN OMIT THIS | |
require 'haml/util' | |
require 'haml/template/options' | |
require 'haml/engine' | |
require 'haml/helpers/action_view_extensions' | |
require "haml/template/plugin" | |
# END HAML SUPPORT STUFF | |
ActionMailer::Base.delivery_method = :test | |
ActionMailer::Base.view_paths = File.expand_path('../../../../app/views', __FILE__) | |
end | |
require File.expand_path('../../../../app/mailers/my_mailer', __FILE__) | |
describe MyMailer do | |
include EmailSpec::Helpers | |
include EmailSpec::Matchers | |
let(:the_email){ MyMailer.some_mail() } | |
it "has the right bit of text" do | |
the_email.must have_body_text("some bit of text") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment