email_spec 0.3.0 → 0.3.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 +12 -2
- data/Rakefile +10 -1
- data/examples/rails_root/app/controllers/{application.rb → application_controller.rb} +0 -0
- data/examples/rails_root/app/models/user_mailer.rb +1 -2
- data/examples/rails_root/config/boot.rb +1 -0
- data/examples/rails_root/config/environment.rb +2 -2
- data/examples/rails_root/config/environments/test.rb +6 -10
- data/examples/rails_root/features/errors.feature +31 -41
- data/examples/rails_root/features/example.feature +44 -41
- data/examples/rails_root/features/step_definitions/email_steps.rb +66 -30
- data/examples/rails_root/features/step_definitions/user_steps.rb +11 -8
- data/examples/rails_root/features/step_definitions/webrat_steps.rb +72 -39
- data/examples/rails_root/features/support/env.rb +15 -4
- data/examples/rails_root/features/support/paths.rb +21 -0
- data/examples/rails_root/script/cucumber +6 -4
- data/examples/rails_root/spec/models/user_mailer_spec.rb +3 -3
- data/examples/rails_root/spec/spec_helper.rb +1 -1
- data/examples/rails_root/vendor/plugins/email_spec/rails_generators/email_spec/templates/email_steps.rb +66 -30
- data/lib/email_spec/deliveries.rb +0 -2
- data/lib/email_spec/helpers.rb +48 -31
- data/rails_generators/email_spec/templates/email_steps.rb +66 -30
- metadata +45 -78
- data/examples/rails_root/cucumber.yml +0 -1
@@ -1,104 +1,137 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
|
2
|
+
|
1
3
|
# Commonly used webrat steps
|
2
4
|
# http://github.com/brynary/webrat
|
3
5
|
|
4
|
-
Given /^I am
|
5
|
-
visit
|
6
|
+
Given /^I am on (.+)$/ do |page_name|
|
7
|
+
visit path_to(page_name)
|
6
8
|
end
|
7
9
|
|
8
|
-
|
9
|
-
|
10
|
-
visit locations[page]
|
10
|
+
When /^I go to (.+)$/ do |page_name|
|
11
|
+
visit path_to(page_name)
|
11
12
|
end
|
12
13
|
|
13
|
-
When /^I press "(
|
14
|
+
When /^I press "([^\"]*)"$/ do |button|
|
14
15
|
click_button(button)
|
15
16
|
end
|
16
17
|
|
17
|
-
When /^I follow "(
|
18
|
+
When /^I follow "([^\"]*)"$/ do |link|
|
18
19
|
click_link(link)
|
19
20
|
end
|
20
21
|
|
21
|
-
When /^I
|
22
|
-
|
22
|
+
When /^I follow "([^\"]*)" within "([^\"]*)"$/ do |link, parent|
|
23
|
+
click_link_within(parent, link)
|
24
|
+
end
|
25
|
+
|
26
|
+
When /^I fill in "([^\"]*)" with "([^\"]*)"$/ do |field, value|
|
27
|
+
fill_in(field, :with => value)
|
23
28
|
end
|
24
29
|
|
25
|
-
When /^I select "(
|
26
|
-
select(value, :from => field)
|
30
|
+
When /^I select "([^\"]*)" from "([^\"]*)"$/ do |value, field|
|
31
|
+
select(value, :from => field)
|
27
32
|
end
|
28
33
|
|
29
34
|
# Use this step in conjunction with Rail's datetime_select helper. For example:
|
30
|
-
# When I select "December 25, 2008 10:00" as the date and time
|
31
|
-
When /^I select "(
|
35
|
+
# When I select "December 25, 2008 10:00" as the date and time
|
36
|
+
When /^I select "([^\"]*)" as the date and time$/ do |time|
|
32
37
|
select_datetime(time)
|
33
38
|
end
|
34
39
|
|
35
|
-
# Use this step when using multiple datetime_select helpers on a page or
|
40
|
+
# Use this step when using multiple datetime_select helpers on a page or
|
36
41
|
# you want to specify which datetime to select. Given the following view:
|
37
|
-
#
|
38
|
-
#
|
39
|
-
#
|
40
|
-
#
|
42
|
+
# <%%= f.label :preferred %><br />
|
43
|
+
# <%%= f.datetime_select :preferred %>
|
44
|
+
# <%%= f.label :alternative %><br />
|
45
|
+
# <%%= f.datetime_select :alternative %>
|
41
46
|
# The following steps would fill out the form:
|
42
|
-
# When I select "November 23, 2004 11:20" as the "Preferred"
|
43
|
-
# And I select "November 25, 2004 10:30" as the "Alternative"
|
44
|
-
When /^I select "(
|
47
|
+
# When I select "November 23, 2004 11:20" as the "Preferred" date and time
|
48
|
+
# And I select "November 25, 2004 10:30" as the "Alternative" date and time
|
49
|
+
When /^I select "([^\"]*)" as the "([^\"]*)" date and time$/ do |datetime, datetime_label|
|
45
50
|
select_datetime(datetime, :from => datetime_label)
|
46
51
|
end
|
47
52
|
|
48
|
-
# Use this step in
|
53
|
+
# Use this step in conjunction with Rail's time_select helper. For example:
|
49
54
|
# When I select "2:20PM" as the time
|
50
55
|
# Note: Rail's default time helper provides 24-hour time-- not 12 hour time. Webrat
|
51
|
-
# will convert the 2:20PM to 14:20 and then select it.
|
52
|
-
When /^I select "(
|
56
|
+
# will convert the 2:20PM to 14:20 and then select it.
|
57
|
+
When /^I select "([^\"]*)" as the time$/ do |time|
|
53
58
|
select_time(time)
|
54
59
|
end
|
55
60
|
|
56
61
|
# Use this step when using multiple time_select helpers on a page or you want to
|
57
62
|
# specify the name of the time on the form. For example:
|
58
63
|
# When I select "7:30AM" as the "Gym" time
|
59
|
-
When /^I select "(
|
64
|
+
When /^I select "([^\"]*)" as the "([^\"]*)" time$/ do |time, time_label|
|
60
65
|
select_time(time, :from => time_label)
|
61
66
|
end
|
62
67
|
|
63
|
-
# Use this step in
|
68
|
+
# Use this step in conjunction with Rail's date_select helper. For example:
|
64
69
|
# When I select "February 20, 1981" as the date
|
65
|
-
When /^I select "(
|
70
|
+
When /^I select "([^\"]*)" as the date$/ do |date|
|
66
71
|
select_date(date)
|
67
72
|
end
|
68
73
|
|
69
74
|
# Use this step when using multiple date_select helpers on one page or
|
70
75
|
# you want to specify the name of the date on the form. For example:
|
71
76
|
# When I select "April 26, 1982" as the "Date of Birth" date
|
72
|
-
When /^I select "(
|
77
|
+
When /^I select "([^\"]*)" as the "([^\"]*)" date$/ do |date, date_label|
|
73
78
|
select_date(date, :from => date_label)
|
74
79
|
end
|
75
80
|
|
76
|
-
When /^I check "(
|
77
|
-
check(field)
|
81
|
+
When /^I check "([^\"]*)"$/ do |field|
|
82
|
+
check(field)
|
78
83
|
end
|
79
84
|
|
80
|
-
When /^I uncheck "(
|
81
|
-
uncheck(field)
|
85
|
+
When /^I uncheck "([^\"]*)"$/ do |field|
|
86
|
+
uncheck(field)
|
82
87
|
end
|
83
88
|
|
84
|
-
When /^I choose "(
|
89
|
+
When /^I choose "([^\"]*)"$/ do |field|
|
85
90
|
choose(field)
|
86
91
|
end
|
87
92
|
|
88
|
-
When /^I attach the file at "(
|
93
|
+
When /^I attach the file at "([^\"]*)" to "([^\"]*)"$/ do |path, field|
|
89
94
|
attach_file(field, path)
|
90
95
|
end
|
91
96
|
|
92
|
-
Then /^I should see "(
|
93
|
-
response.
|
97
|
+
Then /^I should see "([^\"]*)"$/ do |text|
|
98
|
+
response.should contain(text)
|
99
|
+
end
|
100
|
+
|
101
|
+
Then /^I should see \/([^\/]*)\/$/ do |regexp|
|
102
|
+
regexp = Regexp.new(regexp)
|
103
|
+
response.should contain(regexp)
|
104
|
+
end
|
105
|
+
|
106
|
+
Then /^I should not see "([^\"]*)"$/ do |text|
|
107
|
+
response.should_not contain(text)
|
94
108
|
end
|
95
109
|
|
96
|
-
Then /^I should not see
|
97
|
-
|
110
|
+
Then /^I should not see \/([^\/]*)\/$/ do |regexp|
|
111
|
+
regexp = Regexp.new(regexp)
|
112
|
+
response.should_not contain(regexp)
|
98
113
|
end
|
99
114
|
|
100
|
-
Then /^the "(
|
115
|
+
Then /^the "([^\"]*)" field should contain "([^\"]*)"$/ do |field, value|
|
116
|
+
field_labeled(field).value.should =~ /#{value}/
|
117
|
+
end
|
118
|
+
|
119
|
+
Then /^the "([^\"]*)" field should not contain "([^\"]*)"$/ do |field, value|
|
120
|
+
field_labeled(field).value.should_not =~ /#{value}/
|
121
|
+
end
|
122
|
+
|
123
|
+
Then /^the "([^\"]*)" checkbox should be checked$/ do |label|
|
101
124
|
field_labeled(label).should be_checked
|
102
125
|
end
|
103
126
|
|
127
|
+
Then /^the "([^\"]*)" checkbox should not be checked$/ do |label|
|
128
|
+
field_labeled(label).should_not be_checked
|
129
|
+
end
|
130
|
+
|
131
|
+
Then /^I should be on (.+)$/ do |page_name|
|
132
|
+
URI.parse(current_url).path.should == path_to(page_name)
|
133
|
+
end
|
104
134
|
|
135
|
+
Then /^show me the page$/ do
|
136
|
+
save_and_open_page
|
137
|
+
end
|
@@ -1,19 +1,30 @@
|
|
1
1
|
# Sets up the Rails environment for Cucumber
|
2
|
-
ENV["RAILS_ENV"]
|
2
|
+
ENV["RAILS_ENV"] ||= "test"
|
3
3
|
require File.expand_path(File.dirname(__FILE__) + '/../../config/environment')
|
4
4
|
require 'cucumber/rails/world'
|
5
|
+
|
6
|
+
# Comment out the next line if you don't want Cucumber Unicode support
|
7
|
+
require 'cucumber/formatter/unicode'
|
8
|
+
|
9
|
+
# Comment out the next line if you don't want transactions to
|
10
|
+
# open/roll back around each scenario
|
5
11
|
Cucumber::Rails.use_transactional_fixtures
|
6
12
|
|
13
|
+
# Comment out the next line if you want Rails' own error handling
|
14
|
+
# (e.g. rescue_action_in_public / rescue_responses / rescue_from)
|
15
|
+
Cucumber::Rails.bypass_rescue
|
16
|
+
|
7
17
|
require 'webrat'
|
8
|
-
require 'cucumber/
|
9
|
-
require 'webrat/core/matchers'
|
18
|
+
require 'cucumber/webrat/table_locator' # Lets you do table.diff!(table_at('#my_table').to_a)
|
10
19
|
|
11
20
|
Webrat.configure do |config|
|
12
21
|
config.mode = :rails
|
13
22
|
end
|
14
23
|
|
24
|
+
require 'cucumber/rails/rspec'
|
25
|
+
require 'webrat/core/matchers'
|
15
26
|
|
16
|
-
|
27
|
+
# email testing in cucumber
|
17
28
|
require File.expand_path(File.dirname(__FILE__) + '../../../../../lib/email_spec')
|
18
29
|
require 'email_spec/cucumber'
|
19
30
|
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module NavigationHelpers
|
2
|
+
# Maps a name to a path. Used by the
|
3
|
+
#
|
4
|
+
# When /^I go to (.+)$/ do |page_name|
|
5
|
+
#
|
6
|
+
# step definition in webrat_steps.rb
|
7
|
+
#
|
8
|
+
def path_to(page_name)
|
9
|
+
case page_name
|
10
|
+
|
11
|
+
when /the homepage/
|
12
|
+
'/'
|
13
|
+
|
14
|
+
else
|
15
|
+
raise "Can't find mapping from \"#{page_name}\" to a path.\n" +
|
16
|
+
"Now, go and add a mapping in #{__FILE__}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
World(NavigationHelpers)
|
@@ -1,7 +1,9 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
begin
|
3
3
|
load File.expand_path(File.dirname(__FILE__) + "/../vendor/plugins/cucumber/bin/cucumber")
|
4
|
-
rescue LoadError
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
rescue LoadError => e
|
5
|
+
raise unless e.to_s =~ /cucumber/
|
6
|
+
require 'rubygems'
|
7
|
+
require 'cucumber'
|
8
|
+
load Cucumber::BINARY
|
9
|
+
end
|
@@ -3,12 +3,12 @@ require File.dirname(__FILE__) + '/../spec_helper'
|
|
3
3
|
# These two example groups are specifying the exact same behavior. However, the documentation style is different
|
4
4
|
# and the value that each one provides is different with various trade-offs. Run these examples with the specdoc
|
5
5
|
# formatter to get an idea of how they differ.
|
6
|
-
|
7
6
|
# Example of documenting the behaviour explicitly and expressing the intent in the example's sentence.
|
8
7
|
describe "Signup Email" do
|
9
8
|
include EmailSpec::Helpers
|
10
9
|
include EmailSpec::Matchers
|
11
10
|
include ActionController::UrlWriter
|
11
|
+
default_url_options = {:host => 'example.com'}
|
12
12
|
|
13
13
|
before(:all) do
|
14
14
|
@email = UserMailer.create_signup("jojo@yahoo.com", "Jojo Binks")
|
@@ -25,7 +25,7 @@ describe "Signup Email" do
|
|
25
25
|
end
|
26
26
|
|
27
27
|
it "should contain a link to the confirmation page" do
|
28
|
-
@email.should have_body_text(/#{confirm_account_url}/)
|
28
|
+
@email.should have_body_text(/#{confirm_account_url(:host => 'example.com')}/)
|
29
29
|
end
|
30
30
|
|
31
31
|
it { should have_subject(/Account confirmation/) }
|
@@ -45,7 +45,7 @@ describe "Signup Email" do
|
|
45
45
|
|
46
46
|
subject { @email }
|
47
47
|
|
48
|
-
it { should have_body_text(/#{confirm_account_url}/) }
|
48
|
+
it { should have_body_text(/#{confirm_account_url(:host => 'example.com')}/) }
|
49
49
|
it { should have_subject(/Account confirmation/) }
|
50
50
|
|
51
51
|
describe "sent with email address of 'jojo@yahoo.com', and users name 'Jojo Binks'" do
|
@@ -6,7 +6,7 @@ require 'spec'
|
|
6
6
|
require 'spec/rails'
|
7
7
|
|
8
8
|
require File.expand_path(File.dirname(__FILE__) + "/model_factory.rb")
|
9
|
-
require (
|
9
|
+
require (RAILS_ROOT + '/../../lib/email_spec.rb')
|
10
10
|
|
11
11
|
Spec::Runner.configure do |config|
|
12
12
|
config.include(Fixjour)
|
@@ -1,9 +1,10 @@
|
|
1
|
-
#Commonly used email steps
|
1
|
+
# Commonly used email steps
|
2
2
|
#
|
3
3
|
# To add your own steps make a custom_email_steps.rb
|
4
4
|
# The provided methods are:
|
5
5
|
#
|
6
|
-
#
|
6
|
+
# last_email_address
|
7
|
+
# reset_mailer
|
7
8
|
# open_last_email
|
8
9
|
# visit_in_email
|
9
10
|
# unread_emails_for
|
@@ -12,6 +13,16 @@
|
|
12
13
|
# open_email
|
13
14
|
# read_emails_for
|
14
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.
|
15
26
|
|
16
27
|
module EmailHelpers
|
17
28
|
def current_email_address
|
@@ -21,63 +32,88 @@ module EmailHelpers
|
|
21
32
|
last_email_address || "example@example.com"
|
22
33
|
end
|
23
34
|
end
|
35
|
+
|
24
36
|
World(EmailHelpers)
|
25
37
|
|
26
|
-
#
|
38
|
+
#
|
39
|
+
# Reset the e-mail queue within a scenario.
|
27
40
|
# This is done automatically before each scenario.
|
41
|
+
#
|
42
|
+
|
28
43
|
Given /^(?:a clear email queue|no emails have been sent)$/ do
|
29
44
|
reset_mailer
|
30
45
|
end
|
31
46
|
|
32
|
-
#
|
33
|
-
|
34
|
-
|
35
|
-
end
|
47
|
+
#
|
48
|
+
# Check how many emails have been sent/received
|
49
|
+
#
|
36
50
|
|
37
|
-
|
38
|
-
|
51
|
+
Then /^(?:I|they|"([^"]*?)") should receive (an|no|\d+) emails?$/ do |address, amount|
|
52
|
+
unread_emails_for(address).size.should == parse_email_count(amount)
|
39
53
|
end
|
40
54
|
|
41
|
-
Then /^(?:I|they) should
|
42
|
-
|
43
|
-
unread_emails_for(current_email_address).size.should == amount.to_i
|
55
|
+
Then /^(?:I|they|"([^"]*?)") should have (an|no|\d+) emails?$/ do |address, amount|
|
56
|
+
mailbox_for(address).size.should == parse_email_count(amount)
|
44
57
|
end
|
45
58
|
|
46
|
-
|
47
|
-
|
59
|
+
# DEPRECATED
|
60
|
+
# The following methods are left in for backwards compatibility and
|
61
|
+
# should be removed by version 0.3.5.
|
62
|
+
Then /^(?:I|they|"([^"]*?)") should not receive an email$/ do |address|
|
63
|
+
email_spec_deprecate "The step 'I/they/[email] should not receive an email' is no longer supported.
|
64
|
+
Please use 'I/they/[email] should receive no emails' instead."
|
65
|
+
unread_emails_for(address).size.should == 0
|
48
66
|
end
|
49
67
|
|
50
|
-
|
51
|
-
|
52
|
-
|
68
|
+
#
|
69
|
+
# Accessing emails
|
70
|
+
#
|
71
|
+
|
72
|
+
# Opens the most recently received email
|
73
|
+
When /^(?:I|they|"([^"]*?)") opens? the email$/ do |address|
|
74
|
+
open_email(address)
|
53
75
|
end
|
54
76
|
|
55
|
-
|
56
|
-
|
77
|
+
When /^(?:I|they|"([^"]*?)") opens? the email with subject "([^"]*?)"$/ do |address, subject|
|
78
|
+
open_email(address, :with_subject => subject)
|
57
79
|
end
|
58
80
|
|
59
|
-
|
60
|
-
|
81
|
+
When /^(?:I|they|"([^"]*?)") opens? the email with text "([^"]*?)"$/ do |address, text|
|
82
|
+
open_email(address, :with_text => text)
|
61
83
|
end
|
62
84
|
|
63
|
-
|
85
|
+
#
|
86
|
+
# Inspect the Email Contents
|
87
|
+
#
|
88
|
+
|
89
|
+
Then /^(?:I|they) should see "([^"]*?)" in the email subject$/ do |text|
|
64
90
|
current_email.should have_subject(Regexp.new(text))
|
65
91
|
end
|
66
92
|
|
67
|
-
Then
|
93
|
+
Then /^(?:I|they) should see "([^"]*?)" in the email body$/ do |text|
|
68
94
|
current_email.body.should =~ Regexp.new(text)
|
69
95
|
end
|
70
96
|
|
71
|
-
|
72
|
-
|
97
|
+
# DEPRECATED
|
98
|
+
# The following methods are left in for backwards compatibility and
|
99
|
+
# should be removed by version 0.3.5.
|
100
|
+
Then /^(?:I|they) should see "([^"]*?)" in the subject$/ do |text|
|
101
|
+
email_spec_deprecate "The step 'I/they should see [text] in the subject' is no longer supported.
|
102
|
+
Please use 'I/they should see [text] in the email subject' instead."
|
103
|
+
current_email.should have_subject(Regexp.new(text))
|
73
104
|
end
|
74
|
-
|
75
|
-
|
76
|
-
|
105
|
+
Then /^(?:I|they) should see "([^"]*?)" in the email$/ do |text|
|
106
|
+
email_spec_deprecate "The step 'I/they should see [text] in the email' is no longer supported.
|
107
|
+
Please use 'I/they should see [text] in the email body' instead."
|
108
|
+
current_email.body.should =~ Regexp.new(text)
|
77
109
|
end
|
78
110
|
|
79
|
-
|
80
|
-
|
111
|
+
#
|
112
|
+
# Interact with Email Contents
|
113
|
+
#
|
114
|
+
|
115
|
+
When /^(?:I|they) follow "([^"]*?)" in the email$/ do |link|
|
116
|
+
visit_in_email(link)
|
81
117
|
end
|
82
118
|
|
83
119
|
When /^(?:I|they) click the first link in the email$/ do
|
@@ -13,7 +13,6 @@ module EmailSpec
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def mailbox_for(address)
|
16
|
-
address = AddressConverter.instance.convert(address)
|
17
16
|
ActionMailer::Base.deliveries.select { |m| m.to.include?(address) || (m.bcc && m.bcc.include?(address)) || (m.cc && m.cc.include?(address)) }
|
18
17
|
end
|
19
18
|
end
|
@@ -36,7 +35,6 @@ module EmailSpec
|
|
36
35
|
end
|
37
36
|
|
38
37
|
def mailbox_for(address)
|
39
|
-
address = AddressConverter.instance.convert(address)
|
40
38
|
Email.all.select { |email| email.to.include?(address) || email.bcc.include?(address) || email.cc.include?(address) }.map{ |email| parse_to_tmail(email) }
|
41
39
|
end
|
42
40
|
|