email_spec 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,10 @@
1
1
  (In Git)
2
2
 
3
+ == 0.6.1 2010-03-17
4
+
5
+ === New features
6
+ * Ability to click image links via the image alt tag. (Tim Harper)
7
+
3
8
  == 0.6.0 2010-03-05
4
9
 
5
10
  === New features
@@ -146,7 +151,7 @@ No changes. Bumping version for RubyForge release.
146
151
  === New features
147
152
  * Change Rakefile to run all specs and features, as well as prepare the db (Mischa Fierer)
148
153
  * Allow for array to be passed into deliver_to matcher. (Diego Carrion)
149
- * Added matcher for checking if a collection of emails includes an email with a particular subject (Luke Melia, Noah Davis)
154
+ * Added matcher for checking if a collision of emails includes an email with a particular subject (Luke Melia, Noah Davis)
150
155
  * Introduced hook to convert objects to email addresses (Luke Melia and Lee Bankewitz)
151
156
 
152
157
  This allows you, in your step matcher, to say something like:
data/Rakefile CHANGED
@@ -26,7 +26,7 @@ rescue LoadError
26
26
  end
27
27
 
28
28
  # TODO: switch to gem bundler
29
- ([['delayed_job', '1.8.4']] + %w[fixjour pony sinatra rack-test].map{|g| [g]}).each do |gem_args|
29
+ ([['delayed_job', '1.8.4']] + %w[mimetype-fu fixjour pony sinatra rack-test].map{|g| [g]}).each do |gem_args|
30
30
  gem_name = gem_args.first
31
31
  gem_version = gem_args.size > 1 ? gem_args[1] : nil
32
32
  begin
@@ -9,4 +9,8 @@ class WelcomeController < ApplicationController
9
9
  def newsletter
10
10
  UserMailer.send_later(:deliver_newsletter, params['Email'], params['Name'])
11
11
  end
12
+
13
+ def attachments
14
+ UserMailer.deliver_attachments(params['Email'], params['Name'])
15
+ end
12
16
  end
@@ -15,4 +15,25 @@ class UserMailer < ActionMailer::Base
15
15
  @sent_on = Time.now
16
16
  @body[:name] = name
17
17
  end
18
+
19
+ def attachments(email, name)
20
+ @recipients = email
21
+ @from = "admin@example.com"
22
+ @subject = "Attachments test"
23
+ @sent_on = Time.now
24
+ @body[:name] = name
25
+ add_attachment 'image.png'
26
+ add_attachment 'document.pdf'
27
+ end
28
+
29
+ private
30
+
31
+ def add_attachment(attachment_name)
32
+ content_type 'multipart/mixed'
33
+ attachment_path = File.join(RAILS_ROOT, 'attachments', attachment_name)
34
+ File.open(attachment_path) do |file|
35
+ filename = File.basename(file.path)
36
+ attachment :filename => filename, :content_type => File.mime_type?(file), :body => file.read
37
+ end
38
+ end
18
39
  end
@@ -0,0 +1,6 @@
1
+ Hello <%= @name %>!
2
+
3
+ Documents are attached.
4
+
5
+ Regards
6
+ Rails Example App
@@ -16,6 +16,7 @@ Rails::Initializer.run do |config|
16
16
 
17
17
  config.gem 'fixjour', :lib => 'fixjour'
18
18
  config.gem 'delayed_job', :lib => 'delayed_job'
19
+ config.gem 'mimetype-fu', :lib => 'mimetype_fu'
19
20
 
20
21
  config.time_zone = 'UTC'
21
22
 
@@ -34,6 +34,7 @@ ActionController::Routing::Routes.draw do |map|
34
34
  map.root :controller => "welcome", :action => "index"
35
35
  map.confirm_account "/confirm", :controller => "welcome", :action => "confirm"
36
36
  map.request_newsletter "/newsletter", :controller => "welcome", :action => "newsletter"
37
+ map.request_attachments "/attachments", :controller => "welcome", :action => "attachments"
37
38
  # See how all your routes lay out with "rake routes"
38
39
 
39
40
  # Install the default routes as the lowest priority.
@@ -0,0 +1,27 @@
1
+ Feature: Attachment testing support
2
+ In order for developers to test attachments in emails
3
+ I want to be able to provide working steps which inspect attachments
4
+
5
+ Scenario: Email with Attachments
6
+ Given no emails have been sent
7
+ And I go to request attachments be sent to me
8
+ Then I should receive an email
9
+ When I open the email
10
+ Then I should see 2 attachments with the email
11
+ And there should be an attachment named "image.png"
12
+ And there should be an attachment named "document.pdf"
13
+ And attachment 1 should be named "image.png"
14
+ And attachment 2 should be named "document.pdf"
15
+ And there should be an attachment of type "image/png"
16
+ And there should be an attachment of type "application/pdf"
17
+ And attachment 1 should be of type "image/png"
18
+ And attachment 2 should be of type "application/pdf"
19
+ And all attachments should not be blank
20
+
21
+ Scenario: Email without Attachments
22
+ Given no emails have been sent
23
+ And I am on the homepage
24
+ And I submit my registration information
25
+ Then I should receive an email
26
+ When I open the email
27
+ Then I should see no attachments with the email
@@ -20,6 +20,9 @@ module NavigationHelpers
20
20
  when /request a newsletter/
21
21
  request_newsletter_url('Name' => 'Joe Someone', 'Email' => 'example@example.com')
22
22
 
23
+ when /request attachments be sent to me/
24
+ request_attachments_url('Name' => 'Joe Someone', 'Email' => 'example@example.com')
25
+
23
26
  else
24
27
  raise "Can't find mapping from \"#{page_name}\" to a path.\n" +
25
28
  "Now, go and add a mapping in #{__FILE__}"
@@ -44,6 +44,10 @@ module EmailSpec
44
44
  email
45
45
  end
46
46
 
47
+ def current_email_attachments(address=nil)
48
+ current_email(address).attachments || Array.new
49
+ end
50
+
47
51
  def unread_emails_for(address)
48
52
  mailbox_for(address) - read_emails_for(address)
49
53
  end
@@ -110,9 +114,16 @@ module EmailSpec
110
114
 
111
115
  # e.g. Click here in <a href="http://confirm">Click here</a>
112
116
  def parse_email_for_anchor_text_link(email, link_text)
113
- email.body =~ %r{<a[^>]*href=['"]?([^'"]*)['"]?[^>]*?>[^<]*?#{link_text}[^<]*?</a>}
114
- URI.split($~[1])[5..-1].compact!.join("?").gsub("&amp;", "&")
115
- # sub correct ampersand after rails switches it (http://dev.rubyonrails.org/ticket/4002)
117
+ if textify_images(email.body) =~ %r{<a[^>]*href=['"]?([^'"]*)['"]?[^>]*?>[^<]*?#{link_text}[^<]*?</a>}
118
+ URI.split($1)[5..-1].compact!.join("?").gsub("&amp;", "&")
119
+ # sub correct ampersand after rails switches it (http://dev.rubyonrails.org/ticket/4002)
120
+ else
121
+ return nil
122
+ end
123
+ end
124
+
125
+ def textify_images(email_body)
126
+ email_body.gsub(%r{<img[^>]*alt=['"]?([^'"]*)['"]?[^>]*?/>}) { $1 }
116
127
  end
117
128
 
118
129
  def parse_email_count(amount)
@@ -117,28 +117,28 @@ end
117
117
  # Inspect the Email Attachments
118
118
  #
119
119
 
120
- Then /^(?:I|they) should see (\d+) attachments? with the email$/ do |amount|
121
- current_email.attachments.size.should == amount.to_i
120
+ Then /^(?:I|they) should see (an|no|\d+) attachments? with the email$/ do |amount|
121
+ current_email_attachments.size.should == parse_email_count(amount)
122
122
  end
123
123
 
124
124
  Then /^there should be (an|no|\d+) attachments? named "([^"]*?)"$/ do |amount, filename|
125
- current_email.attachments.select { |a| a.original_filename == filename }.size.should == parse_email_count(amount)
125
+ current_email_attachments.select { |a| a.original_filename == filename }.size.should == parse_email_count(amount)
126
126
  end
127
127
 
128
128
  Then /^attachment (\d+) should be named "([^"]*?)"$/ do |index, filename|
129
- current_email.attachments[(index.to_i - 1)].original_filename.should == filename
129
+ current_email_attachments[(index.to_i - 1)].original_filename.should == filename
130
130
  end
131
131
 
132
132
  Then /^there should be (an|no|\d+) attachments? of type "([^"]*?)"$/ do |amount, content_type|
133
- current_email.attachments.select { |a| a.content_type == content_type }.size.should == parse_email_count(amount)
133
+ current_email_attachments.select { |a| a.content_type == content_type }.size.should == parse_email_count(amount)
134
134
  end
135
135
 
136
136
  Then /^attachment (\d+) should be of type "([^"]*?)"$/ do |index, content_type|
137
- current_email.attachments[(index.to_i - 1)].content_type.should == content_type
137
+ current_email_attachments[(index.to_i - 1)].content_type.should == content_type
138
138
  end
139
139
 
140
140
  Then /^all attachments should not be blank$/ do
141
- current_email.attachments.each do |attachment|
141
+ current_email_attachments.each do |attachment|
142
142
  attachment.size.should_not == 0
143
143
  end
144
144
  end
@@ -0,0 +1,23 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe EmailSpec::Helpers do
4
+ include EmailSpec::Helpers
5
+ describe "#parse_email_for_link" do
6
+ it "properly finds links with text" do
7
+ email = stub(:has_body_text? => true,
8
+ :body => %(<a href="/path/to/page">Click Here</a>))
9
+ parse_email_for_link(email, "Click Here").should == "/path/to/page"
10
+ end
11
+
12
+ it "recognizes img alt properties as text" do
13
+ email = stub(:has_body_text? => true,
14
+ :body => %(<a href="/path/to/page"><img src="http://host.com/images/image.gif" alt="an image" /></a>))
15
+ parse_email_for_link(email, "an image").should == "/path/to/page"
16
+ end
17
+
18
+ it "causes a spec to fail if the body doesn't contain the text specified to click" do
19
+ email = stub(:has_body_text? => false)
20
+ lambda { parse_email_for_link(email, "non-existent text") }.should raise_error(Spec::Expectations::ExpectationNotMetError)
21
+ end
22
+ end
23
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: email_spec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Mabey
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2010-03-05 00:00:00 -07:00
14
+ date: 2010-03-17 00:00:00 -06:00
15
15
  default_executable:
16
16
  dependencies: []
17
17
 
@@ -70,6 +70,7 @@ signing_key:
70
70
  specification_version: 3
71
71
  summary: Easily test email in rspec and cucumber
72
72
  test_files:
73
+ - spec/email_spec/helpers_spec.rb
73
74
  - spec/email_spec/matchers_spec.rb
74
75
  - spec/spec.opts
75
76
  - spec/spec_helper.rb
@@ -79,12 +80,16 @@ test_files:
79
80
  - examples/rails_root/app/helpers/welcome_helper.rb
80
81
  - examples/rails_root/app/models/user.rb
81
82
  - examples/rails_root/app/models/user_mailer.rb
83
+ - examples/rails_root/app/views/user_mailer/attachments.erb
82
84
  - examples/rails_root/app/views/user_mailer/newsletter.erb
83
85
  - examples/rails_root/app/views/user_mailer/signup.erb
86
+ - examples/rails_root/app/views/welcome/attachments.html.erb
84
87
  - examples/rails_root/app/views/welcome/confirm.html.erb
85
88
  - examples/rails_root/app/views/welcome/index.html.erb
86
89
  - examples/rails_root/app/views/welcome/newsletter.html.erb
87
90
  - examples/rails_root/app/views/welcome/signup.html.erb
91
+ - examples/rails_root/attachments/document.pdf
92
+ - examples/rails_root/attachments/image.png
88
93
  - examples/rails_root/config/boot.rb
89
94
  - examples/rails_root/config/cucumber.yml
90
95
  - examples/rails_root/config/database.yml
@@ -101,6 +106,7 @@ test_files:
101
106
  - examples/rails_root/db/migrate/20090908054656_create_delayed_jobs.rb
102
107
  - examples/rails_root/db/schema.rb
103
108
  - examples/rails_root/doc/README_FOR_APP
109
+ - examples/rails_root/features/attachments.feature
104
110
  - examples/rails_root/features/delayed_job.feature
105
111
  - examples/rails_root/features/errors.feature
106
112
  - examples/rails_root/features/example.feature
@@ -123,7 +129,6 @@ test_files:
123
129
  - examples/rails_root/public/javascripts/prototype.js
124
130
  - examples/rails_root/public/robots.txt
125
131
  - examples/rails_root/Rakefile
126
- - examples/rails_root/rerun.txt
127
132
  - examples/rails_root/script/about
128
133
  - examples/rails_root/script/autospec
129
134
  - examples/rails_root/script/console
@@ -1 +0,0 @@
1
- features/errors.feature:13:17:21:26:30