gardelea-email_spec 1.3.0
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 +257 -0
- data/MIT-LICENSE.txt +19 -0
- data/README.md +277 -0
- data/Rakefile +17 -0
- data/lib/email-spec.rb +1 -0
- data/lib/email_spec.rb +18 -0
- data/lib/email_spec/address_converter.rb +29 -0
- data/lib/email_spec/background_processes.rb +45 -0
- data/lib/email_spec/cucumber.rb +26 -0
- data/lib/email_spec/deliveries.rb +91 -0
- data/lib/email_spec/email_viewer.rb +91 -0
- data/lib/email_spec/errors.rb +7 -0
- data/lib/email_spec/helpers.rb +175 -0
- data/lib/email_spec/mail_ext.rb +11 -0
- data/lib/email_spec/matchers.rb +257 -0
- data/lib/email_spec/test_observer.rb +7 -0
- data/lib/generators/email_spec/steps/USAGE +5 -0
- data/lib/generators/email_spec/steps/steps_generator.rb +14 -0
- data/lib/generators/email_spec/steps/templates/email_steps.rb +206 -0
- data/rails_generators/email_spec/email_spec_generator.rb +17 -0
- data/rails_generators/email_spec/templates/email_steps.rb +195 -0
- metadata +109 -0
@@ -0,0 +1,17 @@
|
|
1
|
+
# This generator adds email steps to the step definitions directory
|
2
|
+
generator_base = defined?(Rails) ? Rails::Generator::Base : RubiGen::Base
|
3
|
+
class EmailSpecGenerator < generator_base
|
4
|
+
def manifest
|
5
|
+
record do |m|
|
6
|
+
m.directory 'features/step_definitions'
|
7
|
+
m.file 'email_steps.rb', 'features/step_definitions/email_steps.rb'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
protected
|
12
|
+
|
13
|
+
def banner
|
14
|
+
"Usage: #{$0} email_spec"
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,195 @@
|
|
1
|
+
# Commonly used email steps
|
2
|
+
#
|
3
|
+
# To add your own steps make a custom_email_steps.rb
|
4
|
+
# The provided methods are:
|
5
|
+
#
|
6
|
+
# last_email_address
|
7
|
+
# reset_mailer
|
8
|
+
# open_last_email
|
9
|
+
# visit_in_email
|
10
|
+
# unread_emails_for
|
11
|
+
# mailbox_for
|
12
|
+
# current_email
|
13
|
+
# open_email
|
14
|
+
# read_emails_for
|
15
|
+
# find_email
|
16
|
+
#
|
17
|
+
# General form for email scenarios are:
|
18
|
+
# - clear the email queue (done automatically by email_spec)
|
19
|
+
# - execute steps that sends an email
|
20
|
+
# - check the user received an/no/[0-9] emails
|
21
|
+
# - open the email
|
22
|
+
# - inspect the email contents
|
23
|
+
# - interact with the email (e.g. click links)
|
24
|
+
#
|
25
|
+
# The Cucumber steps below are setup in this order.
|
26
|
+
|
27
|
+
module EmailHelpers
|
28
|
+
def current_email_address
|
29
|
+
# Replace with your way to find your current email (e.g @current_user.email).
|
30
|
+
# last_email_address will return the last email address used by email spec to find an email.
|
31
|
+
# Note that last_email_address will be reset after each Scenario.
|
32
|
+
last_email_address || "example@example.com"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
World(EmailHelpers)
|
37
|
+
|
38
|
+
#
|
39
|
+
# Reset the e-mail queue within a scenario.
|
40
|
+
# This is done automatically before each scenario.
|
41
|
+
#
|
42
|
+
|
43
|
+
Given /^(?:a clear email queue|no emails have been sent)$/ do
|
44
|
+
reset_mailer
|
45
|
+
end
|
46
|
+
|
47
|
+
#
|
48
|
+
# Check how many emails have been sent/received
|
49
|
+
#
|
50
|
+
|
51
|
+
Then /^(?:I|they|he|she|"([^"]*?)") should receive (an|no|\d+) emails?$/ do |address, amount|
|
52
|
+
unread_emails_for(address).size.should == parse_email_count(amount)
|
53
|
+
end
|
54
|
+
|
55
|
+
Then /^(?:I|they|he|she|"([^"]*?)") should have (an|no|\d+) emails?$/ do |address, amount|
|
56
|
+
mailbox_for(address).size.should == parse_email_count(amount)
|
57
|
+
end
|
58
|
+
|
59
|
+
Then /^(?:I|they|he|she|"([^"]*?)") should receive (an|no|\d+) emails? with subject "([^"]*?)"$/ do |address, amount, subject|
|
60
|
+
unread_emails_for(address).select { |m| m.subject =~ Regexp.new(Regexp.escape(subject)) }.size.should == parse_email_count(amount)
|
61
|
+
end
|
62
|
+
|
63
|
+
Then /^(?:I|they|he|she|"([^"]*?)") should receive an email with the following body:$/ do |address, expected_body|
|
64
|
+
open_email(address, :with_text => expected_body)
|
65
|
+
end
|
66
|
+
|
67
|
+
#
|
68
|
+
# Accessing emails
|
69
|
+
#
|
70
|
+
|
71
|
+
# Opens the most recently received email
|
72
|
+
When /^(?:I|they|he|she|"([^"]*?)") opens? the email$/ do |address|
|
73
|
+
open_email(address)
|
74
|
+
end
|
75
|
+
|
76
|
+
When /^(?:I|they|he|she|"([^"]*?)") opens? the email with subject "([^"]*?)"$/ do |address, subject|
|
77
|
+
open_email(address, :with_subject => subject)
|
78
|
+
end
|
79
|
+
|
80
|
+
When /^(?:I|they|he|she|"([^"]*?)") opens? the email with text "([^"]*?)"$/ do |address, text|
|
81
|
+
open_email(address, :with_text => text)
|
82
|
+
end
|
83
|
+
|
84
|
+
#
|
85
|
+
# Inspect the Email Contents
|
86
|
+
#
|
87
|
+
|
88
|
+
Then /^(?:I|they|he|she) should see "([^"]*?)" in the email subject$/ do |text|
|
89
|
+
current_email.should have_subject(text)
|
90
|
+
end
|
91
|
+
|
92
|
+
Then /^(?:I|they|he|she) should see "([^"]*?)" in the email body$/ do |text|
|
93
|
+
if current_email.multipart?
|
94
|
+
Then %(I should see "#{text}" in the html part of the email body)
|
95
|
+
Then %(I should see "#{text}" in the text part of the email body)
|
96
|
+
else
|
97
|
+
current_email.body.should =~ Regexp.new(text)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
Then /^(?:I|they|he|she) should see "([^"]*?)" in the html part of the email body$/ do |text|
|
102
|
+
current_email.html_part.body.should =~ Regexp.new(text)
|
103
|
+
end
|
104
|
+
|
105
|
+
Then /^(?:I|they|he|she) should see "([^"]*?)" in the text part of the email body$/ do |text|
|
106
|
+
current_email.text_part.body.should =~ Regexp.new(text)
|
107
|
+
end
|
108
|
+
|
109
|
+
Then /^(?:I|they|he|she) should see "([^"]*?)" in the email body$/ do |text|
|
110
|
+
current_email.body.should include(text)
|
111
|
+
end
|
112
|
+
|
113
|
+
Then /^(?:I|they|he|she) should see \/([^"]*?)\/ in the email body$/ do |text|
|
114
|
+
current_email.body.should =~ Regexp.new(text)
|
115
|
+
end
|
116
|
+
|
117
|
+
Then /^(?:I|they|he|she) should see the email delivered from "([^"]*?)"$/ do |text|
|
118
|
+
current_email.should be_delivered_from(text)
|
119
|
+
end
|
120
|
+
|
121
|
+
Then /^(?:I|they|he|she) should see "([^\"]*)" in the email "([^"]*?)" header$/ do |text, name|
|
122
|
+
current_email.should have_header(name, text)
|
123
|
+
end
|
124
|
+
|
125
|
+
Then /^(?:I|they|he|she) should see \/([^\"]*)\/ in the email "([^"]*?)" header$/ do |text, name|
|
126
|
+
current_email.should have_header(name, Regexp.new(text))
|
127
|
+
end
|
128
|
+
|
129
|
+
#
|
130
|
+
# Inspect the Email Attachments
|
131
|
+
#
|
132
|
+
|
133
|
+
Then /^(?:I|they|he|she) should see (an|no|\d+) attachments? with the email$/ do |amount|
|
134
|
+
current_email_attachments.size.should == parse_email_count(amount)
|
135
|
+
end
|
136
|
+
|
137
|
+
Then /^there should be (an|no|\d+) attachments? named "([^"]*?)"$/ do |amount, filename|
|
138
|
+
current_email_attachments.select { |a| a.original_filename == filename }.size.should == parse_email_count(amount)
|
139
|
+
end
|
140
|
+
|
141
|
+
Then /^attachment (\d+) should be named "([^"]*?)"$/ do |index, filename|
|
142
|
+
current_email_attachments[(index.to_i - 1)].original_filename.should == filename
|
143
|
+
end
|
144
|
+
|
145
|
+
Then /^there should be (an|no|\d+) attachments? of type "([^"]*?)"$/ do |amount, content_type|
|
146
|
+
current_email_attachments.select { |a| a.content_type == content_type }.size.should == parse_email_count(amount)
|
147
|
+
end
|
148
|
+
|
149
|
+
Then /^attachment (\d+) should be of type "([^"]*?)"$/ do |index, content_type|
|
150
|
+
current_email_attachments[(index.to_i - 1)].content_type.should == content_type
|
151
|
+
end
|
152
|
+
|
153
|
+
Then /^all attachments should not be blank$/ do
|
154
|
+
current_email_attachments.each do |attachment|
|
155
|
+
attachment.size.should_not == 0
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
Then /^show me a list of email attachments$/ do
|
160
|
+
EmailSpec::EmailViewer::save_and_open_email_attachments_list(current_email)
|
161
|
+
end
|
162
|
+
|
163
|
+
#
|
164
|
+
# Interact with Email Contents
|
165
|
+
#
|
166
|
+
|
167
|
+
When /^(?:I|they|he|she) follow "([^"]*?)" in the email$/ do |link|
|
168
|
+
visit_in_email(link)
|
169
|
+
end
|
170
|
+
|
171
|
+
When /^(?:I|they|he|she) click the first link in the email$/ do
|
172
|
+
click_first_link_in_email
|
173
|
+
end
|
174
|
+
|
175
|
+
#
|
176
|
+
# Debugging
|
177
|
+
# These only work with Rails and OSx ATM since EmailViewer uses RAILS_ROOT and OSx's 'open' command.
|
178
|
+
# Patches accepted. ;)
|
179
|
+
#
|
180
|
+
|
181
|
+
Then /^save and open current email$/ do
|
182
|
+
EmailSpec::EmailViewer::save_and_open_email(current_email)
|
183
|
+
end
|
184
|
+
|
185
|
+
Then /^save and open all text emails$/ do
|
186
|
+
EmailSpec::EmailViewer::save_and_open_all_text_emails
|
187
|
+
end
|
188
|
+
|
189
|
+
Then /^save and open all html emails$/ do
|
190
|
+
EmailSpec::EmailViewer::save_and_open_all_html_emails
|
191
|
+
end
|
192
|
+
|
193
|
+
Then /^save and open all raw emails$/ do
|
194
|
+
EmailSpec::EmailViewer::save_and_open_all_raw_emails
|
195
|
+
end
|
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gardelea-email_spec
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 1.3.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Ben Mabey
|
9
|
+
- Aaron Gibralter
|
10
|
+
- Mischa Fierer
|
11
|
+
autorequire:
|
12
|
+
bindir: bin
|
13
|
+
cert_chain: []
|
14
|
+
|
15
|
+
date: 2012-04-08 00:00:00 Z
|
16
|
+
dependencies:
|
17
|
+
- !ruby/object:Gem::Dependency
|
18
|
+
name: launchy
|
19
|
+
prerelease: false
|
20
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
21
|
+
none: false
|
22
|
+
requirements:
|
23
|
+
- - ~>
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: "2.1"
|
26
|
+
type: :runtime
|
27
|
+
version_requirements: *id001
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: mail
|
30
|
+
prerelease: false
|
31
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
32
|
+
none: false
|
33
|
+
requirements:
|
34
|
+
- - ~>
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: "2.2"
|
37
|
+
type: :runtime
|
38
|
+
version_requirements: *id002
|
39
|
+
- !ruby/object:Gem::Dependency
|
40
|
+
name: rspec
|
41
|
+
prerelease: false
|
42
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: "2.0"
|
48
|
+
type: :runtime
|
49
|
+
version_requirements: *id003
|
50
|
+
description: Easily test email in rspec and cucumber
|
51
|
+
email: ben@benmabey.com
|
52
|
+
executables: []
|
53
|
+
|
54
|
+
extensions: []
|
55
|
+
|
56
|
+
extra_rdoc_files:
|
57
|
+
- README.md
|
58
|
+
- MIT-LICENSE.txt
|
59
|
+
files:
|
60
|
+
- README.md
|
61
|
+
- History.txt
|
62
|
+
- MIT-LICENSE.txt
|
63
|
+
- Rakefile
|
64
|
+
- lib/email-spec.rb
|
65
|
+
- lib/email_spec.rb
|
66
|
+
- lib/email_spec/address_converter.rb
|
67
|
+
- lib/email_spec/background_processes.rb
|
68
|
+
- lib/email_spec/cucumber.rb
|
69
|
+
- lib/email_spec/deliveries.rb
|
70
|
+
- lib/email_spec/email_viewer.rb
|
71
|
+
- lib/email_spec/errors.rb
|
72
|
+
- lib/email_spec/helpers.rb
|
73
|
+
- lib/email_spec/mail_ext.rb
|
74
|
+
- lib/email_spec/matchers.rb
|
75
|
+
- lib/email_spec/test_observer.rb
|
76
|
+
- lib/generators/email_spec/steps/USAGE
|
77
|
+
- lib/generators/email_spec/steps/steps_generator.rb
|
78
|
+
- lib/generators/email_spec/steps/templates/email_steps.rb
|
79
|
+
- rails_generators/email_spec/email_spec_generator.rb
|
80
|
+
- rails_generators/email_spec/templates/email_steps.rb
|
81
|
+
homepage: http://github.com/bmabey/email-spec/
|
82
|
+
licenses: []
|
83
|
+
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: "0"
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: "0"
|
101
|
+
requirements: []
|
102
|
+
|
103
|
+
rubyforge_project:
|
104
|
+
rubygems_version: 1.8.16
|
105
|
+
signing_key:
|
106
|
+
specification_version: 3
|
107
|
+
summary: Easily test email in rspec and cucumber
|
108
|
+
test_files: []
|
109
|
+
|