email_spec 1.6.0 → 2.0.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.
- checksums.yaml +7 -0
- data/History.txt +18 -0
- data/README.md +30 -28
- data/examples/rails4_root/Gemfile +19 -0
- data/examples/rails4_root/Gemfile.lock +180 -0
- data/examples/rails4_root/README +5 -0
- data/examples/rails4_root/Rakefile +11 -0
- data/examples/rails4_root/app/controllers/application_controller.rb +3 -0
- data/examples/rails4_root/app/controllers/welcome_controller.rb +18 -0
- data/examples/rails4_root/app/helpers/application_helper.rb +2 -0
- data/examples/rails4_root/app/mailers/user_mailer.rb +39 -0
- data/examples/rails4_root/app/models/user.rb +2 -0
- data/examples/rails4_root/app/views/user_mailer/email_with_attachment.html.erb +6 -0
- data/examples/rails4_root/app/views/user_mailer/newsletter.html.erb +8 -0
- data/examples/rails4_root/app/views/user_mailer/signup.html.erb +4 -0
- data/examples/rails4_root/app/views/user_mailer/signup.text.erb +4 -0
- data/examples/rails4_root/app/views/welcome/attachments.html.erb +0 -0
- data/examples/rails4_root/app/views/welcome/confirm.html.erb +1 -0
- data/examples/rails4_root/app/views/welcome/index.html.erb +8 -0
- data/examples/rails4_root/app/views/welcome/newsletter.html.erb +0 -0
- data/examples/rails4_root/app/views/welcome/signup.html.erb +1 -0
- data/examples/rails4_root/attachments/document.pdf +0 -0
- data/examples/rails4_root/attachments/image.png +0 -0
- data/examples/rails4_root/config.ru +4 -0
- data/examples/rails4_root/config/application.rb +45 -0
- data/examples/rails4_root/config/boot.rb +14 -0
- data/examples/rails4_root/config/cucumber.yml +8 -0
- data/examples/rails4_root/config/database.yml +25 -0
- data/examples/rails4_root/config/environment.rb +6 -0
- data/examples/rails4_root/config/environments/development.rb +19 -0
- data/examples/rails4_root/config/environments/production.rb +42 -0
- data/examples/rails4_root/config/environments/test.rb +32 -0
- data/examples/rails4_root/config/initializers/backtrace_silencers.rb +7 -0
- data/examples/rails4_root/config/initializers/cookie_verification_secret.rb +7 -0
- data/examples/rails4_root/config/initializers/delayed_job.rb +1 -0
- data/examples/rails4_root/config/initializers/inflections.rb +10 -0
- data/examples/rails4_root/config/initializers/mime_types.rb +5 -0
- data/examples/rails4_root/config/initializers/notifier_job.rb +1 -0
- data/examples/rails4_root/config/initializers/rspec_generator.rb +6 -0
- data/examples/rails4_root/config/initializers/session_store.rb +10 -0
- data/examples/rails4_root/config/locales/en.yml +5 -0
- data/examples/rails4_root/config/routes.rb +7 -0
- data/examples/rails4_root/config/secrets.yml +22 -0
- data/examples/rails4_root/db/migrate/20090125013728_create_users.rb +11 -0
- data/examples/rails4_root/db/migrate/20090908054656_create_delayed_jobs.rb +20 -0
- data/examples/rails4_root/db/migrate/20141119224309_add_queue_to_delayed_jobs.rb +9 -0
- data/examples/rails4_root/db/schema.rb +35 -0
- data/examples/rails4_root/db/seeds.rb +7 -0
- data/examples/rails4_root/db/test.sqlite3 +0 -0
- data/examples/rails4_root/doc/README_FOR_APP +2 -0
- data/examples/rails4_root/features/attachments.feature +27 -0
- data/examples/rails4_root/features/delayed_job.feature +13 -0
- data/examples/rails4_root/features/errors.feature +40 -0
- data/examples/rails4_root/features/example.feature +93 -0
- data/examples/rails4_root/features/step_definitions/email_steps.rb +210 -0
- data/examples/rails4_root/features/step_definitions/user_steps.rb +26 -0
- data/examples/rails4_root/features/step_definitions/web_steps.rb +219 -0
- data/examples/rails4_root/features/support/env.rb +59 -0
- data/examples/rails4_root/features/support/env_ext.rb +4 -0
- data/examples/rails4_root/features/support/paths.rb +33 -0
- data/examples/rails4_root/lib/notifier_job.rb +5 -0
- data/examples/rails4_root/lib/tasks/cucumber.rake +65 -0
- data/examples/rails4_root/lib/tasks/rspec.rake +69 -0
- data/examples/rails4_root/log/development.log +0 -0
- data/examples/rails4_root/log/test.log +43813 -0
- data/examples/rails4_root/public/404.html +26 -0
- data/examples/rails4_root/public/422.html +26 -0
- data/examples/rails4_root/public/500.html +26 -0
- data/examples/rails4_root/public/favicon.ico +0 -0
- data/examples/rails4_root/public/images/rails.png +0 -0
- data/examples/rails4_root/public/javascripts/application.js +2 -0
- data/examples/rails4_root/public/javascripts/controls.js +965 -0
- data/examples/rails4_root/public/javascripts/dragdrop.js +974 -0
- data/examples/rails4_root/public/javascripts/effects.js +1123 -0
- data/examples/rails4_root/public/javascripts/prototype.js +4874 -0
- data/examples/rails4_root/public/javascripts/rails.js +109 -0
- data/examples/rails4_root/public/robots.txt +5 -0
- data/examples/rails4_root/script/cucumber +10 -0
- data/examples/rails4_root/script/delayed_job +5 -0
- data/examples/rails4_root/script/rails +9 -0
- data/examples/rails4_root/spec/controllers/welcome_controller_spec.rb +20 -0
- data/examples/rails4_root/spec/models/user_mailer_spec.rb +47 -0
- data/examples/rails4_root/spec/spec_helper.rb +20 -0
- data/examples/rails4_root/test/mailers/user_mailer_classic_test.rb +27 -0
- data/examples/rails4_root/test/mailers/user_mailer_spec_test.rb +29 -0
- data/examples/rails4_root/test/test_helper.rb +10 -0
- data/{rails_generators → examples/rails4_root/vendor/plugins/email_spec/rails_generators}/email_spec/email_spec_generator.rb +0 -0
- data/{rails_generators → examples/rails4_root/vendor/plugins/email_spec/rails_generators}/email_spec/templates/email_steps.rb +22 -18
- data/examples/sinatra_root/Gemfile +15 -0
- data/examples/sinatra_root/Gemfile.lock +95 -0
- data/examples/sinatra_root/config.ru +4 -0
- data/examples/sinatra_root/features/errors.feature +40 -0
- data/examples/sinatra_root/features/example.feature +93 -0
- data/examples/sinatra_root/features/step_definitions/email_steps.rb +210 -0
- data/examples/sinatra_root/features/step_definitions/user_steps.rb +26 -0
- data/examples/sinatra_root/features/step_definitions/web_steps.rb +219 -0
- data/examples/sinatra_root/features/support/env.rb +21 -0
- data/examples/sinatra_root/features/support/paths.rb +29 -0
- data/examples/sinatra_root/lib/example_sinatra_app.rb +45 -0
- data/features/rails4_app.feature +32 -0
- data/features/sinatra_app.feature +14 -0
- data/features/step_definitions/app_steps.rb +58 -0
- data/features/support/env.rb +16 -0
- data/lib/email_spec.rb +1 -1
- data/lib/email_spec/deliveries.rb +0 -1
- data/lib/email_spec/email_viewer.rb +1 -1
- data/lib/email_spec/helpers.rb +16 -5
- data/lib/email_spec/matchers.rb +2 -1
- data/lib/email_spec/version.rb +3 -0
- data/lib/generators/email_spec/steps/templates/email_steps.rb +24 -20
- data/spec/email_spec/email_viewer_spec.rb +20 -0
- data/spec/email_spec/helpers_spec.rb +316 -0
- data/spec/email_spec/mail_ext_spec.rb +34 -0
- data/spec/email_spec/matchers_spec.rb +513 -0
- data/spec/spec_helper.rb +24 -0
- metadata +161 -150
- data/lib/email_spec/background_processes.rb +0 -45
- data/lib/generators/email_spec/steps/USAGE +0 -5
@@ -0,0 +1,40 @@
|
|
1
|
+
Feature: Email-spec errors example
|
2
|
+
In order to help alleviate email testing in apps
|
3
|
+
As a email-spec contributor I a newcomer
|
4
|
+
Should be able to easily determine where I have gone wrong
|
5
|
+
These scenarios should fail with helpful messages
|
6
|
+
|
7
|
+
Background:
|
8
|
+
Given I am on the homepage
|
9
|
+
And no emails have been sent
|
10
|
+
When I fill in "Email" with "example@example.com"
|
11
|
+
And I press "Sign up"
|
12
|
+
|
13
|
+
Scenario: I fail to open an email with incorrect subject
|
14
|
+
Then I should receive an email
|
15
|
+
When "example@example.com" opens the email with subject "no email"
|
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
|
+
|
21
|
+
Scenario: I fail to open an email with incorrect text
|
22
|
+
Then I should receive an email
|
23
|
+
When "example@example.com" opens the email with text "no email"
|
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
|
+
|
29
|
+
Scenario: I fail to receive an email with the expected link
|
30
|
+
Then I should receive an email
|
31
|
+
When I open the email
|
32
|
+
When I follow "link that doesn't exist" in the email
|
33
|
+
|
34
|
+
Scenario: I attempt to operate on an email that is not opened
|
35
|
+
Then I should receive an email
|
36
|
+
When I follow "confirm" in the email
|
37
|
+
|
38
|
+
Scenario: I attempt to check out an unopened email
|
39
|
+
Then I should see "confirm" in the email body
|
40
|
+
And I should see "Account confirmation" in the email subject
|
@@ -0,0 +1,93 @@
|
|
1
|
+
Feature: EmailSpec Example -- Prevent Bots from creating accounts
|
2
|
+
|
3
|
+
In order to help alleviate email testing in apps
|
4
|
+
As an email-spec contributor I want new users of the library
|
5
|
+
to easily adopt email-spec in their app by following this example
|
6
|
+
|
7
|
+
In order to prevent bots from setting up new accounts
|
8
|
+
As a site manager I want new users
|
9
|
+
to verify their email address with a confirmation link
|
10
|
+
|
11
|
+
Background:
|
12
|
+
Given no emails have been sent
|
13
|
+
And I am a real person wanting to sign up for an account
|
14
|
+
And I am on the homepage
|
15
|
+
And I submit my registration information
|
16
|
+
|
17
|
+
Scenario: First person signup (as myself) with three ways of opening email
|
18
|
+
Then I should receive an email
|
19
|
+
And I should have 1 email
|
20
|
+
|
21
|
+
# Opening email #1
|
22
|
+
When I open the email
|
23
|
+
Then I should see "Account confirmation" in the email subject
|
24
|
+
And I should see "Joe Someone" in the email body
|
25
|
+
And I should see "confirm" in the email body
|
26
|
+
|
27
|
+
# Opening email #2
|
28
|
+
When I open the email with subject "Account confirmation"
|
29
|
+
Then I should see "Account confirmation" in the email subject
|
30
|
+
And I should see "Joe Someone" in the email body
|
31
|
+
And I should see "confirm" in the email body
|
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
|
+
|
39
|
+
When I follow "Click here to confirm your account!" in the email
|
40
|
+
Then I should see "Confirm your new account"
|
41
|
+
|
42
|
+
And "foo@bar.com" should have no emails
|
43
|
+
|
44
|
+
Scenario: Third person signup (emails sent to others) with three ways of opening email
|
45
|
+
Then "foo@bar.com" should have no emails
|
46
|
+
And "example@example.com" should receive an email
|
47
|
+
And "example@example.com" should have 1 email
|
48
|
+
|
49
|
+
# Opening email #1
|
50
|
+
When they open the email
|
51
|
+
Then they should see "Account confirmation" in the email subject
|
52
|
+
And they should see "Joe Someone" in the email body
|
53
|
+
And they should see "confirm" in the email body
|
54
|
+
|
55
|
+
# Opening email #2
|
56
|
+
When "example@example.com" opens the email with subject "Account confirmation"
|
57
|
+
Then they should see "Account confirmation" in the email subject
|
58
|
+
And they should see "Joe Someone" in the email body
|
59
|
+
And they should see "confirm" in the email body
|
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
|
+
|
67
|
+
When they follow "Click here to confirm your account!" in the email
|
68
|
+
Then they should see "Confirm your new account"
|
69
|
+
|
70
|
+
Scenario: Declarative First Person signup
|
71
|
+
Then I should receive an email with a link to a confirmation page
|
72
|
+
|
73
|
+
Scenario: Declarative First Person signup
|
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
|
@@ -0,0 +1,210 @@
|
|
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 a 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|"([^"]*?)") should receive (an|no|\d+) emails?$/ do |address, amount|
|
52
|
+
expect(unread_emails_for(address).size).to eql parse_email_count(amount)
|
53
|
+
end
|
54
|
+
|
55
|
+
Then /^(?:I|they|"([^"]*?)") should have (an|no|\d+) emails?$/ do |address, amount|
|
56
|
+
expect(mailbox_for(address).size).to eql parse_email_count(amount)
|
57
|
+
end
|
58
|
+
|
59
|
+
Then /^(?:I|they|"([^"]*?)") should receive (an|no|\d+) emails? with subject "([^"]*?)"$/ do |address, amount, subject|
|
60
|
+
expect(unread_emails_for(address).select { |m| m.subject =~ Regexp.new(Regexp.escape(subject)) }.size).to eql parse_email_count(amount)
|
61
|
+
end
|
62
|
+
|
63
|
+
Then /^(?:I|they|"([^"]*?)") should receive (an|no|\d+) emails? with subject \/([^"]*?)\/$/ do |address, amount, subject|
|
64
|
+
expect(unread_emails_for(address).select { |m| m.subject =~ Regexp.new(subject) }.size).to eql parse_email_count(amount)
|
65
|
+
end
|
66
|
+
|
67
|
+
Then /^(?:I|they|"([^"]*?)") should receive an email with the following body:$/ do |address, expected_body|
|
68
|
+
open_email(address, :with_text => expected_body)
|
69
|
+
end
|
70
|
+
|
71
|
+
#
|
72
|
+
# Accessing emails
|
73
|
+
#
|
74
|
+
|
75
|
+
# Opens the most recently received email
|
76
|
+
When /^(?:I|they|"([^"]*?)") opens? the email$/ do |address|
|
77
|
+
open_email(address)
|
78
|
+
end
|
79
|
+
|
80
|
+
When /^(?:I|they|"([^"]*?)") opens? the email with subject "([^"]*?)"$/ do |address, subject|
|
81
|
+
open_email(address, :with_subject => subject)
|
82
|
+
end
|
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
|
+
|
88
|
+
When /^(?:I|they|"([^"]*?)") opens? the email with text "([^"]*?)"$/ do |address, text|
|
89
|
+
open_email(address, :with_text => text)
|
90
|
+
end
|
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
|
+
|
96
|
+
#
|
97
|
+
# Inspect the Email Contents
|
98
|
+
#
|
99
|
+
|
100
|
+
Then /^(?:I|they) should see "([^"]*?)" in the email subject$/ do |text|
|
101
|
+
expect(current_email).to have_subject(text)
|
102
|
+
end
|
103
|
+
|
104
|
+
Then /^(?:I|they) should see \/([^"]*?)\/ in the email subject$/ do |text|
|
105
|
+
expect(current_email).to have_subject(Regexp.new(text))
|
106
|
+
end
|
107
|
+
|
108
|
+
Then /^(?:I|they) should see "([^"]*?)" in the email body$/ do |text|
|
109
|
+
expect(current_email.default_part_body.to_s).to include(text)
|
110
|
+
end
|
111
|
+
|
112
|
+
Then /^(?:I|they) should see \/([^"]*?)\/ in the email body$/ do |text|
|
113
|
+
expect(current_email.default_part_body.to_s).to match Regexp.new(text)
|
114
|
+
end
|
115
|
+
|
116
|
+
Then /^(?:I|they) should see the email delivered from "([^"]*?)"$/ do |text|
|
117
|
+
expect(current_email).to be_delivered_from(text)
|
118
|
+
end
|
119
|
+
|
120
|
+
Then /^(?:I|they) should see the email reply to "([^"]*?)"$/ do |text|
|
121
|
+
current_email.should have_reply_to(text)
|
122
|
+
end
|
123
|
+
|
124
|
+
Then /^(?:I|they) should see "([^\"]*)" in the email "([^"]*?)" header$/ do |text, name|
|
125
|
+
expect(current_email).to have_header(name, text)
|
126
|
+
end
|
127
|
+
|
128
|
+
Then /^(?:I|they) should see \/([^\"]*)\/ in the email "([^"]*?)" header$/ do |text, name|
|
129
|
+
expect(current_email).to have_header(name, Regexp.new(text))
|
130
|
+
end
|
131
|
+
|
132
|
+
Then /^I should see it is a multi\-part email$/ do
|
133
|
+
expect(current_email).to be_multipart
|
134
|
+
end
|
135
|
+
|
136
|
+
Then /^(?:I|they) should see "([^"]*?)" in the email html part body$/ do |text|
|
137
|
+
expect(current_email.html_part.body.to_s).to include(text)
|
138
|
+
end
|
139
|
+
|
140
|
+
Then /^(?:I|they) should see "([^"]*?)" in the email text part body$/ do |text|
|
141
|
+
expect(current_email.text_part.body.to_s).to include(text)
|
142
|
+
end
|
143
|
+
|
144
|
+
#
|
145
|
+
# Inspect the Email Attachments
|
146
|
+
#
|
147
|
+
|
148
|
+
Then /^(?:I|they) should see (an|no|\d+) attachments? with the email$/ do |amount|
|
149
|
+
expect(current_email_attachments.size).to eql parse_email_count(amount)
|
150
|
+
end
|
151
|
+
|
152
|
+
Then /^there should be (an|no|\d+) attachments? named "([^"]*?)"$/ do |amount, filename|
|
153
|
+
expect(current_email_attachments.select { |a| a.filename == filename }.size).to eql parse_email_count(amount)
|
154
|
+
end
|
155
|
+
|
156
|
+
Then /^attachment (\d+) should be named "([^"]*?)"$/ do |index, filename|
|
157
|
+
expect(current_email_attachments[(index.to_i - 1)].filename).to eql filename
|
158
|
+
end
|
159
|
+
|
160
|
+
Then /^there should be (an|no|\d+) attachments? of type "([^"]*?)"$/ do |amount, content_type|
|
161
|
+
expect(current_email_attachments.select { |a| a.content_type.include?(content_type) }.size).to eql parse_email_count(amount)
|
162
|
+
end
|
163
|
+
|
164
|
+
Then /^attachment (\d+) should be of type "([^"]*?)"$/ do |index, content_type|
|
165
|
+
expect(current_email_attachments[(index.to_i - 1)].content_type).to include(content_type)
|
166
|
+
end
|
167
|
+
|
168
|
+
Then /^all attachments should not be blank$/ do
|
169
|
+
current_email_attachments.each do |attachment|
|
170
|
+
expect(attachment.read.size).to_not eql 0
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
Then /^show me a list of email attachments$/ do
|
175
|
+
EmailSpec::EmailViewer::save_and_open_email_attachments_list(current_email)
|
176
|
+
end
|
177
|
+
|
178
|
+
#
|
179
|
+
# Interact with Email Contents
|
180
|
+
#
|
181
|
+
|
182
|
+
When /^(?:I|they|"([^"]*?)") follows? "([^"]*?)" in the email$/ do |address, link|
|
183
|
+
visit_in_email(link, address)
|
184
|
+
end
|
185
|
+
|
186
|
+
When /^(?:I|they) click the first link in the email$/ do
|
187
|
+
click_first_link_in_email
|
188
|
+
end
|
189
|
+
|
190
|
+
#
|
191
|
+
# Debugging
|
192
|
+
# These only work with Rails and OSx ATM since EmailViewer uses RAILS_ROOT and OSx's 'open' command.
|
193
|
+
# Patches accepted. ;)
|
194
|
+
#
|
195
|
+
|
196
|
+
Then /^save and open current email$/ do
|
197
|
+
EmailSpec::EmailViewer::save_and_open_email(current_email)
|
198
|
+
end
|
199
|
+
|
200
|
+
Then /^save and open all text emails$/ do
|
201
|
+
EmailSpec::EmailViewer::save_and_open_all_text_emails
|
202
|
+
end
|
203
|
+
|
204
|
+
Then /^save and open all html emails$/ do
|
205
|
+
EmailSpec::EmailViewer::save_and_open_all_html_emails
|
206
|
+
end
|
207
|
+
|
208
|
+
Then /^save and open all raw emails$/ do
|
209
|
+
EmailSpec::EmailViewer::save_and_open_all_raw_emails
|
210
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
Given "I am a real person wanting to sign up for an account" do
|
2
|
+
# no-op.. for documentation purposes only!
|
3
|
+
end
|
4
|
+
|
5
|
+
When /^I submit my registration information$/ do
|
6
|
+
fill_in "Name", :with => 'Joe Someone'
|
7
|
+
fill_in "Email", :with => 'example@example.com'
|
8
|
+
click_button 'Sign up'
|
9
|
+
end
|
10
|
+
|
11
|
+
Then /^(?:I|they) should receive an email with a link to a confirmation page$/ do
|
12
|
+
expect(unread_emails_for(current_email_address).size).to eq 1
|
13
|
+
|
14
|
+
# this call will store the email and you can access it with current_email
|
15
|
+
open_last_email_for(last_email_address)
|
16
|
+
expect(current_email).to have_subject(/Account confirmation/)
|
17
|
+
expect(current_email).to have_body_text('Joe Someone')
|
18
|
+
|
19
|
+
click_email_link_matching /confirm/
|
20
|
+
expect(page).to have_content("Confirm your new account")
|
21
|
+
end
|
22
|
+
|
23
|
+
# Basically aliases "I should see [text]", but for third person
|
24
|
+
Then /^they should see "([^\"]*)"$/ do |text|
|
25
|
+
step "I should see \"#{text}\""
|
26
|
+
end
|
@@ -0,0 +1,219 @@
|
|
1
|
+
# Taken from the cucumber-rails project.
|
2
|
+
# IMPORTANT: This file is generated by cucumber-sinatra - edit at your own peril.
|
3
|
+
# It is recommended to regenerate this file in the future when you upgrade to a
|
4
|
+
# newer version of cucumber-sinatra. Consider adding your own code to a new file
|
5
|
+
# instead of editing this one. Cucumber will automatically load all features/**/*.rb
|
6
|
+
# files.
|
7
|
+
|
8
|
+
require 'uri'
|
9
|
+
require 'cgi'
|
10
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
|
11
|
+
|
12
|
+
module WithinHelpers
|
13
|
+
def with_scope(locator)
|
14
|
+
locator ? within(locator) { yield } : yield
|
15
|
+
end
|
16
|
+
end
|
17
|
+
World(WithinHelpers)
|
18
|
+
|
19
|
+
Given /^(?:|I )am on (.+)$/ do |page_name|
|
20
|
+
visit path_to(page_name)
|
21
|
+
end
|
22
|
+
|
23
|
+
When /^(?:|I )go to (.+)$/ do |page_name|
|
24
|
+
visit path_to(page_name)
|
25
|
+
end
|
26
|
+
|
27
|
+
When /^(?:|I )press "([^\"]*)"(?: within "([^\"]*)")?$/ do |button, selector|
|
28
|
+
with_scope(selector) do
|
29
|
+
click_button(button)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
When /^(?:|I )follow "([^\"]*)"(?: within "([^\"]*)")?$/ do |link, selector|
|
34
|
+
with_scope(selector) do
|
35
|
+
click_link(link)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
When /^(?:|I )fill in "([^\"]*)" with "([^\"]*)"(?: within "([^\"]*)")?$/ do |field, value, selector|
|
40
|
+
with_scope(selector) do
|
41
|
+
fill_in(field, :with => value)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
When /^(?:|I )fill in "([^\"]*)" for "([^\"]*)"(?: within "([^\"]*)")?$/ do |value, field, selector|
|
46
|
+
with_scope(selector) do
|
47
|
+
fill_in(field, :with => value)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# Use this to fill in an entire form with data from a table. Example:
|
52
|
+
#
|
53
|
+
# When I fill in the following:
|
54
|
+
# | Account Number | 5002 |
|
55
|
+
# | Expiry date | 2009-11-01 |
|
56
|
+
# | Note | Nice guy |
|
57
|
+
# | Wants Email? | |
|
58
|
+
#
|
59
|
+
# TODO: Add support for checkbox, select og option
|
60
|
+
# based on naming conventions.
|
61
|
+
#
|
62
|
+
When /^(?:|I )fill in the following(?: within "([^\"]*)")?:$/ do |selector, fields|
|
63
|
+
with_scope(selector) do
|
64
|
+
fields.rows_hash.each do |name, value|
|
65
|
+
When %{I fill in "#{name}" with "#{value}"}
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
When /^(?:|I )select "([^\"]*)" from "([^\"]*)"(?: within "([^\"]*)")?$/ do |value, field, selector|
|
71
|
+
with_scope(selector) do
|
72
|
+
select(value, :from => field)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
When /^(?:|I )check "([^\"]*)"(?: within "([^\"]*)")?$/ do |field, selector|
|
77
|
+
with_scope(selector) do
|
78
|
+
check(field)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
When /^(?:|I )uncheck "([^\"]*)"(?: within "([^\"]*)")?$/ do |field, selector|
|
83
|
+
with_scope(selector) do
|
84
|
+
uncheck(field)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
When /^(?:|I )choose "([^\"]*)"(?: within "([^\"]*)")?$/ do |field, selector|
|
89
|
+
with_scope(selector) do
|
90
|
+
choose(field)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
When /^(?:|I )attach the file "([^\"]*)" to "([^\"]*)"(?: within "([^\"]*)")?$/ do |path, field, selector|
|
95
|
+
with_scope(selector) do
|
96
|
+
attach_file(field, path)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
Then /^(?:|I )should see JSON:$/ do |expected_json|
|
101
|
+
require 'json'
|
102
|
+
expected = JSON.pretty_generate(JSON.parse(expected_json))
|
103
|
+
actual = JSON.pretty_generate(JSON.parse(response.body))
|
104
|
+
expect(expected).to eql actual
|
105
|
+
end
|
106
|
+
|
107
|
+
Then /^(?:|I )should see "([^\"]*)"(?: within "([^\"]*)")?$/ do |text, selector|
|
108
|
+
with_scope(selector) do
|
109
|
+
if self.respond_to? :expect
|
110
|
+
expect(page).to have_content(text)
|
111
|
+
else
|
112
|
+
assert page.has_content?(text)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
Then /^(?:|I )should see \/([^\/]*)\/(?: within "([^\"]*)")?$/ do |regexp, selector|
|
118
|
+
regexp = Regexp.new(regexp)
|
119
|
+
with_scope(selector) do
|
120
|
+
if self.respond_to? :expect
|
121
|
+
expect(page).to have_xpath('//*', :text => regexp)
|
122
|
+
else
|
123
|
+
assert page.has_xpath?('//*', :text => regexp)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
Then /^(?:|I )should not see "([^\"]*)"(?: within "([^\"]*)")?$/ do |text, selector|
|
129
|
+
with_scope(selector) do
|
130
|
+
if self.respond_to? :expect
|
131
|
+
expect(page).to have_no_content(text)
|
132
|
+
else
|
133
|
+
assert page.has_no_content?(text)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
Then /^(?:|I )should not see \/([^\/]*)\/(?: within "([^\"]*)")?$/ do |regexp, selector|
|
139
|
+
regexp = Regexp.new(regexp)
|
140
|
+
with_scope(selector) do
|
141
|
+
if self.respond_to? :expect
|
142
|
+
expect(page).to have_no_xpath('//*', :text => regexp)
|
143
|
+
else
|
144
|
+
assert page.has_no_xpath?('//*', :text => regexp)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
Then /^the "([^\"]*)" field(?: within "([^\"]*)")? should contain "([^\"]*)"$/ do |field, selector, value|
|
150
|
+
with_scope(selector) do
|
151
|
+
field = find_field(field)
|
152
|
+
field_value = (field.tag_name == 'textarea') ? field.text : field.value
|
153
|
+
if self.respond_to? :expect
|
154
|
+
expect(field_value).to match /#{value}/
|
155
|
+
else
|
156
|
+
assert_match(/#{value}/, field_value)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
Then /^the "([^\"]*)" field(?: within "([^\"]*)")? should not contain "([^\"]*)"$/ do |field, selector, value|
|
162
|
+
with_scope(selector) do
|
163
|
+
field = find_field(field)
|
164
|
+
field_value = (field.tag_name == 'textarea') ? field.text : field.value
|
165
|
+
if self.respond_to? :expect
|
166
|
+
expect(field_value).to_not match /#{value}/
|
167
|
+
else
|
168
|
+
assert_no_match(/#{value}/, field_value)
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
Then /^the "([^\"]*)" checkbox(?: within "([^\"]*)")? should be checked$/ do |label, selector|
|
174
|
+
with_scope(selector) do
|
175
|
+
field_checked = find_field(label)['checked']
|
176
|
+
if self.respond_to? :expect
|
177
|
+
epect(field_checked).to eql 'checked'
|
178
|
+
else
|
179
|
+
assert_equal 'checked', field_checked
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
Then /^the "([^\"]*)" checkbox(?: within "([^\"]*)")? should not be checked$/ do |label, selector|
|
185
|
+
with_scope(selector) do
|
186
|
+
field_checked = find_field(label)['checked']
|
187
|
+
if self.respond_to? :expect
|
188
|
+
expect(field_checked).to_not eql 'checked'
|
189
|
+
else
|
190
|
+
assert_not_equal 'checked', field_checked
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
Then /^(?:|I )should be on (.+)$/ do |page_name|
|
196
|
+
current_path = URI.parse(current_url).path
|
197
|
+
if self.respond_to? :expect
|
198
|
+
expect(current_path).to eql path_to(page_name)
|
199
|
+
else
|
200
|
+
assert_equal path_to(page_name), current_path
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
Then /^(?:|I )should have the following query string:$/ do |expected_pairs|
|
205
|
+
query = URI.parse(current_url).query
|
206
|
+
actual_params = query ? CGI.parse(query) : {}
|
207
|
+
expected_params = {}
|
208
|
+
expected_pairs.rows_hash.each_pair{|k,v| expected_params[k] = v.split(',')}
|
209
|
+
|
210
|
+
if self.respond_to? :expect
|
211
|
+
expect(actual_params).to eql expected_params
|
212
|
+
else
|
213
|
+
assert_equal expected_params, actual_params
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
Then /^show me the page$/ do
|
218
|
+
save_and_open_page
|
219
|
+
end
|