Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decouple action mailer #3

Merged
merged 2 commits into from Mar 4, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
@@ -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 ##

Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions capybara-email.gemspec
Expand Up @@ -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 changes: 1 addition & 1 deletion lib/capybara/email/rspec/helpers.rb
Expand Up @@ -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)
Expand Down
38 changes: 35 additions & 3 deletions spec/email/driver_spec.rb
Expand Up @@ -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
Expand All @@ -31,6 +62,7 @@ def self.call(env)

def deliver(email)
ActionMailer::Base.deliveries << email
email
end

def html_email
Expand Down
6 changes: 6 additions & 0 deletions spec/spec_helper.rb
@@ -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