email_spec 0.3.1 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +21 -1
- data/README.rdoc +10 -10
- data/Rakefile +14 -6
- data/examples/rails_root/Rakefile +6 -0
- data/examples/rails_root/app/controllers/welcome_controller.rb +3 -0
- data/examples/rails_root/app/models/user_mailer.rb +7 -0
- data/examples/rails_root/app/views/user_mailer/newsletter.erb +8 -0
- data/examples/rails_root/app/views/welcome/newsletter.html.erb +0 -0
- data/examples/rails_root/config/environment.rb +1 -1
- data/examples/rails_root/config/environments/test.rb +6 -5
- data/examples/rails_root/config/routes.rb +2 -1
- data/examples/rails_root/db/migrate/20090908054656_create_delayed_jobs.rb +20 -0
- data/examples/rails_root/db/schema.rb +14 -1
- data/examples/rails_root/features/delayed_job.feature +13 -0
- data/examples/rails_root/features/step_definitions/user_steps.rb +1 -1
- data/examples/rails_root/features/step_definitions/webrat_steps.rb +4 -4
- data/examples/rails_root/features/support/env.rb +2 -2
- data/examples/rails_root/features/support/paths.rb +3 -0
- data/examples/rails_root/script/delayed_job +5 -0
- data/examples/sinatra/app.rb +33 -0
- data/examples/sinatra/features/errors.feature +32 -0
- data/examples/sinatra/features/example.feature +62 -0
- data/examples/{rails_root → sinatra}/features/step_definitions/email_steps.rb +2 -2
- data/examples/sinatra/features/step_definitions/user_steps.rb +26 -0
- data/examples/sinatra/features/step_definitions/webrat_steps.rb +137 -0
- data/examples/sinatra/features/support/env.rb +33 -0
- data/examples/sinatra/features/support/paths.rb +24 -0
- data/lib/email_spec.rb +3 -2
- data/lib/email_spec/address_converter.rb +2 -0
- data/lib/email_spec/background_processes.rb +31 -0
- data/lib/email_spec/cucumber.rb +7 -5
- data/lib/email_spec/deliveries.rb +24 -7
- data/lib/email_spec/matchers.rb +32 -1
- data/rails_generators/email_spec/templates/email_steps.rb +2 -2
- data/spec/email_spec/matchers_spec.rb +26 -2
- metadata +16 -7
- data/examples/rails_root/stories/all.rb +0 -4
- data/examples/rails_root/stories/helper.rb +0 -3
- data/examples/rails_root/vendor/plugins/email_spec/rails_generators/email_spec/email_spec_generator.rb +0 -17
- data/examples/rails_root/vendor/plugins/email_spec/rails_generators/email_spec/templates/email_steps.rb +0 -122
data/History.txt
CHANGED
@@ -3,13 +3,33 @@
|
|
3
3
|
=== New features
|
4
4
|
=== Bufixes
|
5
5
|
|
6
|
+
== 0.3.5 2009-09-30 The Pony Release!
|
7
|
+
|
8
|
+
=== New features
|
9
|
+
* Support for Pony mailer library. (Rob Holland)
|
10
|
+
|
11
|
+
== 0.3.4 2009-09-26
|
12
|
+
|
13
|
+
=== Bugfixes
|
14
|
+
* Typo and logic fixes for DeliverFrom matcher. (Yury Kotlyarov)
|
15
|
+
|
16
|
+
== 0.3.3 2009-09-18
|
17
|
+
|
18
|
+
=== New features
|
19
|
+
* DeliverFrom matcher. i.e. email.should deliver_from(blah) or email.should be_delivered_from(blah) (Diego Carrion)
|
20
|
+
|
21
|
+
== 0.3.2 2009-09-10
|
22
|
+
|
23
|
+
=== New features
|
24
|
+
* Support for delayed_job. (Kieran Pilkington)
|
25
|
+
|
6
26
|
== 0.3.1 2009-08-19
|
7
27
|
This release is a general refactoring of the steps and helpers.
|
8
28
|
The example rails app was also updated to use the lateset rails and webrat. It also takes advantages
|
9
29
|
and the newer step definistions including the new third-person forms.
|
10
30
|
|
11
31
|
Some of the generated steps are being removed in favor of some of the newer ones. The older ones
|
12
|
-
will remain until 0.
|
32
|
+
will remain until 0.4.0 but will issue deprecation warnings.
|
13
33
|
|
14
34
|
Big shoutout to Kieran Pilkington who did the majority of work for this release.
|
15
35
|
|
data/README.rdoc
CHANGED
@@ -8,12 +8,12 @@ A collection of RSpec matchers and Cucumber steps to make testing emails go smoo
|
|
8
8
|
script/plugin install git://github.com/bmabey/email-spec.git
|
9
9
|
|
10
10
|
=== Gem Setup
|
11
|
-
|
11
|
+
|
12
12
|
gem install bmabey-email_spec
|
13
13
|
|
14
14
|
# config/environments/test.rb
|
15
15
|
config.gem 'bmabey-email_spec', :lib => 'email_spec'
|
16
|
-
|
16
|
+
|
17
17
|
=== Cucumber
|
18
18
|
|
19
19
|
To use the steps in features put the following in your env.rb:
|
@@ -21,7 +21,7 @@ To use the steps in features put the following in your env.rb:
|
|
21
21
|
# Make sure this require is after you require cucumber/rails/world.
|
22
22
|
require 'email_spec/cucumber'
|
23
23
|
|
24
|
-
This will load all the helpers that the steps rely on.
|
24
|
+
This will load all the helpers that the steps rely on.
|
25
25
|
It will also add a Before hook for Cucumber so that emails are cleared at the start of each scenario.
|
26
26
|
|
27
27
|
Then:
|
@@ -32,7 +32,7 @@ This will give you a bunch of steps to get started with in step_definitions/emai
|
|
32
32
|
|
33
33
|
=== RSpec
|
34
34
|
|
35
|
-
|
35
|
+
First you need to require the helpers and matchers in your spec_helper.rb like so:
|
36
36
|
|
37
37
|
require "email_spec/helpers"
|
38
38
|
require "email_spec/matchers"
|
@@ -95,11 +95,11 @@ For more examples, check out examples/rails_root in the source for a small examp
|
|
95
95
|
before(:all) do
|
96
96
|
@email = UserMailer.create_signup("jojo@yahoo.com", "Jojo Binks")
|
97
97
|
end
|
98
|
-
|
98
|
+
|
99
99
|
it "should be set to be delivered to the email passed in" do
|
100
100
|
@email.should deliver_to("jojo@yahoo.com")
|
101
101
|
end
|
102
|
-
|
102
|
+
|
103
103
|
it "should contain the user's message in the mail body" do
|
104
104
|
@email.should have_text(/Jojo Binks/)
|
105
105
|
end
|
@@ -107,14 +107,14 @@ For more examples, check out examples/rails_root in the source for a small examp
|
|
107
107
|
it "should contain a link to the confirmation link" do
|
108
108
|
@email.should have_text(/#{confirm_account_url}/)
|
109
109
|
end
|
110
|
-
|
110
|
+
|
111
111
|
it "should have the correct subject" do
|
112
112
|
@email.should have_subject(/Account confirmation/)
|
113
113
|
end
|
114
|
-
|
114
|
+
|
115
115
|
end
|
116
|
-
|
117
|
-
==== Using the helpers when not testing in isolation ====
|
116
|
+
|
117
|
+
==== Using the helpers when not testing in isolation ====
|
118
118
|
|
119
119
|
Don't. :) Seriously, if you do just take a look at the helpers and use them as you wish.
|
120
120
|
|
data/Rakefile
CHANGED
@@ -25,12 +25,14 @@ rescue LoadError
|
|
25
25
|
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
26
26
|
end
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
28
|
+
# TODO: Maybe use geminstaller instead?
|
29
|
+
%w[collectiveidea-delayed_job fixjour pony sinatra rack-test].each do |gem_name|
|
30
|
+
begin
|
31
|
+
gem gem_name
|
32
|
+
rescue Gem::LoadError
|
33
|
+
puts "Installing #{gem_name} for the example rails app..."
|
34
|
+
puts `gem install #{gem_name} --no-rdoc --no-ri`
|
35
|
+
end
|
34
36
|
end
|
35
37
|
|
36
38
|
begin
|
@@ -60,8 +62,14 @@ task :default => [:features, :spec, 'example_app:spec']
|
|
60
62
|
|
61
63
|
desc "Cleans the project of any tmp file that should not be included in the gemspec."
|
62
64
|
task :clean do
|
65
|
+
FileUtils.rm_f('examples/rails_root/features/step_definitions/email_steps.rb')
|
66
|
+
FileUtils.rm_rf('examples/rails_root/log')
|
67
|
+
FileUtils.rm_rf('examples/rails_root/vendor')
|
63
68
|
%w[*.sqlite3 *.log].each do |pattern|
|
64
69
|
`find . -name "#{pattern}" -delete`
|
65
70
|
end
|
66
71
|
end
|
67
72
|
|
73
|
+
desc "Cleans the dir and builds the gem"
|
74
|
+
task :prep => [:clean, :gemspec, :build]
|
75
|
+
|
File without changes
|
@@ -5,7 +5,7 @@
|
|
5
5
|
# ENV['RAILS_ENV'] ||= 'production'
|
6
6
|
|
7
7
|
# Specifies gem version of Rails to use when vendor/rails is not present
|
8
|
-
RAILS_GEM_VERSION = '2.3.
|
8
|
+
RAILS_GEM_VERSION = '2.3.4' unless defined? RAILS_GEM_VERSION
|
9
9
|
|
10
10
|
# Bootstrap the Rails environment, frameworks, and default configuration
|
11
11
|
require File.join(File.dirname(__FILE__), 'boot')
|
@@ -22,8 +22,9 @@ config.action_controller.allow_forgery_protection = false
|
|
22
22
|
config.action_mailer.delivery_method = :test
|
23
23
|
config.action_mailer.default_url_options = { :host => "example.com" }
|
24
24
|
|
25
|
-
config.gem 'cucumber',
|
26
|
-
config.gem 'webrat',
|
27
|
-
config.gem 'rspec',
|
28
|
-
config.gem 'rspec-rails',
|
29
|
-
config.gem 'fixjour',
|
25
|
+
config.gem 'cucumber', :lib => false
|
26
|
+
config.gem 'webrat', :lib => false
|
27
|
+
config.gem 'rspec', :lib => false
|
28
|
+
config.gem 'rspec-rails', :lib => 'spec/rails'
|
29
|
+
config.gem 'fixjour', :lib => 'fixjour'
|
30
|
+
config.gem 'collectiveidea-delayed_job', :lib => 'delayed_job', :source => 'http://gems.github.com'
|
@@ -17,7 +17,7 @@ ActionController::Routing::Routes.draw do |map|
|
|
17
17
|
|
18
18
|
# Sample resource route with sub-resources:
|
19
19
|
# map.resources :products, :has_many => [ :comments, :sales ], :has_one => :seller
|
20
|
-
|
20
|
+
|
21
21
|
# Sample resource route with more complex sub-resources
|
22
22
|
# map.resources :products do |products|
|
23
23
|
# products.resources :comments
|
@@ -33,6 +33,7 @@ ActionController::Routing::Routes.draw do |map|
|
|
33
33
|
# You can have the root of your site routed with map.root -- just remember to delete public/index.html.
|
34
34
|
map.root :controller => "welcome", :action => "index"
|
35
35
|
map.confirm_account "/confirm", :controller => "welcome", :action => "confirm"
|
36
|
+
map.request_newsletter "/newsletter", :controller => "welcome", :action => "newsletter"
|
36
37
|
# See how all your routes lay out with "rake routes"
|
37
38
|
|
38
39
|
# Install the default routes as the lowest priority.
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class CreateDelayedJobs < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :delayed_jobs, :force => true do |table|
|
4
|
+
table.integer :priority, :default => 0 # Allows some jobs to jump to the front of the queue
|
5
|
+
table.integer :attempts, :default => 0 # Provides for retries, but still fail eventually.
|
6
|
+
table.text :handler # YAML-encoded string of the object that will do work
|
7
|
+
table.text :last_error # reason for last failure (See Note below)
|
8
|
+
table.datetime :run_at # When to run. Could be Time.now for immediately, or sometime in the future.
|
9
|
+
table.datetime :locked_at # Set when a client is working on this object
|
10
|
+
table.datetime :failed_at # Set when all retries have failed (actually, by default, the record is deleted instead)
|
11
|
+
table.string :locked_by # Who is working on this object (if locked)
|
12
|
+
table.timestamps
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.down
|
18
|
+
drop_table :delayed_jobs
|
19
|
+
end
|
20
|
+
end
|
@@ -9,7 +9,20 @@
|
|
9
9
|
#
|
10
10
|
# It's strongly recommended to check this file into your version control system.
|
11
11
|
|
12
|
-
ActiveRecord::Schema.define(:version =>
|
12
|
+
ActiveRecord::Schema.define(:version => 20090908054656) do
|
13
|
+
|
14
|
+
create_table "delayed_jobs", :force => true do |t|
|
15
|
+
t.integer "priority", :default => 0
|
16
|
+
t.integer "attempts", :default => 0
|
17
|
+
t.text "handler"
|
18
|
+
t.text "last_error"
|
19
|
+
t.datetime "run_at"
|
20
|
+
t.datetime "locked_at"
|
21
|
+
t.datetime "failed_at"
|
22
|
+
t.string "locked_by"
|
23
|
+
t.datetime "created_at"
|
24
|
+
t.datetime "updated_at"
|
25
|
+
end
|
13
26
|
|
14
27
|
create_table "users", :force => true do |t|
|
15
28
|
t.string "email"
|
@@ -0,0 +1,13 @@
|
|
1
|
+
Feature: Delayed Job support
|
2
|
+
In order for developers using delayed_job to test emails
|
3
|
+
I want to be able to provide a compatibility layer, which
|
4
|
+
should run all delayed jobs before checking email boxes
|
5
|
+
In order to populate deliveries done via send_later
|
6
|
+
|
7
|
+
Scenario: Newsletter
|
8
|
+
Given no emails have been sent
|
9
|
+
And I go to request a newsletter
|
10
|
+
Then I should receive an email
|
11
|
+
And I should have 1 email
|
12
|
+
When I open the email
|
13
|
+
Then I should see "Newsletter sent" in the email subject
|
@@ -17,7 +17,7 @@ Then /^(?:I|they) should receive an email with a link to a confirmation page$/ d
|
|
17
17
|
current_email.should have_body_text('Joe Someone')
|
18
18
|
|
19
19
|
click_email_link_matching /confirm/
|
20
|
-
|
20
|
+
response_body.should contain("Confirm your new account")
|
21
21
|
end
|
22
22
|
|
23
23
|
# Basically aliases "I should see [text]", but for third person
|
@@ -95,21 +95,21 @@ When /^I attach the file at "([^\"]*)" to "([^\"]*)"$/ do |path, field|
|
|
95
95
|
end
|
96
96
|
|
97
97
|
Then /^I should see "([^\"]*)"$/ do |text|
|
98
|
-
|
98
|
+
response_body.should contain(text)
|
99
99
|
end
|
100
100
|
|
101
101
|
Then /^I should see \/([^\/]*)\/$/ do |regexp|
|
102
102
|
regexp = Regexp.new(regexp)
|
103
|
-
|
103
|
+
response_body.should contain(regexp)
|
104
104
|
end
|
105
105
|
|
106
106
|
Then /^I should not see "([^\"]*)"$/ do |text|
|
107
|
-
|
107
|
+
response_body.should_not contain(text)
|
108
108
|
end
|
109
109
|
|
110
110
|
Then /^I should not see \/([^\/]*)\/$/ do |regexp|
|
111
111
|
regexp = Regexp.new(regexp)
|
112
|
-
|
112
|
+
response_body.should_not contain(regexp)
|
113
113
|
end
|
114
114
|
|
115
115
|
Then /^the "([^\"]*)" field should contain "([^\"]*)"$/ do |field, value|
|
@@ -8,11 +8,11 @@ require 'cucumber/formatter/unicode'
|
|
8
8
|
|
9
9
|
# Comment out the next line if you don't want transactions to
|
10
10
|
# open/roll back around each scenario
|
11
|
-
Cucumber::Rails.use_transactional_fixtures
|
11
|
+
#Cucumber::Rails.use_transactional_fixtures
|
12
12
|
|
13
13
|
# Comment out the next line if you want Rails' own error handling
|
14
14
|
# (e.g. rescue_action_in_public / rescue_responses / rescue_from)
|
15
|
-
Cucumber::Rails.bypass_rescue
|
15
|
+
#Cucumber::Rails.bypass_rescue
|
16
16
|
|
17
17
|
require 'webrat'
|
18
18
|
require 'cucumber/webrat/table_locator' # Lets you do table.diff!(table_at('#my_table').to_a)
|
@@ -11,6 +11,9 @@ module NavigationHelpers
|
|
11
11
|
when /the homepage/
|
12
12
|
'/'
|
13
13
|
|
14
|
+
when /request a newsletter/
|
15
|
+
request_newsletter_url('Name' => 'Joe Someone', 'Email' => 'example@example.com')
|
16
|
+
|
14
17
|
else
|
15
18
|
raise "Can't find mapping from \"#{page_name}\" to a path.\n" +
|
16
19
|
"Now, go and add a mapping in #{__FILE__}"
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'sinatra'
|
2
|
+
require 'pony'
|
3
|
+
|
4
|
+
get '/' do
|
5
|
+
<<-EOHTML
|
6
|
+
<form method="post" action="/signup">
|
7
|
+
<label for="Name">Name</label>
|
8
|
+
<input type="text" id="Name" name="user[name]">
|
9
|
+
<label for="Email">Email</label>
|
10
|
+
<input type="text" id="Email" name="user[email]">
|
11
|
+
<input type="submit" value="Sign up">
|
12
|
+
</form>
|
13
|
+
EOHTML
|
14
|
+
end
|
15
|
+
|
16
|
+
post '/signup' do
|
17
|
+
user = params[:user]
|
18
|
+
body = <<-EOHTML
|
19
|
+
Hello #{user['name']}!
|
20
|
+
|
21
|
+
<a href="http://www.example.com/confirm">Click here to confirm your account!</a>
|
22
|
+
EOHTML
|
23
|
+
Pony.mail(:from => 'admin@example.com',
|
24
|
+
:to => user['email'],
|
25
|
+
:subject => 'Account confirmation',
|
26
|
+
:body => body
|
27
|
+
)
|
28
|
+
'Thanks! Go check your email!'
|
29
|
+
end
|
30
|
+
|
31
|
+
get '/confirm' do
|
32
|
+
'Confirm your new account!'
|
33
|
+
end
|
@@ -0,0 +1,32 @@
|
|
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 text
|
18
|
+
Then I should receive an email
|
19
|
+
When "example@example.com" opens the email with text "no email"
|
20
|
+
|
21
|
+
Scenario: I fail to receive an email with the expected link
|
22
|
+
Then I should receive an email
|
23
|
+
When I open the email
|
24
|
+
When I follow "link that doesn't exist" in the email
|
25
|
+
|
26
|
+
Scenario: I attempt to operate on an email that is not opened
|
27
|
+
Then I should receive an email
|
28
|
+
When I follow "confirm" in the email
|
29
|
+
|
30
|
+
Scenario: I attempt to check out an unopened email
|
31
|
+
Then I should see "confirm" in the email body
|
32
|
+
And I should see "Account confirmation" in the email subject
|
@@ -0,0 +1,62 @@
|
|
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 two 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
|
+
When I follow "Click here to confirm your account!" in the email
|
34
|
+
Then I should see "Confirm your new account"
|
35
|
+
|
36
|
+
And "foo@bar.com" should have no emails
|
37
|
+
|
38
|
+
Scenario: Third person signup (emails sent to others) with two ways of opening email
|
39
|
+
Then "foo@bar.com" should have no emails
|
40
|
+
And "example@example.com" should receive an email
|
41
|
+
And "example@example.com" should have 1 email
|
42
|
+
|
43
|
+
# Opening email #1
|
44
|
+
When they open the email
|
45
|
+
Then they should see "Account confirmation" in the email subject
|
46
|
+
And they should see "Joe Someone" in the email body
|
47
|
+
And they should see "confirm" in the email body
|
48
|
+
|
49
|
+
# Opening email #2
|
50
|
+
When "example@example.com" opens the email with subject "Account confirmation"
|
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
|
+
When they follow "Click here to confirm your account!" in the email
|
56
|
+
Then they should see "Confirm your new account"
|
57
|
+
|
58
|
+
Scenario: Declarative First Person signup
|
59
|
+
Then I should receive an email with a link to a confirmation page
|
60
|
+
|
61
|
+
Scenario: Declarative First Person signup
|
62
|
+
Then they should receive an email with a link to a confirmation page
|
@@ -58,7 +58,7 @@ end
|
|
58
58
|
|
59
59
|
# DEPRECATED
|
60
60
|
# The following methods are left in for backwards compatibility and
|
61
|
-
# should be removed by version 0.
|
61
|
+
# should be removed by version 0.4.0
|
62
62
|
Then /^(?:I|they|"([^"]*?)") should not receive an email$/ do |address|
|
63
63
|
email_spec_deprecate "The step 'I/they/[email] should not receive an email' is no longer supported.
|
64
64
|
Please use 'I/they/[email] should receive no emails' instead."
|
@@ -96,7 +96,7 @@ end
|
|
96
96
|
|
97
97
|
# DEPRECATED
|
98
98
|
# The following methods are left in for backwards compatibility and
|
99
|
-
# should be removed by version 0.
|
99
|
+
# should be removed by version 0.4.0.
|
100
100
|
Then /^(?:I|they) should see "([^"]*?)" in the subject$/ do |text|
|
101
101
|
email_spec_deprecate "The step 'I/they should see [text] in the subject' is no longer supported.
|
102
102
|
Please use 'I/they should see [text] in the email subject' instead."
|
@@ -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
|
9
|
+
end
|
10
|
+
|
11
|
+
Then /^(?:I|they) should receive an email with a link to a confirmation page$/ do
|
12
|
+
unread_emails_for(current_email_address).size.should == 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
|
+
current_email.should have_subject(/Account confirmation/)
|
17
|
+
current_email.should have_body_text('Joe Someone')
|
18
|
+
|
19
|
+
click_email_link_matching /confirm/
|
20
|
+
response_body.should contain("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
|
+
Then "I should see \"#{text}\""
|
26
|
+
end
|
@@ -0,0 +1,137 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
|
2
|
+
|
3
|
+
# Commonly used webrat steps
|
4
|
+
# http://github.com/brynary/webrat
|
5
|
+
|
6
|
+
Given /^I am on (.+)$/ do |page_name|
|
7
|
+
visit path_to(page_name)
|
8
|
+
end
|
9
|
+
|
10
|
+
When /^I go to (.+)$/ do |page_name|
|
11
|
+
visit path_to(page_name)
|
12
|
+
end
|
13
|
+
|
14
|
+
When /^I press "([^\"]*)"$/ do |button|
|
15
|
+
click_button(button)
|
16
|
+
end
|
17
|
+
|
18
|
+
When /^I follow "([^\"]*)"$/ do |link|
|
19
|
+
click_link(link)
|
20
|
+
end
|
21
|
+
|
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)
|
28
|
+
end
|
29
|
+
|
30
|
+
When /^I select "([^\"]*)" from "([^\"]*)"$/ do |value, field|
|
31
|
+
select(value, :from => field)
|
32
|
+
end
|
33
|
+
|
34
|
+
# Use this step in conjunction with Rail's datetime_select helper. For example:
|
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|
|
37
|
+
select_datetime(time)
|
38
|
+
end
|
39
|
+
|
40
|
+
# Use this step when using multiple datetime_select helpers on a page or
|
41
|
+
# you want to specify which datetime to select. Given the following view:
|
42
|
+
# <%%= f.label :preferred %><br />
|
43
|
+
# <%%= f.datetime_select :preferred %>
|
44
|
+
# <%%= f.label :alternative %><br />
|
45
|
+
# <%%= f.datetime_select :alternative %>
|
46
|
+
# The following steps would fill out the form:
|
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|
|
50
|
+
select_datetime(datetime, :from => datetime_label)
|
51
|
+
end
|
52
|
+
|
53
|
+
# Use this step in conjunction with Rail's time_select helper. For example:
|
54
|
+
# When I select "2:20PM" as the time
|
55
|
+
# Note: Rail's default time helper provides 24-hour time-- not 12 hour time. Webrat
|
56
|
+
# will convert the 2:20PM to 14:20 and then select it.
|
57
|
+
When /^I select "([^\"]*)" as the time$/ do |time|
|
58
|
+
select_time(time)
|
59
|
+
end
|
60
|
+
|
61
|
+
# Use this step when using multiple time_select helpers on a page or you want to
|
62
|
+
# specify the name of the time on the form. For example:
|
63
|
+
# When I select "7:30AM" as the "Gym" time
|
64
|
+
When /^I select "([^\"]*)" as the "([^\"]*)" time$/ do |time, time_label|
|
65
|
+
select_time(time, :from => time_label)
|
66
|
+
end
|
67
|
+
|
68
|
+
# Use this step in conjunction with Rail's date_select helper. For example:
|
69
|
+
# When I select "February 20, 1981" as the date
|
70
|
+
When /^I select "([^\"]*)" as the date$/ do |date|
|
71
|
+
select_date(date)
|
72
|
+
end
|
73
|
+
|
74
|
+
# Use this step when using multiple date_select helpers on one page or
|
75
|
+
# you want to specify the name of the date on the form. For example:
|
76
|
+
# When I select "April 26, 1982" as the "Date of Birth" date
|
77
|
+
When /^I select "([^\"]*)" as the "([^\"]*)" date$/ do |date, date_label|
|
78
|
+
select_date(date, :from => date_label)
|
79
|
+
end
|
80
|
+
|
81
|
+
When /^I check "([^\"]*)"$/ do |field|
|
82
|
+
check(field)
|
83
|
+
end
|
84
|
+
|
85
|
+
When /^I uncheck "([^\"]*)"$/ do |field|
|
86
|
+
uncheck(field)
|
87
|
+
end
|
88
|
+
|
89
|
+
When /^I choose "([^\"]*)"$/ do |field|
|
90
|
+
choose(field)
|
91
|
+
end
|
92
|
+
|
93
|
+
When /^I attach the file at "([^\"]*)" to "([^\"]*)"$/ do |path, field|
|
94
|
+
attach_file(field, path)
|
95
|
+
end
|
96
|
+
|
97
|
+
Then /^I should see "([^\"]*)"$/ do |text|
|
98
|
+
response_body.should contain(text)
|
99
|
+
end
|
100
|
+
|
101
|
+
Then /^I should see \/([^\/]*)\/$/ do |regexp|
|
102
|
+
regexp = Regexp.new(regexp)
|
103
|
+
response_body.should contain(regexp)
|
104
|
+
end
|
105
|
+
|
106
|
+
Then /^I should not see "([^\"]*)"$/ do |text|
|
107
|
+
response_body.should_not contain(text)
|
108
|
+
end
|
109
|
+
|
110
|
+
Then /^I should not see \/([^\/]*)\/$/ do |regexp|
|
111
|
+
regexp = Regexp.new(regexp)
|
112
|
+
response_body.should_not contain(regexp)
|
113
|
+
end
|
114
|
+
|
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|
|
124
|
+
field_labeled(label).should be_checked
|
125
|
+
end
|
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
|
134
|
+
|
135
|
+
Then /^show me the page$/ do
|
136
|
+
save_and_open_page
|
137
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# Sets up the Rails environment for Cucumber
|
2
|
+
ENV["RACK_ENV"] ||= "test"
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../app.rb')
|
4
|
+
|
5
|
+
# Comment out the next line if you don't want Cucumber Unicode support
|
6
|
+
require 'cucumber/formatter/unicode'
|
7
|
+
|
8
|
+
require 'rack/test'
|
9
|
+
require 'webrat'
|
10
|
+
require 'cucumber/webrat/table_locator' # Lets you do table.diff!(table_at('#my_table').to_a)
|
11
|
+
|
12
|
+
Webrat.configure do |config|
|
13
|
+
config.mode = :rack
|
14
|
+
end
|
15
|
+
|
16
|
+
require 'webrat/core/matchers'
|
17
|
+
|
18
|
+
# email testing in cucumber
|
19
|
+
require 'activesupport'
|
20
|
+
require File.expand_path(File.dirname(__FILE__) + '../../../../../lib/email_spec')
|
21
|
+
require 'email_spec/cucumber'
|
22
|
+
|
23
|
+
class AppWorld
|
24
|
+
include Rack::Test::Methods
|
25
|
+
include Webrat::Methods
|
26
|
+
include Webrat::Matchers
|
27
|
+
|
28
|
+
def app
|
29
|
+
Sinatra::Application.new
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
World { AppWorld.new }
|
@@ -0,0 +1,24 @@
|
|
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
|
+
when /request a newsletter/
|
15
|
+
"/newsletter/Joe Someone/example@example.com"
|
16
|
+
|
17
|
+
else
|
18
|
+
raise "Can't find mapping from \"#{page_name}\" to a path.\n" +
|
19
|
+
"Now, go and add a mapping in #{__FILE__}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
World(NavigationHelpers)
|
data/lib/email_spec.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
-
unless defined?(ActionMailer)
|
2
|
-
Kernel.warn("
|
1
|
+
unless defined?(Pony) or defined?(ActionMailer)
|
2
|
+
Kernel.warn("Neither Pony nor ActionMailer appear to be loaded so email-spec is requiring ActionMailer.")
|
3
3
|
require 'actionmailer'
|
4
4
|
end
|
5
5
|
|
6
6
|
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__))) unless $LOAD_PATH.include?(File.expand_path(File.dirname(__FILE__)))
|
7
7
|
|
8
|
+
require 'email_spec/background_processes'
|
8
9
|
require 'email_spec/deliveries'
|
9
10
|
require 'email_spec/address_converter'
|
10
11
|
require 'email_spec/email_viewer'
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module EmailSpec
|
2
|
+
module BackgroundProcesses
|
3
|
+
module DelayedJob
|
4
|
+
def all_emails
|
5
|
+
Delayed::Job.work_off
|
6
|
+
super
|
7
|
+
end
|
8
|
+
|
9
|
+
def last_email_sent
|
10
|
+
Delayed::Job.work_off
|
11
|
+
super
|
12
|
+
end
|
13
|
+
|
14
|
+
def reset_mailer
|
15
|
+
Delayed::Job.work_off
|
16
|
+
super
|
17
|
+
end
|
18
|
+
|
19
|
+
def mailbox_for(address)
|
20
|
+
Delayed::Job.work_off
|
21
|
+
super
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
module Compatibility
|
26
|
+
if defined?(Delayed)
|
27
|
+
include EmailSpec::BackgroundProcesses::DelayedJob
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/email_spec/cucumber.rb
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
# require this in your env.rb file after you require cucumber/rails/world
|
2
2
|
|
3
3
|
# Global Setup
|
4
|
-
|
5
|
-
ActionMailer::Base.
|
4
|
+
if defined?(ActionMailer)
|
5
|
+
ActionMailer::Base.delivery_method = :test unless ActionMailer::Base.delivery_method == :activerecord
|
6
|
+
ActionMailer::Base.perform_deliveries = true
|
6
7
|
|
7
|
-
Before do
|
8
|
-
|
9
|
-
|
8
|
+
Before do
|
9
|
+
# Scenario setup
|
10
|
+
ActionMailer::Base.deliveries.clear if ActionMailer::Base.delivery_method == :test
|
11
|
+
end
|
10
12
|
end
|
11
13
|
|
12
14
|
After do
|
@@ -1,19 +1,19 @@
|
|
1
1
|
module EmailSpec
|
2
|
-
module
|
2
|
+
module MailerDeliveries
|
3
3
|
def all_emails
|
4
|
-
|
4
|
+
mailer.deliveries
|
5
5
|
end
|
6
6
|
|
7
7
|
def last_email_sent
|
8
|
-
|
8
|
+
mailer.deliveries.last || raise("No email has been sent!")
|
9
9
|
end
|
10
10
|
|
11
11
|
def reset_mailer
|
12
|
-
|
12
|
+
mailer.deliveries.clear
|
13
13
|
end
|
14
14
|
|
15
15
|
def mailbox_for(address)
|
16
|
-
|
16
|
+
mailer.deliveries.select { |m| m.to.include?(address) || (m.bcc && m.bcc.include?(address)) || (m.cc && m.cc.include?(address)) }
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
@@ -43,12 +43,29 @@ module EmailSpec
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
+
if defined?(Pony)
|
47
|
+
module ::Pony
|
48
|
+
def self.deliveries
|
49
|
+
@deliveries ||= []
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.mail(options)
|
53
|
+
deliveries << build_tmail(options)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
46
58
|
module Deliveries
|
47
|
-
if
|
59
|
+
if defined?(Pony)
|
60
|
+
def mailer; Pony; end
|
61
|
+
include EmailSpec::MailerDeliveries
|
62
|
+
elsif ActionMailer::Base.delivery_method == :activerecord
|
48
63
|
include EmailSpec::ARMailerDeliveries
|
49
64
|
else
|
50
|
-
|
65
|
+
def mailer; ActionMailer::Base; end
|
66
|
+
include EmailSpec::MailerDeliveries
|
51
67
|
end
|
68
|
+
include EmailSpec::BackgroundProcesses::Compatibility
|
52
69
|
end
|
53
70
|
end
|
54
71
|
|
data/lib/email_spec/matchers.rb
CHANGED
@@ -23,7 +23,7 @@ module EmailSpec
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def failure_message
|
26
|
-
"expected #{@email.inspect} to deliver to #{@expected_email_addresses.inspect}, but it
|
26
|
+
"expected #{@email.inspect} to deliver to #{@expected_email_addresses.inspect}, but it delivered to #{@actual_recipients.inspect}"
|
27
27
|
end
|
28
28
|
|
29
29
|
def negative_failure_message
|
@@ -37,6 +37,37 @@ module EmailSpec
|
|
37
37
|
|
38
38
|
alias :be_delivered_to :deliver_to
|
39
39
|
|
40
|
+
class DeliverFrom
|
41
|
+
|
42
|
+
def initialize(email)
|
43
|
+
@expected_email_addresses = email
|
44
|
+
end
|
45
|
+
|
46
|
+
def description
|
47
|
+
"be delivered from #{@expected_email_addresses.inspect}"
|
48
|
+
end
|
49
|
+
|
50
|
+
def matches?(email)
|
51
|
+
@email = email
|
52
|
+
@actual_sender = (email.from || []).first
|
53
|
+
@actual_sender.eql? @expected_email_addresses
|
54
|
+
end
|
55
|
+
|
56
|
+
def failure_message
|
57
|
+
"expected #{@email.inspect} to deliver from #{@expected_email_addresses.inspect}, but it delivered from #{@actual_sender.inspect}"
|
58
|
+
end
|
59
|
+
|
60
|
+
def negative_failure_message
|
61
|
+
"expected #{@email.inspect} not to deliver from #{@expected_email_addresses.inspect}, but it did"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def deliver_from(email)
|
66
|
+
DeliverFrom.new(email)
|
67
|
+
end
|
68
|
+
|
69
|
+
alias :be_delivered_from :deliver_from
|
70
|
+
|
40
71
|
class BccTo
|
41
72
|
|
42
73
|
def initialize(expected_email_addresses_or_objects_that_respond_to_email)
|
@@ -58,7 +58,7 @@ end
|
|
58
58
|
|
59
59
|
# DEPRECATED
|
60
60
|
# The following methods are left in for backwards compatibility and
|
61
|
-
# should be removed by version 0.
|
61
|
+
# should be removed by version 0.4.0
|
62
62
|
Then /^(?:I|they|"([^"]*?)") should not receive an email$/ do |address|
|
63
63
|
email_spec_deprecate "The step 'I/they/[email] should not receive an email' is no longer supported.
|
64
64
|
Please use 'I/they/[email] should receive no emails' instead."
|
@@ -96,7 +96,7 @@ end
|
|
96
96
|
|
97
97
|
# DEPRECATED
|
98
98
|
# The following methods are left in for backwards compatibility and
|
99
|
-
# should be removed by version 0.
|
99
|
+
# should be removed by version 0.4.0.
|
100
100
|
Then /^(?:I|they) should see "([^"]*?)" in the subject$/ do |text|
|
101
101
|
email_spec_deprecate "The step 'I/they should see [text] in the subject' is no longer supported.
|
102
102
|
Please use 'I/they should see [text] in the email subject' instead."
|
@@ -45,7 +45,6 @@ describe EmailSpec::Matchers do
|
|
45
45
|
end
|
46
46
|
|
47
47
|
describe "#deliver_to" do
|
48
|
-
|
49
48
|
it "should match when the email is set to deliver to the specidied address" do
|
50
49
|
email = mock_email(:to => "jimmy_bean@yahoo.com")
|
51
50
|
|
@@ -72,6 +71,31 @@ describe EmailSpec::Matchers do
|
|
72
71
|
deliver_to(user).should match(email)
|
73
72
|
end
|
74
73
|
|
74
|
+
it "should give correct failure message when the email is not set to deliver to the specified address" do
|
75
|
+
matcher = deliver_to("jimmy_bean@yahoo.com")
|
76
|
+
matcher.matches?(mock_email(:inspect => 'email', :to => 'freddy_noe@yahoo.com'))
|
77
|
+
matcher.failure_message.should == %{expected email to deliver to ["jimmy_bean@yahoo.com"], but it delivered to ["freddy_noe@yahoo.com"]}
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
describe "#deliver_from" do
|
83
|
+
it "should match when the email is set to deliver from the specidied address" do
|
84
|
+
email = mock_email(:from => ["jimmy_bean@yahoo.com"])
|
85
|
+
deliver_from("jimmy_bean@yahoo.com").should match(email)
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should not match when the email is not set to deliver from the specified address" do
|
89
|
+
email = mock_email(:from => nil)
|
90
|
+
deliver_from("jimmy_bean@yahoo.com").should_not match(email)
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should give correct failure message when the email is not set to deliver from the specified address" do
|
94
|
+
matcher = deliver_from("jimmy_bean@yahoo.com")
|
95
|
+
matcher.matches?(mock_email(:inspect => 'email', :from => ['freddy_noe@yahoo.com']))
|
96
|
+
matcher.failure_message.should == %{expected email to deliver from "jimmy_bean@yahoo.com", but it delivered from "freddy_noe@yahoo.com"}
|
97
|
+
end
|
98
|
+
|
75
99
|
end
|
76
100
|
|
77
101
|
describe "#bcc_to" do
|
@@ -182,7 +206,7 @@ describe EmailSpec::Matchers do
|
|
182
206
|
describe "#have_body_text" do
|
183
207
|
it "should have specs!"
|
184
208
|
end
|
185
|
-
|
209
|
+
|
186
210
|
describe "#have_header" do
|
187
211
|
it "should have specs!"
|
188
212
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: email_spec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.5
|
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-08
|
14
|
+
date: 2009-10-08 00:00:00 -06:00
|
15
15
|
default_executable:
|
16
16
|
dependencies: []
|
17
17
|
|
@@ -33,6 +33,7 @@ files:
|
|
33
33
|
- lib/email-spec.rb
|
34
34
|
- lib/email_spec.rb
|
35
35
|
- lib/email_spec/address_converter.rb
|
36
|
+
- lib/email_spec/background_processes.rb
|
36
37
|
- lib/email_spec/cucumber.rb
|
37
38
|
- lib/email_spec/deliveries.rb
|
38
39
|
- lib/email_spec/email_viewer.rb
|
@@ -78,9 +79,11 @@ test_files:
|
|
78
79
|
- examples/rails_root/app/helpers/welcome_helper.rb
|
79
80
|
- examples/rails_root/app/models/user.rb
|
80
81
|
- examples/rails_root/app/models/user_mailer.rb
|
82
|
+
- examples/rails_root/app/views/user_mailer/newsletter.erb
|
81
83
|
- examples/rails_root/app/views/user_mailer/signup.erb
|
82
84
|
- examples/rails_root/app/views/welcome/confirm.html.erb
|
83
85
|
- examples/rails_root/app/views/welcome/index.html.erb
|
86
|
+
- examples/rails_root/app/views/welcome/newsletter.html.erb
|
84
87
|
- examples/rails_root/app/views/welcome/signup.html.erb
|
85
88
|
- examples/rails_root/config/boot.rb
|
86
89
|
- examples/rails_root/config/database.yml
|
@@ -93,11 +96,12 @@ test_files:
|
|
93
96
|
- examples/rails_root/config/initializers/new_rails_defaults.rb
|
94
97
|
- examples/rails_root/config/routes.rb
|
95
98
|
- examples/rails_root/db/migrate/20090125013728_create_users.rb
|
99
|
+
- examples/rails_root/db/migrate/20090908054656_create_delayed_jobs.rb
|
96
100
|
- examples/rails_root/db/schema.rb
|
97
101
|
- examples/rails_root/doc/README_FOR_APP
|
102
|
+
- examples/rails_root/features/delayed_job.feature
|
98
103
|
- examples/rails_root/features/errors.feature
|
99
104
|
- examples/rails_root/features/example.feature
|
100
|
-
- examples/rails_root/features/step_definitions/email_steps.rb
|
101
105
|
- examples/rails_root/features/step_definitions/user_steps.rb
|
102
106
|
- examples/rails_root/features/step_definitions/webrat_steps.rb
|
103
107
|
- examples/rails_root/features/support/env.rb
|
@@ -120,6 +124,7 @@ test_files:
|
|
120
124
|
- examples/rails_root/script/console
|
121
125
|
- examples/rails_root/script/cucumber
|
122
126
|
- examples/rails_root/script/dbconsole
|
127
|
+
- examples/rails_root/script/delayed_job
|
123
128
|
- examples/rails_root/script/destroy
|
124
129
|
- examples/rails_root/script/generate
|
125
130
|
- examples/rails_root/script/performance/benchmarker
|
@@ -140,7 +145,11 @@ test_files:
|
|
140
145
|
- examples/rails_root/spec/rcov.opts
|
141
146
|
- examples/rails_root/spec/spec.opts
|
142
147
|
- examples/rails_root/spec/spec_helper.rb
|
143
|
-
- examples/
|
144
|
-
- examples/
|
145
|
-
- examples/
|
146
|
-
- examples/
|
148
|
+
- examples/sinatra/app.rb
|
149
|
+
- examples/sinatra/features/errors.feature
|
150
|
+
- examples/sinatra/features/example.feature
|
151
|
+
- examples/sinatra/features/step_definitions/email_steps.rb
|
152
|
+
- examples/sinatra/features/step_definitions/user_steps.rb
|
153
|
+
- examples/sinatra/features/step_definitions/webrat_steps.rb
|
154
|
+
- examples/sinatra/features/support/env.rb
|
155
|
+
- examples/sinatra/features/support/paths.rb
|
@@ -1,17 +0,0 @@
|
|
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
|
@@ -1,122 +0,0 @@
|
|
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
|
-
unread_emails_for(address).size.should == parse_email_count(amount)
|
53
|
-
end
|
54
|
-
|
55
|
-
Then /^(?:I|they|"([^"]*?)") should have (an|no|\d+) emails?$/ do |address, amount|
|
56
|
-
mailbox_for(address).size.should == parse_email_count(amount)
|
57
|
-
end
|
58
|
-
|
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
|
66
|
-
end
|
67
|
-
|
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)
|
75
|
-
end
|
76
|
-
|
77
|
-
When /^(?:I|they|"([^"]*?)") opens? the email with subject "([^"]*?)"$/ do |address, subject|
|
78
|
-
open_email(address, :with_subject => subject)
|
79
|
-
end
|
80
|
-
|
81
|
-
When /^(?:I|they|"([^"]*?)") opens? the email with text "([^"]*?)"$/ do |address, text|
|
82
|
-
open_email(address, :with_text => text)
|
83
|
-
end
|
84
|
-
|
85
|
-
#
|
86
|
-
# Inspect the Email Contents
|
87
|
-
#
|
88
|
-
|
89
|
-
Then /^(?:I|they) should see "([^"]*?)" in the email subject$/ do |text|
|
90
|
-
current_email.should have_subject(Regexp.new(text))
|
91
|
-
end
|
92
|
-
|
93
|
-
Then /^(?:I|they) should see "([^"]*?)" in the email body$/ do |text|
|
94
|
-
current_email.body.should =~ Regexp.new(text)
|
95
|
-
end
|
96
|
-
|
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))
|
104
|
-
end
|
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)
|
109
|
-
end
|
110
|
-
|
111
|
-
#
|
112
|
-
# Interact with Email Contents
|
113
|
-
#
|
114
|
-
|
115
|
-
When /^(?:I|they) follow "([^"]*?)" in the email$/ do |link|
|
116
|
-
visit_in_email(link)
|
117
|
-
end
|
118
|
-
|
119
|
-
When /^(?:I|they) click the first link in the email$/ do
|
120
|
-
click_first_link_in_email
|
121
|
-
end
|
122
|
-
|