Skip to content


Subversion checkout URL

You can clone with
Download ZIP
a library for using mailinator for testing email from rspec and cucumber
Branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.



Mailinator is a great little service that provides you with temporary email addresses, and provides a way to access. You can send email to any address at, and you're able to access that from the a browser or through rss and atom.

Now, imagine you are doing integration tests of funcaionality that send email. Ideally, you'd want to actually send the email, and verify that the message went through. Feasibly, you could send the email to mailinator and then use their atom feed to check that the email went through. This is essentially what mailinator-spec comes in.

Scenario: Cucumber integration
  Given I have mailinator email address
  And I've manually sent an email to it
  When I wait 2 seconds for mail to process
  Then the email subject should match /omgwtfbbq/
  And the email body should match /http:\/\/zombo\.com/


Start off with the usual gem install:

gem install mailinator-spec

mailinator-spec comes with two main modules:

* Mailinator::Spec::Matchers
* Mailinator::Spec::Helpers

For RSpec, you can add these to spec/spec_helper.rb:

require 'mailinator'
Spec::Runner.configure do |config|
  config.include Mailinator::Spec::Matchers
  config.include Mailinator::Spec::Helpers

It's also usable from cucumber:

require 'mailinator/spec'
require 'mailinator/steps'


At the core of mailinator-spec is the Mailinator class. This represents a mailbox over at It provides you an easy way to get URLs for accessing the mailbox, as well as providing TMail objects of the emails in the mailbox.

mailinator ='zombo-consumer') # => ""
mailinator.inbox_url # => ""
mailinator.rss_url # => ""
mailinator.atom_url # => ""
mailinator.mailbox # => [#<TMail::Mail port=#<TMail::StringPort:id=0x8110d1d8> bodyport=#<TMail::StringPort:id=0x8110c0f8>>]
mailinator.mailbox.first.from # => ""
mailinator.mailbox.first.subject # => "Welcome to!" # => "The only limitation... is you!"
mailinator.mailbox.first.body # => "The only limitation... is you!"

You might not actually care what the address is that you receive email to. For this case, there's a convenience method for creating a (mostly) random one:

mailinator = Mailinator.mostly_random # => ""
mailinator ='zombo-consumer') # => ""

You can also change which domain is used for the email address. This is useful if your application specifically prevents users from using mailinator addresses.

Mailinator.domain = ''
mailinator ='zombo-consumer') # => ""

For this to properly work, you'd need to FIXME to provide that information

For RSpec and Cucumber, this is exposed slightly more convenient way, and there are matchers (courtesy of email-spec)

describe " welcome" do
  before do
    @to = # for a random address
    # @to = mailinator('me') # for a specific address

    # send some email

    @email = last_mailinator_email # shorthand for mailinator.mailbox.last

  it "is from" do
    @email.should be_delivered_from('')

  it "has welcoming subject" do
    @email.should have_subject('Welcome to')

  it "tells us our about our limitation" do
    @email.should have_body_text("The only limitation... is you!")

In cucumber, you can use the same exact techniques. In addition, there are handful of step definitions provided:

When I wait 2 seconds for mail to process
Then the email subject should match /omgwtfbbq/
And the email body should match /http:\/\/zombo\.com/
Something went wrong with that request. Please try again.