email_spec 1.5.0 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,11 @@
1
- == 1.5.0 2012-07-22
1
+ == 1.6.0 2014-05-27
2
+
3
+ * New RSpec matcher API support (Morton Jonuschat)
4
+ * Turnip Doc updates (Joshua Muheim)
5
+ * Use Mail#destination for picking recipients (Lukasz Strzalkowski)
6
+ * Emails deliver to nobody when perform_deliveries is set to false (Sean Griffin)
7
+
8
+ == 1.5.0 2013-07-22
2
9
 
3
10
  * Upgraded use of Capybara to avoid deprecation warnings.
4
11
  * Upgraded use of RSpec to deal with new expect API (Thomas Drake-Brockman)
data/README.md CHANGED
@@ -131,6 +131,10 @@ describe SignupMailer do
131
131
  end
132
132
  ```
133
133
 
134
+ ### Turnip
135
+
136
+ If you're using [Turnip](https://github.com/jnicklas/turnip), you might be interested in this [conversion of the Cucumber steps into Turnip steps](https://github.com/jmuheim/transition/blob/master/spec/support/steps/email_steps.rb).
137
+
134
138
  ## Usage
135
139
 
136
140
  ### Cucumber
@@ -329,7 +333,7 @@ And of course you can use the matcher as an assertion:
329
333
 
330
334
  ```ruby
331
335
  email = UserMailer.create_signup "jojo@yahoo.com", "Jojo Binks"
332
- assert_must_deliver_to "jojo@yahoo.com", email
336
+ assert_must deliver_to("jojo@yahoo.com"), email
333
337
  ```
334
338
 
335
339
 
@@ -17,10 +17,7 @@ module EmailSpec
17
17
  end
18
18
 
19
19
  def mailbox_for(address)
20
- deliveries.select { |email|
21
- (email.to && email.to.include?(address)) ||
22
- (email.bcc && email.bcc.include?(address)) ||
23
- (email.cc && email.cc.include?(address)) }
20
+ deliveries.select { |email| email.destinations.include?(address) }
24
21
  end
25
22
 
26
23
  protected
@@ -41,7 +38,7 @@ module EmailSpec
41
38
 
42
39
  def last_email_sent
43
40
  if email = Email.last
44
- Mail.read(email.mail)
41
+ parse_to_mail(email)
45
42
  else
46
43
  raise("No email has been sent!")
47
44
  end
@@ -52,10 +49,7 @@ module EmailSpec
52
49
  end
53
50
 
54
51
  def mailbox_for(address)
55
- Email.all.select { |email|
56
- (email.to && email.to.include?(address)) ||
57
- (email.bcc && email.bcc.include?(address)) ||
58
- (email.cc && email.cc.include?(address)) }.map{ |email| parse_to_mail(email) }
52
+ Email.all.select { |email| email.destinations.include?(address) }.map{ |email| parse_to_mail(email) }
59
53
  end
60
54
 
61
55
  def parse_to_mail(email)
@@ -1,4 +1,4 @@
1
- require 'uri'
1
+ require 'uri'
2
2
  require 'email_spec/deliveries'
3
3
 
4
4
  module EmailSpec
@@ -180,4 +180,3 @@ module EmailSpec
180
180
 
181
181
  end
182
182
  end
183
-
@@ -1,5 +1,15 @@
1
1
  module EmailSpec
2
2
  module Matchers
3
+ class EmailMatcher
4
+ def address_array
5
+ if @email.perform_deliveries
6
+ Array(yield)
7
+ else
8
+ []
9
+ end
10
+ end
11
+ end
12
+
3
13
  class ReplyTo
4
14
  def initialize(email)
5
15
  @expected_reply_to = Mail::ReplyToField.new(email).addrs.first
@@ -20,9 +30,10 @@ module EmailSpec
20
30
  "expected #{@email.inspect} to reply to #{@expected_reply_to.address.inspect}, but it replied to #{@actual_reply_to.inspect}"
21
31
  end
22
32
 
23
- def negative_failure_message
33
+ def failure_message_when_negated
24
34
  "expected #{@email.inspect} not to deliver to #{@expected_reply_to.address.inspect}, but it did"
25
35
  end
36
+ alias negative_failure_message failure_message_when_negated
26
37
  end
27
38
 
28
39
  def reply_to(email)
@@ -31,7 +42,7 @@ module EmailSpec
31
42
 
32
43
  alias :have_reply_to :reply_to
33
44
 
34
- class DeliverTo
45
+ class DeliverTo < EmailMatcher
35
46
  def initialize(expected_email_addresses_or_objects_that_respond_to_email)
36
47
  emails = expected_email_addresses_or_objects_that_respond_to_email.map do |email_or_object|
37
48
  email_or_object.kind_of?(String) ? email_or_object : email_or_object.email
@@ -46,7 +57,7 @@ module EmailSpec
46
57
 
47
58
  def matches?(email)
48
59
  @email = email
49
- @actual_recipients = (email.header[:to].addrs || []).map(&:to_s).sort
60
+ @actual_recipients = address_array{ email.header[:to].addrs }.map(&:to_s).sort
50
61
  @actual_recipients == @expected_recipients
51
62
  end
52
63
 
@@ -54,9 +65,10 @@ module EmailSpec
54
65
  "expected #{@email.inspect} to deliver to #{@expected_recipients.inspect}, but it delivered to #{@actual_recipients.inspect}"
55
66
  end
56
67
 
57
- def negative_failure_message
68
+ def failure_message_when_negated
58
69
  "expected #{@email.inspect} not to deliver to #{@expected_recipients.inspect}, but it did"
59
70
  end
71
+ alias negative_failure_message failure_message_when_negated
60
72
  end
61
73
 
62
74
  def deliver_to(*expected_email_addresses_or_objects_that_respond_to_email)
@@ -65,7 +77,7 @@ module EmailSpec
65
77
 
66
78
  alias :be_delivered_to :deliver_to
67
79
 
68
- class DeliverFrom
80
+ class DeliverFrom < EmailMatcher
69
81
 
70
82
  def initialize(email)
71
83
  @expected_sender = Mail::FromField.new(email).addrs.first
@@ -77,7 +89,7 @@ module EmailSpec
77
89
 
78
90
  def matches?(email)
79
91
  @email = email
80
- @actual_sender = (email.header[:from].addrs || []).first
92
+ @actual_sender = address_array{ email.header[:from].addrs }.first
81
93
 
82
94
  !@actual_sender.nil? &&
83
95
  @actual_sender.to_s == @expected_sender.to_s
@@ -87,9 +99,10 @@ module EmailSpec
87
99
  %(expected #{@email.inspect} to deliver from "#{@expected_sender.to_s}", but it delivered from "#{@actual_sender.to_s}")
88
100
  end
89
101
 
90
- def negative_failure_message
102
+ def failure_message_when_negated
91
103
  %(expected #{@email.inspect} not to deliver from "#{@expected_sender.to_s}", but it did)
92
104
  end
105
+ alias negative_failure_message failure_message_when_negated
93
106
  end
94
107
 
95
108
  def deliver_from(email)
@@ -98,7 +111,7 @@ module EmailSpec
98
111
 
99
112
  alias :be_delivered_from :deliver_from
100
113
 
101
- class BccTo
114
+ class BccTo < EmailMatcher
102
115
 
103
116
  def initialize(expected_email_addresses_or_objects_that_respond_to_email)
104
117
  emails = expected_email_addresses_or_objects_that_respond_to_email.map do |email_or_object|
@@ -114,7 +127,7 @@ module EmailSpec
114
127
 
115
128
  def matches?(email)
116
129
  @email = email
117
- @actual_recipients = (Array(email.bcc) || []).sort
130
+ @actual_recipients = address_array{ email.bcc }.sort
118
131
  @actual_recipients == @expected_email_addresses
119
132
  end
120
133
 
@@ -122,16 +135,17 @@ module EmailSpec
122
135
  "expected #{@email.inspect} to bcc to #{@expected_email_addresses.inspect}, but it was bcc'd to #{@actual_recipients.inspect}"
123
136
  end
124
137
 
125
- def negative_failure_message
138
+ def failure_message_when_negated
126
139
  "expected #{@email.inspect} not to bcc to #{@expected_email_addresses.inspect}, but it did"
127
140
  end
141
+ alias negative_failure_message failure_message_when_negated
128
142
  end
129
143
 
130
144
  def bcc_to(*expected_email_addresses_or_objects_that_respond_to_email)
131
145
  BccTo.new(expected_email_addresses_or_objects_that_respond_to_email.flatten)
132
146
  end
133
147
 
134
- class CcTo
148
+ class CcTo < EmailMatcher
135
149
 
136
150
  def initialize(expected_email_addresses_or_objects_that_respond_to_email)
137
151
  emails = expected_email_addresses_or_objects_that_respond_to_email.map do |email_or_object|
@@ -147,7 +161,7 @@ module EmailSpec
147
161
 
148
162
  def matches?(email)
149
163
  @email = email
150
- @actual_recipients = (Array(email.cc) || []).sort
164
+ @actual_recipients = address_array { email.cc }.sort
151
165
  @actual_recipients == @expected_email_addresses
152
166
  end
153
167
 
@@ -155,9 +169,10 @@ module EmailSpec
155
169
  "expected #{@email.inspect} to cc to #{@expected_email_addresses.inspect}, but it was cc'd to #{@actual_recipients.inspect}"
156
170
  end
157
171
 
158
- def negative_failure_message
172
+ def failure_message_when_negated
159
173
  "expected #{@email.inspect} not to cc to #{@expected_email_addresses.inspect}, but it did"
160
174
  end
175
+ alias negative_failure_message failure_message_when_negated
161
176
  end
162
177
 
163
178
  def cc_to(*expected_email_addresses_or_objects_that_respond_to_email)
@@ -195,13 +210,14 @@ module EmailSpec
195
210
  end
196
211
  end
197
212
 
198
- def negative_failure_message
213
+ def failure_message_when_negated
199
214
  if @expected_subject.is_a?(String)
200
215
  "expected the subject not to be #{@expected_subject.inspect} but was"
201
216
  else
202
217
  "expected the subject not to match #{@expected_subject.inspect} but #{@given_subject.inspect} does match it."
203
218
  end
204
219
  end
220
+ alias negative_failure_message failure_message_when_negated
205
221
  end
206
222
 
207
223
  def have_subject(subject)
@@ -239,13 +255,14 @@ module EmailSpec
239
255
  end
240
256
  end
241
257
 
242
- def negative_failure_message
258
+ def failure_message_when_negated
243
259
  if @expected_subject.is_a?(String)
244
260
  "expected no email with the subject #{@expected_subject.inspect} but found at least one. Subjects were #{@given_emails.map(&:subject).inspect}"
245
261
  else
246
262
  "expected no email to have a subject matching #{@expected_subject.inspect} but found at least one. Subjects were #{@given_emails.map(&:subject).inspect}"
247
263
  end
248
264
  end
265
+ alias negative_failure_message failure_message_when_negated
249
266
  end
250
267
 
251
268
  def include_email_with_subject(*emails)
@@ -285,13 +302,14 @@ module EmailSpec
285
302
  end
286
303
  end
287
304
 
288
- def negative_failure_message
305
+ def failure_message_when_negated
289
306
  if @expected_text.is_a?(String)
290
307
  "expected the body not to contain #{@expected_text.inspect} but was #{@given_text.inspect}"
291
308
  else
292
309
  "expected the body not to match #{@expected_text.inspect} but #{@given_text.inspect} does match it."
293
310
  end
294
311
  end
312
+ alias negative_failure_message failure_message_when_negated
295
313
  end
296
314
 
297
315
  def have_body_text(text)
@@ -329,13 +347,14 @@ module EmailSpec
329
347
  end
330
348
  end
331
349
 
332
- def negative_failure_message
350
+ def failure_message_when_negated
333
351
  if @expected_value.is_a?(String)
334
352
  "expected the headers not to include '#{@expected_name}: #{@expected_value}' but they were #{mail_headers_hash(@given_header).inspect}"
335
353
  else
336
354
  "expected the headers not to include '#{@expected_name}' with a value matching #{@expected_value.inspect} but they were #{mail_headers_hash(@given_header).inspect}"
337
355
  end
338
356
  end
357
+ alias negative_failure_message failure_message_when_negated
339
358
 
340
359
  def mail_headers_hash(email_headers)
341
360
  email_headers.fields.inject({}) { |hash, field| hash[field.field.class::FIELD_NAME] = field.to_s; hash }
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: 1.5.0
4
+ version: 1.6.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-07-22 00:00:00.000000000 Z
14
+ date: 2014-05-27 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: launchy
@@ -189,22 +189,6 @@ dependencies:
189
189
  - - ! '>='
190
190
  - !ruby/object:Gem::Version
191
191
  version: '0'
192
- - !ruby/object:Gem::Dependency
193
- name: mail
194
- requirement: !ruby/object:Gem::Requirement
195
- none: false
196
- requirements:
197
- - - ! '>='
198
- - !ruby/object:Gem::Version
199
- version: '0'
200
- type: :development
201
- prerelease: false
202
- version_requirements: !ruby/object:Gem::Requirement
203
- none: false
204
- requirements:
205
- - - ! '>='
206
- - !ruby/object:Gem::Version
207
- version: '0'
208
192
  - !ruby/object:Gem::Dependency
209
193
  name: rails
210
194
  requirement: !ruby/object:Gem::Requirement
@@ -315,7 +299,8 @@ files:
315
299
  - rails_generators/email_spec/email_spec_generator.rb
316
300
  - rails_generators/email_spec/templates/email_steps.rb
317
301
  homepage: http://github.com/bmabey/email-spec/
318
- licenses: []
302
+ licenses:
303
+ - MIT
319
304
  post_install_message:
320
305
  rdoc_options: []
321
306
  require_paths: