Skip to content
Collection of helpers and Cucumber steps for testing email through Pony
Pull request Compare This branch is 4 commits ahead, 7 commits behind johnmendonca:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.



A collection of helper methods and Cucumber steps to make testing email with Pony a piece of cake. It works simply by overwriting the Pony mail method with one that stores the email in an array instead of sending it. You can access this email with the helper methods and perform whatever checks you want.


gem install pony-test


In your test environment:

require 'pony-test'


To use pony-test in Cucumber include the helpers in features/support/env.rb:

World do
  include Pony::TestHelpers

You probably want all emails to be cleared for each scenario:

Before do

To use the Cucumber steps, you will need to copy lib/email_steps.rb from the gem or github to features/step_definitions.


You will need to include Pony::TestHelpers in your example groups. If you want to have access to the helpers in all of your examples you can do the following in your spec_helper.rb:

Spec::Runner.configure do |config|

Otherwise, you will need to include them in the example groups you wish to use them:

describe "Signup Email" do
  include Pony::TestHelpers

Remember to call reset_mailer in a before block or whenever you want the emails to be reset.


Helper methods

deliveries, all_email returns the whole array of emails

current_email returns either the last email sent, or the last email “opened”

current_email_address returns the last address used in a lookup operation

reset_mailer clears everything

last_email_sent “opens” the last email sent

inbox, inbox_for returns all emails, filterable by address, pass the option :address => ''

open_email, open_email_for “opens” the first email matching all criteria, accepts options :address, :with_subject, and :with_body

find_email, find_email_for returns all email matching all criteria, accepts options :address, :with_subject, and :with_body

email_links returns all links in an email body, searching current_email by default

email_links_matching returns all links matching a pattern


Scenario: A new person signs up
    Given I am at "/"
    When I fill in "Email" with ""
    And I press "Sign up"
    Then I should have an email
    And I should see "confirm" in the email body

    When I visit "confirm" in the email
    Then I should see "Confirm your new account"

Please read lib/email_steps.rb for the rest. For more examples, check out the examples folder for a small example app that implements the steps.


This project is a major simplification and rewrite of the Email-Spec project:

If you are a Rails/ActionMailer user, you may want to check it out.

Something went wrong with that request. Please try again.