Project

pony-test

0.01
No commit activity in last 3 years
No release in over 3 years
Collection of helper methods and Cucumber steps for testing email through Pony
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 0.6.0
>= 0
>= 0
 Project Readme

Pony-Test¶ ↑

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.

Installation¶ ↑

gem install pony-test

Setup¶ ↑

In your test environment:

require 'pony-test'

Cucumber¶ ↑

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

World do
  ...
  include Pony::TestHelpers
end

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

Before do
  reset_mailer
end

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

RSpec¶ ↑

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|
  config.include(Pony::TestHelpers)
end

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

describe "Signup Email" do
  include Pony::TestHelpers
  ...
end

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

Usage¶ ↑

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 => 'foo@example.com'

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

Cucumber¶ ↑

Scenario: A new person signs up
    Given I am at "/"
    When I fill in "Email" with "quentin@example.com"
    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.

Acknowledgements¶ ↑

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

github.com/bmabey/email-spec

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