mailinator-spec 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,39 @@
1
+ # rcov generated
2
+ coverage
3
+
4
+ # rdoc generated
5
+ rdoc
6
+
7
+ # yard generated
8
+ doc
9
+ .yardoc
10
+
11
+ # jeweler generated
12
+ pkg
13
+
14
+ # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
15
+ #
16
+ # * Create a file at ~/.gitignore
17
+ # * Include files you want ignored
18
+ # * Run: git config --global core.excludesfile ~/.gitignore
19
+ #
20
+ # After doing this, these files will be ignored in all your git projects,
21
+ # saving you from having to 'pollute' every project you touch with them
22
+ #
23
+ # Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
24
+ #
25
+ # For MacOS:
26
+ #
27
+ #.DS_Store
28
+ #
29
+ # For TextMate
30
+ #*.tmproj
31
+ #tmtags
32
+ #
33
+ # For emacs:
34
+ #*~
35
+ #\#*
36
+ #.\#*
37
+ #
38
+ # For vim:
39
+ #*.swp
@@ -0,0 +1,102 @@
1
+ = mailinator-spec
2
+
3
+ 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.
4
+
5
+ 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.
6
+
7
+
8
+ Scenario: Cucumber integration
9
+ Given I have mailinator email address
10
+ And I've manually sent an email to it
11
+ When I wait 2 seconds for mail to process
12
+ Then the email subject should match /omgwtfbbq/
13
+ And the email body should match /http:\/\/zombo\.com/
14
+
15
+
16
+ == Setup
17
+
18
+ Start off with the usual gem install:
19
+
20
+ gem install mailinator-spec
21
+
22
+ mailinator-spec comes with two main modules:
23
+
24
+ * Mailinator::Spec::Matchers
25
+ * Mailinator::Spec::Helpers
26
+
27
+ For RSpec, you can add these to spec/spec_helper.rb:
28
+
29
+ require 'mailinator'
30
+ Spec::Runner.configure do |config|
31
+ config.include Mailinator::Spec::Matchers
32
+ config.include Mailinator::Spec::Helpers
33
+ end
34
+
35
+ It's also usable from cucumber:
36
+
37
+ require 'mailinator/spec'
38
+ require 'mailinator/steps'
39
+ World(Mailinator::Spec::Matchers)
40
+ World(Mailinator::Spec::Helpers)
41
+
42
+ == Usage
43
+
44
+ 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.
45
+
46
+ mailinator = Mailinator.new('zombo-consumer')
47
+ mailinator.email # => "zombo-consumer@mailinator.com"
48
+ mailinator.inbox_url # => "http://mailinator.com/maildir.jsp?email=zombo-consumer@mailinator.com"
49
+ mailinator.rss_url # => "http://mailinator.com/rss.jsp?email=zombo-consumer@mailinator.com"
50
+ mailinator.atom_url # => "http://mailinator.com/atom.jsp?email=zombo-consumer@mailinator.com"
51
+ mailinator.mailbox # => [#<TMail::Mail port=#<TMail::StringPort:id=0x8110d1d8> bodyport=#<TMail::StringPort:id=0x8110c0f8>>]
52
+ mailinator.mailbox.first.from # => "noreply@zombo.com"
53
+ mailinator.mailbox.first.subject # => "Welcome to zombo.com!"
54
+ mailinator.mailbox.first.to # => "The only limitation... is you!"
55
+ mailinator.mailbox.first.body # => "The only limitation... is you!"
56
+
57
+ 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:
58
+
59
+ mailinator = Mailinator.mostly_random
60
+ mailinator.email # => "7d6f4373dbfde6a698f1000eb@mailinator.com"
61
+ mailinator = Mailinator.new('zombo-consumer')
62
+ mailinator.email # => "zombo-consumer@mailinator.com"
63
+
64
+ 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.
65
+
66
+ Mailinator.domain = 'mailinator.zombo.com'
67
+ mailinator = Mailinator.new('zombo-consumer')
68
+ mailinator.email # => "zombo-consumer@mailinator.zombo.com"
69
+
70
+ For this to properly work, you'd need to FIXME to provide that information
71
+
72
+
73
+ For RSpec and Cucumber, this is exposed slightly more convenient way, and there are matchers (courtesy of email-spec)
74
+
75
+ describe "zombo.com welcome" do
76
+ before do
77
+ @to = mailinator.email # for a random address
78
+ # @to = mailinator('me') # for a specific address
79
+
80
+ # send some email
81
+
82
+ @email = last_mailinator_email # shorthand for mailinator.mailbox.last
83
+ end
84
+
85
+ it "is from noreply@zombo.com" do
86
+ @email.should be_delivered_from('noreply@zombo.com')
87
+ end
88
+
89
+ it "has welcoming subject" do
90
+ @email.should have_subject('Welcome to zombo.com')
91
+ end
92
+
93
+ it "tells us our about our limitation" do
94
+ @email.should have_body_text("The only limitation... is you!")
95
+ end
96
+ end
97
+
98
+ In cucumber, you can use the same exact techniques. In addition, there are handful of step definitions provided:
99
+
100
+ When I wait 2 seconds for mail to process
101
+ Then the email subject should match /omgwtfbbq/
102
+ And the email body should match /http:\/\/zombo\.com/
@@ -0,0 +1,62 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "mailinator-spec"
8
+ gem.summary = %Q{mailinate the contryside... from rspec and cucumber}
9
+ gem.description = %Q{mailinator-spec is a library for using mailinator for testing email from rspec and cucumber}
10
+ gem.email = "josh@technicalpickles.com"
11
+ gem.homepage = "http://github.com/technicalpickles/mailinator-spec"
12
+ gem.authors = ["Joshua Nichols"]
13
+ gem.add_dependency 'email_spec'
14
+ gem.add_dependency 'mail'
15
+ gem.add_development_dependency "rspec", "~> 1.3.0"
16
+ gem.version = "0.0.1"
17
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
18
+ end
19
+ Jeweler::GemcutterTasks.new
20
+ rescue LoadError
21
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
22
+ end
23
+
24
+ require 'spec/rake/spectask'
25
+ Spec::Rake::SpecTask.new(:spec) do |spec|
26
+ spec.libs << 'lib' << 'spec'
27
+ spec.spec_files = FileList['spec/**/*_spec.rb']
28
+ end
29
+
30
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
31
+ spec.libs << 'lib' << 'spec'
32
+ spec.pattern = 'spec/**/*_spec.rb'
33
+ spec.rcov = true
34
+ end
35
+
36
+ task :spec => :check_dependencies
37
+
38
+
39
+ task :spec => :check_dependencies
40
+
41
+ begin
42
+ require 'cucumber/rake/task'
43
+ Cucumber::Rake::Task.new(:features)
44
+
45
+ task :features => :check_dependencies
46
+ rescue LoadError
47
+ task :features do
48
+ abort "Cucumber is not available. In order to run features, you must: sudo gem install cucumber"
49
+ end
50
+ end
51
+
52
+ task :default => :spec
53
+
54
+ require 'rake/rdoctask'
55
+ Rake::RDocTask.new do |rdoc|
56
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
57
+
58
+ rdoc.rdoc_dir = 'rdoc'
59
+ rdoc.title = "cucumber-mailinator #{version}"
60
+ rdoc.rdoc_files.include('README*')
61
+ rdoc.rdoc_files.include('lib/**/*.rb')
62
+ end
@@ -0,0 +1,8 @@
1
+ Feature: Mailinator
2
+
3
+ Scenario: Cucumber integration
4
+ Given I have mailinator email address
5
+ And I've manually sent an email to it
6
+ When I wait 2 seconds for mail to process
7
+ Then the email subject should match /omgwtfbbq/
8
+ And the email body should match /http:\/\/zombo\.com/
@@ -0,0 +1,8 @@
1
+ Given /^I have mailinator email address$/ do
2
+ @mailinator_email = mailinator('zomgwtfbbbbbbbq').email
3
+ end
4
+
5
+ Given /^I've manually sent an email to it$/ do
6
+ # no-op
7
+ end
8
+
@@ -0,0 +1,10 @@
1
+ $LOAD_PATH.unshift File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
2
+
3
+ require 'spec/matchers'
4
+ require 'mailinator'
5
+ require 'mailinator/spec'
6
+ require 'mailinator/steps'
7
+ require 'email-spec'
8
+
9
+ World(Mailinator::Spec::Helpers)
10
+ World(Mailinator::Spec::Matchers)
@@ -0,0 +1,77 @@
1
+ require 'digest/sha1'
2
+ require 'open-uri'
3
+ require 'nokogiri'
4
+ require 'cgi'
5
+ require 'mail'
6
+
7
+ class Mailinator
8
+ BASE_URL = 'http://mailinator.com'
9
+
10
+ attr_accessor :email, :name
11
+
12
+ def initialize(name = nil, opts = {})
13
+ @name = name
14
+ @email = format_email(name)
15
+ end
16
+
17
+ def inbox_url
18
+ action_url('maildir')
19
+ end
20
+
21
+ def rss_url
22
+ action_url('rss')
23
+ end
24
+
25
+ def atom_url
26
+ action_url('atom')
27
+ end
28
+
29
+ def widget_url(width = '250', height = '250')
30
+ URI.parse("#{BASE_URL}/widget/mailin8r.jsp?w=#{width}&h=#{height}&b=#{@name}").to_s
31
+ end
32
+
33
+ def mailbox
34
+ doc = Nokogiri::HTML(open(atom_url))
35
+
36
+ doc.css('feed entry').map do |entry|
37
+ mail = Mail.new
38
+
39
+ mail.subject = entry.at_css('title').text
40
+ mail.body = entry.at_css('summary').text
41
+
42
+ mail.to = @email
43
+ mail.from = entry.at_css('author name').text
44
+
45
+ mail
46
+ end
47
+ end
48
+
49
+ def self.mostly_random
50
+ now = Time.now
51
+ sha = Digest::SHA1.hexdigest("#{now.to_i}#{now.usec}").to_s
52
+
53
+ new(sha.slice(0, 25))
54
+ end
55
+
56
+ def self.domain=(domain)
57
+ @domain = domain
58
+ end
59
+
60
+ def self.reset_domain!
61
+ @domain = nil
62
+ end
63
+
64
+ def self.domain
65
+ @domain ||= "mailinator.com"
66
+ end
67
+
68
+ private
69
+
70
+ def action_url(action)
71
+ URI.parse("#{BASE_URL}/#{action}.jsp?email=#{@name}").to_s
72
+ end
73
+
74
+ def format_email(email)
75
+ email =~ /^[a-zA-Z0-9]+@#{self.class.domain}$/ ? email : "#{email}@#{self.class.domain}"
76
+ end
77
+ end
@@ -0,0 +1,29 @@
1
+ require 'mailinator'
2
+ require 'email-spec'
3
+
4
+ class Mailinator
5
+ module Spec
6
+ module Matchers
7
+ include EmailSpec::Matchers
8
+ end
9
+
10
+ module Helpers
11
+
12
+ def mailinator(email = nil)
13
+ @mailinator ||= begin
14
+ if email
15
+ Mailinator.new(email)
16
+ else
17
+ Mailinator.mostly_random
18
+ end
19
+ end
20
+ end
21
+
22
+ def last_mailinator_email
23
+ mailinator.mailbox.last
24
+ end
25
+
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,15 @@
1
+ When /I wait (\d+) seconds for mail to process/ do |count|
2
+ sleep(count.to_i)
3
+ end
4
+
5
+ Then "I should have one email in my inbox" do
6
+ pending
7
+ end
8
+
9
+ Then /^the email subject should match \/(.*)\/$/ do |subject_regexp|
10
+ last_mailinator_email.should have_subject(Regexp.new(subject_regexp))
11
+ end
12
+
13
+ Then /^the email body should match \/(.*)\/$/ do |body_regexp|
14
+ last_mailinator_email.should have_body_text(Regexp.new(body_regexp))
15
+ end
@@ -0,0 +1,56 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe Mailinator do
4
+ context "with default domain" do
5
+ before(:each) do
6
+ @random_name = "awesomemail#{rand(420)}"
7
+ @primary_email = "#{@random_name}@mailinator.com"
8
+ @mail = Mailinator.new(@random_name)
9
+ end
10
+
11
+ it 'should have a primary email address' do
12
+ @mail.email.should == @primary_email
13
+ end
14
+
15
+ it 'should have an inbox URL' do
16
+ @mail.inbox_url.should == "http://mailinator.com/maildir.jsp?email=#{@random_name}"
17
+ end
18
+
19
+ it 'should have an RSS URL' do
20
+ @mail.rss_url.should == "http://mailinator.com/rss.jsp?email=#{@random_name}"
21
+ end
22
+
23
+ it 'should have an RSS URL' do
24
+ @mail.atom_url.should == "http://mailinator.com/atom.jsp?email=#{@random_name}"
25
+ end
26
+
27
+ it 'should have a widget URL' do
28
+ width = '500'
29
+ height = '250'
30
+ widget_url = "http://mailinator.com/widget/mailin8r.jsp?w=#{width}&h=#{height}&b=#{@random_name}"
31
+ @mail.widget_url(width, height).should == widget_url
32
+ end
33
+
34
+ it 'should have an alternate email address'
35
+ it 'should have an RSS feed'
36
+ it 'should fetch a random primary email address'
37
+ end
38
+
39
+ context "configured custom domain" do
40
+ before(:each) do
41
+ Mailinator.domain = "zombo.com"
42
+
43
+ @random_name = "awesomemail#{rand(420)}"
44
+ @primary_email = "#{@random_name}@zombo.com"
45
+ @mail = Mailinator.new(@random_name)
46
+ end
47
+
48
+ after(:each) do
49
+ Mailinator.reset_domain!
50
+ end
51
+
52
+ it "should figure use the correct domain" do
53
+ @mail.email.should == @primary_email
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,6 @@
1
+ $LOAD_PATH.unshift File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ require 'spec'
3
+ require 'mailinator'
4
+
5
+ Spec::Runner.configure do
6
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mailinator-spec
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Joshua Nichols
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-06-28 00:00:00 -04:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: email_spec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :runtime
31
+ version_requirements: *id001
32
+ - !ruby/object:Gem::Dependency
33
+ name: mail
34
+ prerelease: false
35
+ requirement: &id002 !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ segments:
40
+ - 0
41
+ version: "0"
42
+ type: :runtime
43
+ version_requirements: *id002
44
+ - !ruby/object:Gem::Dependency
45
+ name: rspec
46
+ prerelease: false
47
+ requirement: &id003 !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ~>
50
+ - !ruby/object:Gem::Version
51
+ segments:
52
+ - 1
53
+ - 3
54
+ - 0
55
+ version: 1.3.0
56
+ type: :development
57
+ version_requirements: *id003
58
+ description: mailinator-spec is a library for using mailinator for testing email from rspec and cucumber
59
+ email: josh@technicalpickles.com
60
+ executables: []
61
+
62
+ extensions: []
63
+
64
+ extra_rdoc_files:
65
+ - README.rdoc
66
+ files:
67
+ - .gitignore
68
+ - README.rdoc
69
+ - Rakefile
70
+ - features/mailinator.feature
71
+ - features/step_definitions/mailinator_steps.rb
72
+ - features/support/env.rb
73
+ - lib/mailinator.rb
74
+ - lib/mailinator/spec.rb
75
+ - lib/mailinator/steps.rb
76
+ - spec/mailinator_spec.rb
77
+ - spec/spec_helper.rb
78
+ has_rdoc: true
79
+ homepage: http://github.com/technicalpickles/mailinator-spec
80
+ licenses: []
81
+
82
+ post_install_message:
83
+ rdoc_options:
84
+ - --charset=UTF-8
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ segments:
92
+ - 0
93
+ version: "0"
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ segments:
99
+ - 0
100
+ version: "0"
101
+ requirements: []
102
+
103
+ rubyforge_project:
104
+ rubygems_version: 1.3.6
105
+ signing_key:
106
+ specification_version: 3
107
+ summary: mailinate the contryside... from rspec and cucumber
108
+ test_files:
109
+ - spec/mailinator_spec.rb
110
+ - spec/spec_helper.rb