Cucumber

Once you have required capybara-email, gaining access to usable methods
is easy as adding this module to your Cucumber World:

World(Capybara::Email::DSL)

I recommend adding this to a support file such as features/support/capybara_email.rb

require'capybara/email'World(Capybara::Email::DSL)

Example:

Scenario:Email is sent to winning user
Given"me@example.com" is playing a game
When that user picks a winning piece
Then"me@example.com" 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)
expect(current_email.subject).to eq subject
end

CurrentEmail API

The current_email method will delegate all necessary method calls to
Mail::Message. So if you need to access the subject of an email:

current_email.subject

Check out API for the mail gem for details on what methods are
available.

Setting your test host

When testing, it's common to want to open an email and click through to your
application. To do this, you'll probably need to update your test
environment, as well as Capybara's configuration.

By default, Capybara's app_host is set to
http://example.com. You should update this so that it points to the
same host as your test environment. In our example, we'll update both to
http://localhost:3001:

Sending Emails with JavaScript

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: