Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Decouple action mailer #3

Merged
merged 2 commits into from

2 participants

@DCarper

Happened to be using the Mail gem but not ActionMailer. Pretty small change as ActionMailer just delegates to Mail anyway.

Specs for both strategies are included.

Dan

@bcardarella
Owner

I'm all for this.

A few things:

1.) can you rebase against master so I can cleanly merge as there are come conflicts
2.) Can you make the vim swap file ignore a separate pull request as it is not involved with this issue
3.) I'm not clear were Sinatra is necessary. I don't see it being used in the tests

dcarper added some commits
dcarper Added Sinatra to gemspec
`bundle install` was not getting Sinatra installed, which is necessary for specs to run.
a9badd7
dcarper decoupled ActionMailer
Now also works for people just using the Mail gem without ActionMailer.
7dddc87
@DCarper

Okay moved the vim swp stuff to another branch, will file another pull request.

Seems like Capybara's TestApp is an instance of Sinatra. I can remove that commit as well if you want as it's a change that should really be made to the capybara gem.

carperMBP:capybara-email dancarper$ rspec
/Users/dancarper/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': no such file to load -- sinatra/base (LoadError)
    from /Users/dancarper/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /Users/dancarper/.rvm/gems/ruby-1.9.2-p290@haa/gems/capybara-1.1.2/lib/capybara/spec/test_app.rb:1:in `<top (required)>'
@bcardarella
Owner

Oh that's funny, I actually wrote a small rack app called TestApp and it seems that the test suite is loading the one from Capybara instead.

I'll fix this. Thank-you for the pull request.

@bcardarella bcardarella merged commit 0b3912d into dockyard:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 4, 2012
  1. Added Sinatra to gemspec

    dcarper authored
    `bundle install` was not getting Sinatra installed, which is necessary for specs to run.
  2. decoupled ActionMailer

    dcarper authored
    Now also works for people just using the Mail gem without ActionMailer.
This page is out of date. Refresh to see the latest.
View
4 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 ##
@@ -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
2  capybara-email.gemspec
@@ -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
View
2  lib/capybara/email/rspec/helpers.rb
@@ -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
38 spec/email/driver_spec.rb
@@ -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
6 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
Something went wrong with that request. Please try again.