Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/technicalpickles/mailinator-spec
a library for using mailinator for testing email from rspec and cucumber
https://github.com/technicalpickles/mailinator-spec
Last synced: 2 months ago
JSON representation
a library for using mailinator for testing email from rspec and cucumber
- Host: GitHub
- URL: https://github.com/technicalpickles/mailinator-spec
- Owner: technicalpickles
- Created: 2010-06-09T03:12:43.000Z (over 14 years ago)
- Default Branch: master
- Last Pushed: 2010-06-28T23:09:52.000Z (over 14 years ago)
- Last Synced: 2024-10-14T21:49:37.596Z (3 months ago)
- Language: Ruby
- Homepage:
- Size: 99.6 KB
- Stars: 14
- Watchers: 4
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.rdoc
Awesome Lists containing this project
README
= mailinator-spec
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 mailinator.com, 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/== Setup
Start off with the usual gem install:
gem install mailinator-spec
mailinator-spec comes with two main modules:
* Mailinator::Spec::Matchers
* Mailinator::Spec::HelpersFor 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
endIt's also usable from cucumber:
require 'mailinator/spec'
require 'mailinator/steps'
World(Mailinator::Spec::Matchers)
World(Mailinator::Spec::Helpers)== Usage
At the core of mailinator-spec is the Mailinator class. This represents a mailbox over at http://mailinator.com. 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 = Mailinator.new('zombo-consumer')
mailinator.email # => "[email protected]"
mailinator.inbox_url # => "http://mailinator.com/[email protected]"
mailinator.rss_url # => "http://mailinator.com/[email protected]"
mailinator.atom_url # => "http://mailinator.com/[email protected]"
mailinator.mailbox # => [# bodyport=#>]
mailinator.mailbox.first.from # => "[email protected]"
mailinator.mailbox.first.subject # => "Welcome to zombo.com!"
mailinator.mailbox.first.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.email # => "[email protected]"
mailinator = Mailinator.new('zombo-consumer')
mailinator.email # => "[email protected]"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.com'
mailinator = Mailinator.new('zombo-consumer')
mailinator.email # => "[email protected]"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 "zombo.com welcome" do
before do
@to = mailinator.email # for a random address
# @to = mailinator('me') # for a specific address# send some email
@email = last_mailinator_email # shorthand for mailinator.mailbox.last
endit "is from [email protected]" do
@email.should be_delivered_from('[email protected]')
endit "has welcoming subject" do
@email.should have_subject('Welcome to zombo.com')
endit "tells us our about our limitation" do
@email.should have_body_text("The only limitation... is you!")
end
endIn 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/