Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Decouple action mailer #3

Merged
merged 2 commits into from Mar 4, 2012
Jump to file or symbol
Failed to load files and symbols.
+46 −6
Split
View
@@ -1,6 +1,6 @@
# CapybaraEmail #
-Easily test your ActionMailer emails in your Capybara integration tests.
+Easily test ActionMailer and Mail emails in your Capybara integration tests
## Installation ##
@@ -23,7 +23,7 @@ Or install it yourself as:
feature 'Emailer' do
background do
- # will clear the ActionMailer queue
+ # will clear the mail queue
clear_emails
visit email_trigger_path
# Will find an email sent to test@example.com
View
@@ -15,7 +15,9 @@ Gem::Specification.new do |gem|
gem.require_paths = ['lib']
gem.version = Capybara::Email::VERSION
+ gem.add_development_dependency 'mail'
gem.add_development_dependency 'actionmailer'
+ gem.add_development_dependency 'sinatra'
gem.add_development_dependency 'capybara'
gem.add_development_dependency 'rspec'
end
@@ -2,7 +2,7 @@ module Capybara::Email::RSpecHelpers
attr_accessor :current_email, :current_emails
def all_emails
- ActionMailer::Base.deliveries
+ Mail::TestMailer.deliveries
end
def emails_sent_to(recipient)
View
@@ -7,20 +7,51 @@
end
scenario 'html email' do
- deliver(html_email)
- open_email('test@example.com')
+ email = deliver(html_email)
+
+ open_email('test@example.com')
current_email.click_link 'example'
page.should have_content 'Hello world!'
current_email.should have_content 'This is only a html test'
+
+ all_emails.first.should == email
+
+ clear_emails()
+ all_emails.should be_empty
+
end
scenario 'plain text email' do
- deliver(plain_email)
+ email = deliver(plain_email)
+
open_email('test@example.com')
current_email.click_link 'http://example.com'
page.should have_content 'Hello world!'
current_email.should have_content 'This is only a plain test.'
+
+ all_emails.first.should == email
+
+ clear_emails()
+ all_emails.should be_empty
end
+
+ scenario 'via ActionMailer' do
+ email = deliver(plain_email)
+
+ all_emails.first.should == email
+
+ clear_emails
+ all_emails.should be_empty
+ end
+
+ scenario 'via Mail' do
+ email = plain_email.deliver!
+
+ all_emails.first.should == email
+
+ clear_emails
+ all_emails.should be_empty
+ end
end
class TestApp
@@ -31,6 +62,7 @@ def self.call(env)
def deliver(email)
ActionMailer::Base.deliveries << email
+ email
end
def html_email
View
@@ -1,5 +1,11 @@
require 'rspec'
+require 'mail'
require 'action_mailer'
+
require 'capybara/rspec'
require 'capybara/email/rspec'
require 'capybara/spec/driver'
+
+Mail.defaults do
+ delivery_method :test
+end