Add this line to your application's Gemfile:
And then execute:
Or install it yourself as:
$ gem install capybara-email
capybara/email/rspec in your
feature 'Emailer' do background do # will clear the message queue clear_emails visit email_trigger_path # Will find an email sent to [email protected] # and set `current_email` open_email('[email protected]') end scenario 'following a link' do current_email. 'your profile' page.should have_content 'Profile page' end scenario 'testing for content' do current_email.should have_content 'Hello Joe!' end scenario 'view the email body in your browser' do # the `launchy` gem is required current_email.save_and_open end end
capybara/email in your
Once you have required
capybara-email, gaining access to usable methods
is easy as adding this module to your Cucumber
I recommend adding this to a support file such as
require 'capybara/email' World(::::)
Scenario: Email is sent to winning user Given "[email protected]" is playing a game When that user picks a winning piece Then "[email protected]" receives an email with "You've Won!" as the subject Then /^"([^"]*)" receives an email with "([^"]*)" as the subject$/ do |email_address, subject| open_email(email_address) current_email.subject.should eq subject end
capybara/email at the top of
Capybara::Email::DSL in your test class
class ActionDispatch::IntegrationTest include :::: end
class EmailTriggerControllerTest < ActionController::IntegrationTest def setup # will clear the message queue clear_emails visit email_trigger_path # Will find an email sent to `[email protected]` # and set `current_email` open_email('[email protected]') end test 'following a link' do current_email. 'your profile' page.should have_content 'Profile page' end test 'testing for content' do current_email.should have_content 'Hello Joe!' end test 'view the email body in your browser' do # the `launchy` gem is required current_email.save_and_open end end
Sending emails asynchronously will cause
#open_email to not open the
correct email or not find any email at all depending on the state of the
email queue. We recommend forcing a sleep prior to trying to read any
email after an asynchronous event:
'Send email' sleep 0.1 open_email '[email protected]'
This gem follows Semantic Versioning
Want to help?
Stable branches are created based upon each minor version. Please make pull requests to specific branches rather than master.
Please make sure you include tests!
Unless Rails drops support for Ruby 1.8.7 we will continue to use the hash-rocket syntax. Please respect this.
Don't use tabs to indent, two spaces are the standard.
DockYard, LLC © 2012