email_spec 1.2.0 → 1.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 +8 -1
- data/examples/rails3_root/Gemfile.lock +1 -1
- data/examples/rails3_root/features/errors.feature +8 -0
- data/examples/rails3_root/features/example.feature +24 -2
- data/examples/sinatra_root/features/errors.feature +8 -0
- data/examples/sinatra_root/features/example.feature +33 -2
- data/examples/sinatra_root/lib/example_sinatra_app.rb +12 -2
- data/lib/email_spec/helpers.rb +5 -2
- data/lib/email_spec/matchers.rb +4 -4
- data/lib/generators/email_spec/steps/templates/email_steps.rb +12 -0
- data/spec/email_spec/helpers_spec.rb +27 -7
- metadata +4 -4
data/History.txt
CHANGED
@@ -1,4 +1,11 @@
|
|
1
|
-
== 1.2 (git)
|
1
|
+
== 1.2.x (git)
|
2
|
+
|
3
|
+
== 1.2.1 2011-06-20
|
4
|
+
|
5
|
+
=== Bugfixes
|
6
|
+
* find_email now allows with_subject and with_text to be either a String or Regexp. Issue #67. (Curtis Miller)
|
7
|
+
|
8
|
+
== 1.2.0 2011-06-16
|
2
9
|
|
3
10
|
=== New features
|
4
11
|
* [he|she] options for steps. (Dan Croak)
|
@@ -14,10 +14,18 @@ Feature: Email-spec errors example
|
|
14
14
|
Then I should receive an email
|
15
15
|
When "example@example.com" opens the email with subject "no email"
|
16
16
|
|
17
|
+
Scenario: I fail to open an email with incorrect subject
|
18
|
+
Then I should receive an email
|
19
|
+
When "example@example.com" opens the email with subject /no email/
|
20
|
+
|
17
21
|
Scenario: I fail to open an email with incorrect text
|
18
22
|
Then I should receive an email
|
19
23
|
When "example@example.com" opens the email with text "no email"
|
20
24
|
|
25
|
+
Scenario: I fail to open an email with incorrect text
|
26
|
+
Then I should receive an email
|
27
|
+
When "example@example.com" opens the email with text /no email/
|
28
|
+
|
21
29
|
Scenario: I fail to receive an email with the expected link
|
22
30
|
Then I should receive an email
|
23
31
|
When I open the email
|
@@ -14,7 +14,7 @@ Feature: EmailSpec Example -- Prevent Bots from creating accounts
|
|
14
14
|
And I am on the homepage
|
15
15
|
And I submit my registration information
|
16
16
|
|
17
|
-
Scenario: First person signup (as myself) with
|
17
|
+
Scenario: First person signup (as myself) with three ways of opening email
|
18
18
|
Then I should receive an email
|
19
19
|
And I should have 1 email
|
20
20
|
|
@@ -30,12 +30,18 @@ Feature: EmailSpec Example -- Prevent Bots from creating accounts
|
|
30
30
|
And I should see "Joe Someone" in the email body
|
31
31
|
And I should see "confirm" in the email body
|
32
32
|
|
33
|
+
# Opening email #3
|
34
|
+
When I open the email with subject /Account confirmation/
|
35
|
+
Then I should see "Account confirmation" in the email subject
|
36
|
+
And I should see "Joe Someone" in the email body
|
37
|
+
And I should see "confirm" in the email body
|
38
|
+
|
33
39
|
When I follow "Click here to confirm your account!" in the email
|
34
40
|
Then I should see "Confirm your new account"
|
35
41
|
|
36
42
|
And "foo@bar.com" should have no emails
|
37
43
|
|
38
|
-
Scenario: Third person signup (emails sent to others) with
|
44
|
+
Scenario: Third person signup (emails sent to others) with three ways of opening email
|
39
45
|
Then "foo@bar.com" should have no emails
|
40
46
|
And "example@example.com" should receive an email
|
41
47
|
And "example@example.com" should have 1 email
|
@@ -52,6 +58,12 @@ Feature: EmailSpec Example -- Prevent Bots from creating accounts
|
|
52
58
|
And they should see "Joe Someone" in the email body
|
53
59
|
And they should see "confirm" in the email body
|
54
60
|
|
61
|
+
# Opening email #3
|
62
|
+
When "example@example.com" opens the email with subject /Account confirmation/
|
63
|
+
Then they should see "Account confirmation" in the email subject
|
64
|
+
And they should see "Joe Someone" in the email body
|
65
|
+
And they should see "confirm" in the email body
|
66
|
+
|
55
67
|
When they follow "Click here to confirm your account!" in the email
|
56
68
|
Then they should see "Confirm your new account"
|
57
69
|
|
@@ -69,3 +81,13 @@ Feature: EmailSpec Example -- Prevent Bots from creating accounts
|
|
69
81
|
When I open the email
|
70
82
|
Then I should see "This is the HTML part" in the email html part body
|
71
83
|
And I should see "This is the text part" in the email text part body
|
84
|
+
|
85
|
+
# Opening email #2
|
86
|
+
When I open the email with text "This is the HTML part"
|
87
|
+
Then I should see "This is the HTML part" in the email html part body
|
88
|
+
And I should see "This is the text part" in the email text part body
|
89
|
+
|
90
|
+
# Opening email #3
|
91
|
+
When I open the email with text /This is the HTML part/
|
92
|
+
Then I should see "This is the HTML part" in the email html part body
|
93
|
+
And I should see "This is the text part" in the email text part body
|
@@ -14,10 +14,18 @@ Feature: Email-spec errors example
|
|
14
14
|
Then I should receive an email
|
15
15
|
When "example@example.com" opens the email with subject "no email"
|
16
16
|
|
17
|
+
Scenario: I fail to open an email with incorrect subject
|
18
|
+
Then I should receive an email
|
19
|
+
When "example@example.com" opens the email with subject /no email/
|
20
|
+
|
17
21
|
Scenario: I fail to open an email with incorrect text
|
18
22
|
Then I should receive an email
|
19
23
|
When "example@example.com" opens the email with text "no email"
|
20
24
|
|
25
|
+
Scenario: I fail to open an email with incorrect text
|
26
|
+
Then I should receive an email
|
27
|
+
When "example@example.com" opens the email with text /no email/
|
28
|
+
|
21
29
|
Scenario: I fail to receive an email with the expected link
|
22
30
|
Then I should receive an email
|
23
31
|
When I open the email
|
@@ -14,7 +14,7 @@ Feature: EmailSpec Example -- Prevent Bots from creating accounts
|
|
14
14
|
And I am on the homepage
|
15
15
|
And I submit my registration information
|
16
16
|
|
17
|
-
Scenario: First person signup (as myself) with
|
17
|
+
Scenario: First person signup (as myself) with three ways of opening email
|
18
18
|
Then I should receive an email
|
19
19
|
And I should have 1 email
|
20
20
|
|
@@ -30,12 +30,18 @@ Feature: EmailSpec Example -- Prevent Bots from creating accounts
|
|
30
30
|
And I should see "Joe Someone" in the email body
|
31
31
|
And I should see "confirm" in the email body
|
32
32
|
|
33
|
+
# Opening email #3
|
34
|
+
When I open the email with subject /Account confirmation/
|
35
|
+
Then I should see "Account confirmation" in the email subject
|
36
|
+
And I should see "Joe Someone" in the email body
|
37
|
+
And I should see "confirm" in the email body
|
38
|
+
|
33
39
|
When I follow "Click here to confirm your account!" in the email
|
34
40
|
Then I should see "Confirm your new account"
|
35
41
|
|
36
42
|
And "foo@bar.com" should have no emails
|
37
43
|
|
38
|
-
Scenario: Third person signup (emails sent to others) with
|
44
|
+
Scenario: Third person signup (emails sent to others) with three ways of opening email
|
39
45
|
Then "foo@bar.com" should have no emails
|
40
46
|
And "example@example.com" should receive an email
|
41
47
|
And "example@example.com" should have 1 email
|
@@ -52,6 +58,12 @@ Feature: EmailSpec Example -- Prevent Bots from creating accounts
|
|
52
58
|
And they should see "Joe Someone" in the email body
|
53
59
|
And they should see "confirm" in the email body
|
54
60
|
|
61
|
+
# Opening email #3
|
62
|
+
When "example@example.com" opens the email with subject /Account confirmation/
|
63
|
+
Then they should see "Account confirmation" in the email subject
|
64
|
+
And they should see "Joe Someone" in the email body
|
65
|
+
And they should see "confirm" in the email body
|
66
|
+
|
55
67
|
When they follow "Click here to confirm your account!" in the email
|
56
68
|
Then they should see "Confirm your new account"
|
57
69
|
|
@@ -60,3 +72,22 @@ Feature: EmailSpec Example -- Prevent Bots from creating accounts
|
|
60
72
|
|
61
73
|
Scenario: Declarative First Person signup
|
62
74
|
Then they should receive an email with a link to a confirmation page
|
75
|
+
|
76
|
+
Scenario: Checking for text in different parts
|
77
|
+
Then I should receive an email
|
78
|
+
And I should have 1 email
|
79
|
+
|
80
|
+
# Opening email #1
|
81
|
+
When I open the email
|
82
|
+
Then I should see "This is the HTML part" in the email html part body
|
83
|
+
And I should see "This is the text part" in the email text part body
|
84
|
+
|
85
|
+
# Opening email #2
|
86
|
+
When I open the email with text "This is the HTML part"
|
87
|
+
Then I should see "This is the HTML part" in the email html part body
|
88
|
+
And I should see "This is the text part" in the email text part body
|
89
|
+
|
90
|
+
# Opening email #3
|
91
|
+
When I open the email with text /This is the HTML part/
|
92
|
+
Then I should see "This is the HTML part" in the email html part body
|
93
|
+
And I should see "This is the text part" in the email text part body
|
@@ -16,15 +16,25 @@ class ExampleSinatraApp < Sinatra::Base
|
|
16
16
|
|
17
17
|
post '/signup' do
|
18
18
|
user = params[:user]
|
19
|
-
body = <<-
|
19
|
+
body = <<-EOTEXT
|
20
|
+
Hello #{user['name']}!
|
21
|
+
|
22
|
+
Copy and paste this URL into your browser to confirm your account!
|
23
|
+
|
24
|
+
http://www.example.com/confirm
|
25
|
+
This is the text part.
|
26
|
+
EOTEXT
|
27
|
+
html_body = <<-EOHTML
|
20
28
|
Hello #{user['name']}!
|
21
29
|
|
22
30
|
<a href="http://www.example.com/confirm">Click here to confirm your account!</a>
|
31
|
+
This is the HTML part.
|
23
32
|
EOHTML
|
24
33
|
Pony.mail(:from => 'admin@example.com',
|
25
34
|
:to => user['email'],
|
26
35
|
:subject => 'Account confirmation',
|
27
|
-
:body => body
|
36
|
+
:body => body,
|
37
|
+
:html_body => html_body
|
28
38
|
)
|
29
39
|
'Thanks! Go check your email!'
|
30
40
|
end
|
data/lib/email_spec/helpers.rb
CHANGED
@@ -54,12 +54,15 @@ module EmailSpec
|
|
54
54
|
email_spec_hash[:read_emails][convert_address(address)] ||= []
|
55
55
|
end
|
56
56
|
|
57
|
+
# Should be able to accept String or Regexp options.
|
57
58
|
def find_email(address, opts={})
|
58
59
|
address = convert_address(address)
|
59
60
|
if opts[:with_subject]
|
60
|
-
|
61
|
+
expected_subject = (opts[:with_subject].is_a?(String) ? Regexp.escape(opts[:with_subject]) : opts[:with_subject])
|
62
|
+
mailbox_for(address).find { |m| m.subject =~ Regexp.new(expected_subject) }
|
61
63
|
elsif opts[:with_text]
|
62
|
-
|
64
|
+
expected_text = (opts[:with_text].is_a?(String) ? Regexp.escape(opts[:with_text]) : opts[:with_text])
|
65
|
+
mailbox_for(address).find { |m| m.default_part_body =~ Regexp.new(expected_text) }
|
63
66
|
else
|
64
67
|
mailbox_for(address).first
|
65
68
|
end
|
data/lib/email_spec/matchers.rb
CHANGED
@@ -164,7 +164,7 @@ module EmailSpec
|
|
164
164
|
CcTo.new(expected_email_addresses_or_objects_that_respond_to_email.flatten)
|
165
165
|
end
|
166
166
|
|
167
|
-
|
167
|
+
RSpec::Matchers.define :have_subject do
|
168
168
|
match do |given|
|
169
169
|
given_subject = given.subject
|
170
170
|
expected_subject = expected.first
|
@@ -185,7 +185,7 @@ module EmailSpec
|
|
185
185
|
end
|
186
186
|
end
|
187
187
|
|
188
|
-
|
188
|
+
RSpec::Matchers.define :include_email_with_subject do
|
189
189
|
match do |given_emails|
|
190
190
|
expected_subject = expected.first
|
191
191
|
|
@@ -205,7 +205,7 @@ module EmailSpec
|
|
205
205
|
end
|
206
206
|
end
|
207
207
|
|
208
|
-
|
208
|
+
RSpec::Matchers.define :have_body_text do
|
209
209
|
match do |given|
|
210
210
|
expected_text = expected.first
|
211
211
|
|
@@ -232,7 +232,7 @@ module EmailSpec
|
|
232
232
|
email_headers.fields.inject({}) { |hash, field| hash[field.field.class::FIELD_NAME] = field.to_s; hash }
|
233
233
|
end
|
234
234
|
|
235
|
-
|
235
|
+
RSpec::Matchers.define :have_header do
|
236
236
|
match do |given|
|
237
237
|
given_header = given.header
|
238
238
|
expected_name, expected_value = *expected
|
@@ -60,6 +60,10 @@ Then /^(?:I|they|"([^"]*?)") should receive (an|no|\d+) emails? with subject "([
|
|
60
60
|
unread_emails_for(address).select { |m| m.subject =~ Regexp.new(Regexp.escape(subject)) }.size.should == parse_email_count(amount)
|
61
61
|
end
|
62
62
|
|
63
|
+
Then /^(?:I|they|"([^"]*?)") should receive (an|no|\d+) emails? with subject \/([^"]*?)\/$/ do |address, amount, subject|
|
64
|
+
unread_emails_for(address).select { |m| m.subject =~ Regexp.new(subject) }.size.should == parse_email_count(amount)
|
65
|
+
end
|
66
|
+
|
63
67
|
Then /^(?:I|they|"([^"]*?)") should receive an email with the following body:$/ do |address, expected_body|
|
64
68
|
open_email(address, :with_text => expected_body)
|
65
69
|
end
|
@@ -77,10 +81,18 @@ When /^(?:I|they|"([^"]*?)") opens? the email with subject "([^"]*?)"$/ do |addr
|
|
77
81
|
open_email(address, :with_subject => subject)
|
78
82
|
end
|
79
83
|
|
84
|
+
When /^(?:I|they|"([^"]*?)") opens? the email with subject \/([^"]*?)\/$/ do |address, subject|
|
85
|
+
open_email(address, :with_subject => Regexp.new(subject))
|
86
|
+
end
|
87
|
+
|
80
88
|
When /^(?:I|they|"([^"]*?)") opens? the email with text "([^"]*?)"$/ do |address, text|
|
81
89
|
open_email(address, :with_text => text)
|
82
90
|
end
|
83
91
|
|
92
|
+
When /^(?:I|they|"([^"]*?)") opens? the email with text \/([^"]*?)\/$/ do |address, text|
|
93
|
+
open_email(address, :with_text => Regexp.new(text))
|
94
|
+
end
|
95
|
+
|
84
96
|
#
|
85
97
|
# Inspect the Email Contents
|
86
98
|
#
|
@@ -144,21 +144,32 @@ describe EmailSpec::Helpers do
|
|
144
144
|
end
|
145
145
|
|
146
146
|
it "should open the email with subject" do
|
147
|
-
open_email(@to, :with_subject => @
|
147
|
+
open_email(@to, :with_subject => @expected).should == @email
|
148
148
|
end
|
149
149
|
end
|
150
150
|
|
151
|
-
describe 'simple subject' do
|
151
|
+
describe 'simple string subject' do
|
152
152
|
before do
|
153
|
-
@subject
|
153
|
+
@subject = 'This is a simple subject'
|
154
|
+
@expected = 'a simple'
|
154
155
|
end
|
155
156
|
|
156
157
|
it_should_behave_like 'something that opens the email with subject'
|
157
158
|
end
|
158
159
|
|
159
|
-
describe 'with regex sensitive characters' do
|
160
|
+
describe 'string with regex sensitive characters' do
|
160
161
|
before do
|
161
|
-
@subject
|
162
|
+
@subject = '[app name] Contains regex characters?'
|
163
|
+
@expected = 'regex characters?'
|
164
|
+
end
|
165
|
+
|
166
|
+
it_should_behave_like 'something that opens the email with subject'
|
167
|
+
end
|
168
|
+
|
169
|
+
describe 'regular expression' do
|
170
|
+
before do
|
171
|
+
@subject = "This is a simple subject"
|
172
|
+
@expected = /a simple/
|
162
173
|
end
|
163
174
|
|
164
175
|
it_should_behave_like 'something that opens the email with subject'
|
@@ -178,7 +189,7 @@ describe EmailSpec::Helpers do
|
|
178
189
|
end
|
179
190
|
end
|
180
191
|
|
181
|
-
describe 'simple text' do
|
192
|
+
describe 'simple string text' do
|
182
193
|
before do
|
183
194
|
@body = 'This is an email body that is very simple'
|
184
195
|
@text = 'email body'
|
@@ -187,7 +198,7 @@ describe EmailSpec::Helpers do
|
|
187
198
|
it_should_behave_like 'something that opens the email with text'
|
188
199
|
end
|
189
200
|
|
190
|
-
describe 'with regex sensitive characters' do
|
201
|
+
describe 'string with regex sensitive characters' do
|
191
202
|
before do
|
192
203
|
@body = 'This is an email body. It contains some [regex] characters?'
|
193
204
|
@text = '[regex] characters?'
|
@@ -195,6 +206,15 @@ describe EmailSpec::Helpers do
|
|
195
206
|
|
196
207
|
it_should_behave_like 'something that opens the email with text'
|
197
208
|
end
|
209
|
+
|
210
|
+
describe 'regular expression' do
|
211
|
+
before do
|
212
|
+
@body = 'This is an email body.'
|
213
|
+
@text = /an\ email/
|
214
|
+
end
|
215
|
+
|
216
|
+
it_should_behave_like 'something that opens the email with text'
|
217
|
+
end
|
198
218
|
end
|
199
219
|
end
|
200
220
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: email_spec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 29
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 1.2.
|
9
|
+
- 1
|
10
|
+
version: 1.2.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ben Mabey
|
@@ -17,7 +17,7 @@ autorequire:
|
|
17
17
|
bindir: bin
|
18
18
|
cert_chain: []
|
19
19
|
|
20
|
-
date: 2011-06-
|
20
|
+
date: 2011-06-20 00:00:00 -06:00
|
21
21
|
default_executable:
|
22
22
|
dependencies:
|
23
23
|
- !ruby/object:Gem::Dependency
|