bmabey-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 +9 -1
- data/Rakefile +7 -0
- data/lib/email_spec/deliveries.rb +13 -12
- data/lib/email_spec/matchers.rb +33 -0
- data/spec/email_spec/matchers_spec.rb +30 -0
- metadata +2 -2
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
|
+
|
data/lib/email_spec/matchers.rb
CHANGED
@@ -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: bmabey-email_spec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
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-
|
14
|
+
date: 2009-07-18 00:00:00 -07:00
|
15
15
|
default_executable:
|
16
16
|
dependencies: []
|
17
17
|
|