email_spec 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/History.txt CHANGED
@@ -3,6 +3,14 @@
3
3
  === New features
4
4
  === Bufixes
5
5
 
6
+ == 0.2.1 2009-5-29
7
+
8
+ === New Features
9
+ * BCC RSpec matcher. (Josh Nichols)
10
+
11
+ === Bugfixes
12
+ * Include BCCed and CCed messsages in the mailbox. (Jakub Kosiński)
13
+
6
14
  == 0.2.0 2009-6-08
7
15
  No changes. Bumping version for RubyForge release.
8
16
 
@@ -11,7 +19,7 @@ No changes. Bumping version for RubyForge release.
11
19
 
12
20
  === Bufixes
13
21
  * Require deliveries in the helpers so it doesn't blow up with RSpec. (Craig Webster)
14
-
22
+
15
23
  == 0.1.3 2009-4-15
16
24
 
17
25
  === Bufixes
data/Rakefile CHANGED
@@ -49,3 +49,10 @@ end
49
49
 
50
50
  task :default => [:features, :spec, 'example_app:spec']
51
51
 
52
+ desc "Cleans the project of any tmp file that should not be included in the gemspec."
53
+ task :clean do
54
+ %w[*.sqlite3 *.log].each do |pattern|
55
+ `find . -name "#{pattern}" -delete`
56
+ end
57
+ end
58
+
@@ -3,7 +3,7 @@ module EmailSpec
3
3
  def all_emails
4
4
  ActionMailer::Base.deliveries
5
5
  end
6
-
6
+
7
7
  def last_email_sent
8
8
  ActionMailer::Base.deliveries.last || raise("No email has been sent!")
9
9
  end
@@ -11,18 +11,18 @@ module EmailSpec
11
11
  def reset_mailer
12
12
  ActionMailer::Base.deliveries.clear
13
13
  end
14
-
14
+
15
15
  def mailbox_for(address)
16
16
  address = AddressConverter.instance.convert(address)
17
- ActionMailer::Base.deliveries.select { |m| m.to.include?(address) }
17
+ ActionMailer::Base.deliveries.select { |m| m.to.include?(address) || (m.bcc && m.bcc.include?(address)) || (m.cc && m.cc.include?(address)) }
18
18
  end
19
19
  end
20
-
20
+
21
21
  module ARMailerDeliveries
22
22
  def all_emails
23
23
  Email.all.map{ |email| parse_to_tmail(email) }
24
24
  end
25
-
25
+
26
26
  def last_email_sent
27
27
  if email = Email.last
28
28
  TMail::Mail.parse(email.mail)
@@ -34,22 +34,23 @@ module EmailSpec
34
34
  def reset_mailer
35
35
  Email.delete_all
36
36
  end
37
-
37
+
38
38
  def mailbox_for(address)
39
39
  address = AddressConverter.instance.convert(address)
40
- Email.all.select { |email| email.to.include?(address) }.map{ |email| parse_to_tmail(email) }
40
+ Email.all.select { |email| email.to.include?(address) || email.bcc.include?(address) || email.cc.include?(address) }.map{ |email| parse_to_tmail(email) }
41
41
  end
42
-
42
+
43
43
  def parse_to_tmail(email)
44
44
  TMail::Mail.parse(email.mail)
45
- end
45
+ end
46
46
  end
47
-
47
+
48
48
  module Deliveries
49
49
  if ActionMailer::Base.delivery_method == :activerecord
50
50
  include EmailSpec::ARMailerDeliveries
51
51
  else
52
52
  include EmailSpec::TestDeliveries
53
- end
53
+ end
54
54
  end
55
- end
55
+ end
56
+
@@ -37,6 +37,39 @@ module EmailSpec
37
37
 
38
38
  alias :be_delivered_to :deliver_to
39
39
 
40
+ class BccTo
41
+
42
+ def initialize(expected_email_addresses_or_objects_that_respond_to_email)
43
+ emails = expected_email_addresses_or_objects_that_respond_to_email.map do |email_or_object|
44
+ email_or_object.kind_of?(String) ? email_or_object : email_or_object.email
45
+ end
46
+
47
+ @expected_email_addresses = emails.sort
48
+ end
49
+
50
+ def description
51
+ "be bcc'd to #{@expected_email_addresses.inspect}"
52
+ end
53
+
54
+ def matches?(email)
55
+ @email = email
56
+ @actual_recipients = (email.bcc || []).sort
57
+ @actual_recipients == @expected_email_addresses
58
+ end
59
+
60
+ def failure_message
61
+ "expected #{@email.inspect} to bcc to #{@expected_email_addresses.inspect}, but it was bcc'd to #{@actual_recipients.inspect}"
62
+ end
63
+
64
+ def negative_failure_message
65
+ "expected #{@email.inspect} not to bcc to #{@expected_email_addresses.inspect}, but it did"
66
+ end
67
+ end
68
+
69
+ def bcc_to(*expected_email_addresses_or_objects_that_respond_to_email)
70
+ BccTo.new(expected_email_addresses_or_objects_that_respond_to_email.flatten)
71
+ end
72
+
40
73
  def have_subject(expected)
41
74
  simple_matcher do |given, matcher|
42
75
  given_subject = given.subject
@@ -74,6 +74,36 @@ describe EmailSpec::Matchers do
74
74
 
75
75
  end
76
76
 
77
+ describe "#bcc_to" do
78
+
79
+ it "should match when the email is set to deliver to the specidied address" do
80
+ email = mock_email(:bcc => "jimmy_bean@yahoo.com")
81
+
82
+ bcc_to("jimmy_bean@yahoo.com").should match(email)
83
+ end
84
+
85
+ it "should match when a list of emails is exact same as all of the email's recipients" do
86
+ email = mock_email(:bcc => ["james@yahoo.com", "karen@yahoo.com"])
87
+
88
+ bcc_to("karen@yahoo.com", "james@yahoo.com").should match(email)
89
+ bcc_to("karen@yahoo.com").should_not match(email)
90
+ end
91
+
92
+ it "should match when an array of emails is exact same as all of the email's recipients" do
93
+ addresses = ["james@yahoo.com", "karen@yahoo.com"]
94
+ email = mock_email(:bcc => addresses)
95
+ bcc_to(addresses).should match(email)
96
+ end
97
+
98
+ it "should use the passed in objects :email method if not a string" do
99
+ email = mock_email(:bcc => "jimmy_bean@yahoo.com")
100
+ user = mock("user", :email => "jimmy_bean@yahoo.com")
101
+
102
+ bcc_to(user).should match(email)
103
+ end
104
+
105
+ end
106
+
77
107
  describe "#have_subject" do
78
108
 
79
109
  describe "when regexps are used" do
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.2.0
4
+ version: 0.2.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: 2009-06-08 00:00:00 -06:00
14
+ date: 2009-07-18 00:00:00 -06:00
15
15
  default_executable:
16
16
  dependencies: []
17
17
 
@@ -60,8 +60,6 @@ files:
60
60
  - examples/rails_root/features/step_definitions/user_steps.rb
61
61
  - examples/rails_root/features/step_definitions/webrat_steps.rb
62
62
  - examples/rails_root/features/support/env.rb
63
- - examples/rails_root/log/development.log
64
- - examples/rails_root/log/test.log
65
63
  - examples/rails_root/public/404.html
66
64
  - examples/rails_root/public/422.html
67
65
  - examples/rails_root/public/500.html
@@ -1 +0,0 @@
1
- # Logfile created on Mon Jun 08 20:15:58 -0600 2009
@@ -1,224 +0,0 @@
1
- # Logfile created on Mon Jun 08 20:16:03 -0600 2009 SQL (0.3ms)  SELECT name
2
- FROM sqlite_master
3
- WHERE type = 'table' AND NOT name = 'sqlite_sequence'
4
- 
5
- SQL (0.2ms) select sqlite_version(*)
6
- SQL (2.7ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) 
7
- SQL (43.5ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
8
- SQL (0.3ms)  SELECT name
9
- FROM sqlite_master
10
- WHERE type = 'table' AND NOT name = 'sqlite_sequence'
11
- 
12
- SQL (0.1ms) SELECT version FROM schema_migrations
13
- Migrating to CreateUsers (20090125013728)
14
- SQL (32.4ms) CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "email" varchar(255), "name" varchar(255)) 
15
- SQL (5.7ms) INSERT INTO schema_migrations (version) VALUES ('20090125013728')
16
- SQL (0.4ms)  SELECT name
17
- FROM sqlite_master
18
- WHERE type = 'table' AND NOT name = 'sqlite_sequence'
19
- 
20
- SQL (0.2ms) SELECT version FROM schema_migrations
21
- SQL (0.2ms)  SELECT name
22
- FROM sqlite_master
23
- WHERE type = 'table' AND NOT name = 'sqlite_sequence'
24
- 
25
- SQL (0.1ms) PRAGMA index_list("users")
26
- REQUESTING PAGE: GET / with {} and HTTP headers {}
27
-
28
-
29
- Processing WelcomeController#index (for 127.0.0.1 at 2009-06-08 20:16:10) [GET]
30
- Rendering welcome/index
31
- Completed in 3ms (View: 1, DB: 0) | 200 OK [http://www.example.com/]
32
- REQUESTING PAGE: POST /welcome/signup with {"Name"=>"", "commit"=>"Sign up", "Email"=>"quentin@example.com"} and HTTP headers {"HTTP_REFERER"=>"/"}
33
-
34
-
35
- Processing WelcomeController#signup (for 127.0.0.1 at 2009-06-08 20:16:10) [POST]
36
- Parameters: {"Name"=>"", "commit"=>"Sign up", "Email"=>"quentin@example.com"}
37
- Sent mail to quentin@example.com
38
-
39
- Date: Mon, 8 Jun 2009 20:16:10 -0600
40
- From: admin@example.com
41
- To: quentin@example.com
42
- Subject: Account confirmation
43
- Mime-Version: 1.0
44
- Content-Type: text/plain; charset=utf-8
45
-
46
- Hello !
47
-
48
- <a href="http:///confirm">Click here to confirm your account!</a>
49
- Rendering welcome/signup
50
- Completed in 5ms (View: 1, DB: 0) | 200 OK [http://www.example.com/welcome/signup]
51
- REQUESTING PAGE: GET / with {} and HTTP headers {}
52
-
53
-
54
- Processing WelcomeController#index (for 127.0.0.1 at 2009-06-08 20:16:10) [GET]
55
- Rendering welcome/index
56
- Completed in 1ms (View: 1, DB: 0) | 200 OK [http://www.example.com/]
57
- REQUESTING PAGE: POST /welcome/signup with {"Name"=>"", "commit"=>"Sign up", "Email"=>"quentin@example.com"} and HTTP headers {"HTTP_REFERER"=>"/"}
58
-
59
-
60
- Processing WelcomeController#signup (for 127.0.0.1 at 2009-06-08 20:16:10) [POST]
61
- Parameters: {"Name"=>"", "commit"=>"Sign up", "Email"=>"quentin@example.com"}
62
- Sent mail to quentin@example.com
63
-
64
- Date: Mon, 8 Jun 2009 20:16:10 -0600
65
- From: admin@example.com
66
- To: quentin@example.com
67
- Subject: Account confirmation
68
- Mime-Version: 1.0
69
- Content-Type: text/plain; charset=utf-8
70
-
71
- Hello !
72
-
73
- <a href="http:///confirm">Click here to confirm your account!</a>
74
- Rendering welcome/signup
75
- Completed in 4ms (View: 0, DB: 0) | 200 OK [http://www.example.com/welcome/signup]
76
- REQUESTING PAGE: GET / with {} and HTTP headers {}
77
-
78
-
79
- Processing WelcomeController#index (for 127.0.0.1 at 2009-06-08 20:16:10) [GET]
80
- Rendering welcome/index
81
- Completed in 1ms (View: 1, DB: 0) | 200 OK [http://www.example.com/]
82
- REQUESTING PAGE: POST /welcome/signup with {"Name"=>"", "commit"=>"Sign up", "Email"=>"quentin@example.com"} and HTTP headers {"HTTP_REFERER"=>"/"}
83
-
84
-
85
- Processing WelcomeController#signup (for 127.0.0.1 at 2009-06-08 20:16:10) [POST]
86
- Parameters: {"Name"=>"", "commit"=>"Sign up", "Email"=>"quentin@example.com"}
87
- Sent mail to quentin@example.com
88
-
89
- Date: Mon, 8 Jun 2009 20:16:10 -0600
90
- From: admin@example.com
91
- To: quentin@example.com
92
- Subject: Account confirmation
93
- Mime-Version: 1.0
94
- Content-Type: text/plain; charset=utf-8
95
-
96
- Hello !
97
-
98
- <a href="http:///confirm">Click here to confirm your account!</a>
99
- Rendering welcome/signup
100
- Completed in 4ms (View: 1, DB: 0) | 200 OK [http://www.example.com/welcome/signup]
101
- REQUESTING PAGE: GET / with {} and HTTP headers {}
102
-
103
-
104
- Processing WelcomeController#index (for 127.0.0.1 at 2009-06-08 20:16:10) [GET]
105
- Rendering welcome/index
106
- Completed in 1ms (View: 1, DB: 0) | 200 OK [http://www.example.com/]
107
- REQUESTING PAGE: POST /welcome/signup with {"Name"=>"", "commit"=>"Sign up", "Email"=>"quentin@example.com"} and HTTP headers {"HTTP_REFERER"=>"/"}
108
-
109
-
110
- Processing WelcomeController#signup (for 127.0.0.1 at 2009-06-08 20:16:10) [POST]
111
- Parameters: {"Name"=>"", "commit"=>"Sign up", "Email"=>"quentin@example.com"}
112
- Sent mail to quentin@example.com
113
-
114
- Date: Mon, 8 Jun 2009 20:16:10 -0600
115
- From: admin@example.com
116
- To: quentin@example.com
117
- Subject: Account confirmation
118
- Mime-Version: 1.0
119
- Content-Type: text/plain; charset=utf-8
120
-
121
- Hello !
122
-
123
- <a href="http:///confirm">Click here to confirm your account!</a>
124
- Rendering welcome/signup
125
- Completed in 5ms (View: 1, DB: 0) | 200 OK [http://www.example.com/welcome/signup]
126
- REQUESTING PAGE: GET / with {} and HTTP headers {}
127
-
128
-
129
- Processing WelcomeController#index (for 127.0.0.1 at 2009-06-08 20:16:10) [GET]
130
- Rendering welcome/index
131
- Completed in 1ms (View: 1, DB: 0) | 200 OK [http://www.example.com/]
132
- REQUESTING PAGE: POST /welcome/signup with {"Name"=>"Quentin Jones", "commit"=>"Sign up", "Email"=>"quentin@example.com"} and HTTP headers {"HTTP_REFERER"=>"/"}
133
-
134
-
135
- Processing WelcomeController#signup (for 127.0.0.1 at 2009-06-08 20:16:10) [POST]
136
- Parameters: {"Name"=>"Quentin Jones", "commit"=>"Sign up", "Email"=>"quentin@example.com"}
137
- Sent mail to quentin@example.com
138
-
139
- Date: Mon, 8 Jun 2009 20:16:10 -0600
140
- From: admin@example.com
141
- To: quentin@example.com
142
- Subject: Account confirmation
143
- Mime-Version: 1.0
144
- Content-Type: text/plain; charset=utf-8
145
-
146
- Hello Quentin Jones!
147
-
148
- <a href="http:///confirm">Click here to confirm your account!</a>
149
- Rendering welcome/signup
150
- Completed in 5ms (View: 1, DB: 0) | 200 OK [http://www.example.com/welcome/signup]
151
- REQUESTING PAGE: GET /confirm with {} and HTTP headers {"HTTP_REFERER"=>"/welcome/signup"}
152
-
153
-
154
- Processing WelcomeController#confirm (for 127.0.0.1 at 2009-06-08 20:16:10) [GET]
155
- Rendering welcome/confirm
156
- Completed in 1ms (View: 1, DB: 0) | 200 OK [http://www.example.com/confirm]
157
- REQUESTING PAGE: GET / with {} and HTTP headers {}
158
-
159
-
160
- Processing WelcomeController#index (for 127.0.0.1 at 2009-06-08 20:16:10) [GET]
161
- Rendering welcome/index
162
- Completed in 1ms (View: 1, DB: 0) | 200 OK [http://www.example.com/]
163
- REQUESTING PAGE: POST /welcome/signup with {"Name"=>"Quentin Jones", "commit"=>"Sign up", "Email"=>"quentin@example.com"} and HTTP headers {"HTTP_REFERER"=>"/"}
164
-
165
-
166
- Processing WelcomeController#signup (for 127.0.0.1 at 2009-06-08 20:16:10) [POST]
167
- Parameters: {"Name"=>"Quentin Jones", "commit"=>"Sign up", "Email"=>"quentin@example.com"}
168
- Sent mail to quentin@example.com
169
-
170
- Date: Mon, 8 Jun 2009 20:16:10 -0600
171
- From: admin@example.com
172
- To: quentin@example.com
173
- Subject: Account confirmation
174
- Mime-Version: 1.0
175
- Content-Type: text/plain; charset=utf-8
176
-
177
- Hello Quentin Jones!
178
-
179
- <a href="http:///confirm">Click here to confirm your account!</a>
180
- Rendering welcome/signup
181
- Completed in 4ms (View: 1, DB: 0) | 200 OK [http://www.example.com/welcome/signup]
182
- REQUESTING PAGE: GET /confirm with {} and HTTP headers {"HTTP_REFERER"=>"/welcome/signup"}
183
-
184
-
185
- Processing WelcomeController#confirm (for 127.0.0.1 at 2009-06-08 20:16:10) [GET]
186
- Rendering welcome/confirm
187
- Completed in 1ms (View: 1, DB: 0) | 200 OK [http://www.example.com/confirm]
188
- REQUESTING PAGE: GET / with {} and HTTP headers {}
189
-
190
-
191
- Processing WelcomeController#index (for 127.0.0.1 at 2009-06-08 20:16:10) [GET]
192
- Rendering welcome/index
193
- Completed in 1ms (View: 1, DB: 0) | 200 OK [http://www.example.com/]
194
- REQUESTING PAGE: POST /welcome/signup with {"Name"=>"Jojo Binks", "commit"=>"Sign up", "Email"=>"jojo@thebinks.com"} and HTTP headers {"HTTP_REFERER"=>"/"}
195
-
196
-
197
- Processing WelcomeController#signup (for 127.0.0.1 at 2009-06-08 20:16:11) [POST]
198
- Parameters: {"Name"=>"Jojo Binks", "commit"=>"Sign up", "Email"=>"jojo@thebinks.com"}
199
- Sent mail to jojo@thebinks.com
200
-
201
- Date: Mon, 8 Jun 2009 20:16:11 -0600
202
- From: admin@example.com
203
- To: jojo@thebinks.com
204
- Subject: Account confirmation
205
- Mime-Version: 1.0
206
- Content-Type: text/plain; charset=utf-8
207
-
208
- Hello Jojo Binks!
209
-
210
- <a href="http:///confirm">Click here to confirm your account!</a>
211
- Rendering welcome/signup
212
- Completed in 5ms (View: 0, DB: 0) | 200 OK [http://www.example.com/welcome/signup]
213
- REQUESTING PAGE: GET /confirm with {} and HTTP headers {"HTTP_REFERER"=>"/welcome/signup"}
214
-
215
-
216
- Processing WelcomeController#confirm (for 127.0.0.1 at 2009-06-08 20:16:11) [GET]
217
- Rendering welcome/confirm
218
- Completed in 1ms (View: 1, DB: 0) | 200 OK [http://www.example.com/confirm]
219
-
220
-
221
- Processing WelcomeController#signup (for 0.0.0.0 at 2009-06-08 20:16:17) [POST]
222
- Parameters: {"Name"=>"Jimmy Bean", "Email"=>"email@example.com"}
223
- Rendering welcome/signup
224
- Completed in 3ms (View: 0, DB: 0) | 200 OK [http://test.host/welcome/signup?Email=email%40example.com&Name=Jimmy+Bean]