path-email_spec 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +199 -0
- data/MIT-LICENSE.txt +19 -0
- data/README.rdoc +137 -0
- data/Rakefile +64 -0
- data/examples/rails3_root/Gemfile +24 -0
- data/examples/rails3_root/README +5 -0
- data/examples/rails3_root/Rakefile +11 -0
- data/examples/rails3_root/app/controllers/application_controller.rb +3 -0
- data/examples/rails3_root/app/controllers/welcome_controller.rb +16 -0
- data/examples/rails3_root/app/helpers/application_helper.rb +2 -0
- data/examples/rails3_root/app/mailers/user_mailer.rb +39 -0
- data/examples/rails3_root/app/models/user.rb +2 -0
- data/examples/rails3_root/app/views/user_mailer/attachments.html.erb +6 -0
- data/examples/rails3_root/app/views/user_mailer/newsletter.html.erb +8 -0
- data/examples/rails3_root/app/views/user_mailer/signup.html.erb +3 -0
- data/examples/rails3_root/app/views/welcome/attachments.html.erb +0 -0
- data/examples/rails3_root/app/views/welcome/confirm.html.erb +1 -0
- data/examples/rails3_root/app/views/welcome/index.html.erb +8 -0
- data/examples/rails3_root/app/views/welcome/newsletter.html.erb +0 -0
- data/examples/rails3_root/app/views/welcome/signup.html.erb +1 -0
- data/examples/rails3_root/attachments/document.pdf +0 -0
- data/examples/rails3_root/attachments/image.png +0 -0
- data/examples/rails3_root/config.ru +4 -0
- data/examples/rails3_root/config/application.rb +43 -0
- data/examples/rails3_root/config/boot.rb +14 -0
- data/examples/rails3_root/config/cucumber.yml +7 -0
- data/examples/rails3_root/config/database.yml +25 -0
- data/examples/rails3_root/config/environment.rb +6 -0
- data/examples/rails3_root/config/environments/development.rb +19 -0
- data/examples/rails3_root/config/environments/production.rb +42 -0
- data/examples/rails3_root/config/environments/test.rb +29 -0
- data/examples/rails3_root/config/initializers/backtrace_silencers.rb +7 -0
- data/examples/rails3_root/config/initializers/cookie_verification_secret.rb +7 -0
- data/examples/rails3_root/config/initializers/inflections.rb +10 -0
- data/examples/rails3_root/config/initializers/mime_types.rb +5 -0
- data/examples/rails3_root/config/initializers/rspec_generator.rb +6 -0
- data/examples/rails3_root/config/initializers/session_store.rb +10 -0
- data/examples/rails3_root/config/locales/en.yml +5 -0
- data/examples/rails3_root/config/routes.rb +7 -0
- data/examples/rails3_root/db/migrate/20090125013728_create_users.rb +11 -0
- data/examples/rails3_root/db/migrate/20090908054656_create_delayed_jobs.rb +20 -0
- data/examples/rails3_root/db/schema.rb +32 -0
- data/examples/rails3_root/db/seeds.rb +7 -0
- data/examples/rails3_root/doc/README_FOR_APP +2 -0
- data/examples/rails3_root/features/attachments.feature +27 -0
- data/examples/rails3_root/features/delayed_job.feature +13 -0
- data/examples/rails3_root/features/errors.feature +32 -0
- data/examples/rails3_root/features/example.feature +62 -0
- data/examples/rails3_root/features/step_definitions/user_steps.rb +26 -0
- data/examples/rails3_root/features/step_definitions/web_steps.rb +202 -0
- data/examples/rails3_root/features/support/env.rb +59 -0
- data/examples/rails3_root/features/support/env_ext.rb +2 -0
- data/examples/rails3_root/features/support/paths.rb +33 -0
- data/examples/rails3_root/lib/tasks/cucumber.rake +47 -0
- data/examples/rails3_root/lib/tasks/rspec.rake +69 -0
- data/examples/rails3_root/public/404.html +26 -0
- data/examples/rails3_root/public/422.html +26 -0
- data/examples/rails3_root/public/500.html +26 -0
- data/examples/rails3_root/public/favicon.ico +0 -0
- data/examples/rails3_root/public/images/rails.png +0 -0
- data/examples/rails3_root/public/javascripts/application.js +2 -0
- data/examples/rails3_root/public/javascripts/controls.js +965 -0
- data/examples/rails3_root/public/javascripts/dragdrop.js +974 -0
- data/examples/rails3_root/public/javascripts/effects.js +1123 -0
- data/examples/rails3_root/public/javascripts/prototype.js +4874 -0
- data/examples/rails3_root/public/javascripts/rails.js +109 -0
- data/examples/rails3_root/public/robots.txt +5 -0
- data/examples/rails3_root/script/cucumber +10 -0
- data/examples/rails3_root/script/rails +9 -0
- data/examples/rails3_root/spec/controllers/welcome_controller_spec.rb +18 -0
- data/examples/rails3_root/spec/models/user_mailer_spec.rb +47 -0
- data/examples/rails3_root/spec/spec.opts +2 -0
- data/examples/rails3_root/spec/spec_helper.rb +19 -0
- data/examples/rails_root/Rakefile +13 -0
- data/examples/rails_root/app/controllers/application_controller.rb +15 -0
- data/examples/rails_root/app/controllers/welcome_controller.rb +16 -0
- data/examples/rails_root/app/helpers/application_helper.rb +3 -0
- data/examples/rails_root/app/helpers/welcome_helper.rb +2 -0
- data/examples/rails_root/app/models/user.rb +2 -0
- data/examples/rails_root/app/models/user_mailer.rb +39 -0
- data/examples/rails_root/app/views/user_mailer/attachments.erb +6 -0
- data/examples/rails_root/app/views/user_mailer/newsletter.erb +8 -0
- data/examples/rails_root/app/views/user_mailer/signup.erb +3 -0
- data/examples/rails_root/app/views/welcome/attachments.html.erb +0 -0
- data/examples/rails_root/app/views/welcome/confirm.html.erb +1 -0
- data/examples/rails_root/app/views/welcome/index.html.erb +8 -0
- data/examples/rails_root/app/views/welcome/newsletter.html.erb +0 -0
- data/examples/rails_root/app/views/welcome/signup.html.erb +1 -0
- data/examples/rails_root/attachments/document.pdf +0 -0
- data/examples/rails_root/attachments/image.png +0 -0
- data/examples/rails_root/config/boot.rb +110 -0
- data/examples/rails_root/config/cucumber.yml +7 -0
- data/examples/rails_root/config/database.yml +25 -0
- data/examples/rails_root/config/environment.rb +28 -0
- data/examples/rails_root/config/environments/cucumber.rb +29 -0
- data/examples/rails_root/config/environments/development.rb +17 -0
- data/examples/rails_root/config/environments/production.rb +28 -0
- data/examples/rails_root/config/environments/test.rb +28 -0
- data/examples/rails_root/config/initializers/inflections.rb +10 -0
- data/examples/rails_root/config/initializers/mime_types.rb +5 -0
- data/examples/rails_root/config/initializers/new_rails_defaults.rb +17 -0
- data/examples/rails_root/config/routes.rb +45 -0
- data/examples/rails_root/db/migrate/20090125013728_create_users.rb +11 -0
- data/examples/rails_root/db/migrate/20090908054656_create_delayed_jobs.rb +20 -0
- data/examples/rails_root/db/schema.rb +32 -0
- data/examples/rails_root/doc/README_FOR_APP +5 -0
- data/examples/rails_root/features/attachments.feature +27 -0
- data/examples/rails_root/features/delayed_job.feature +13 -0
- data/examples/rails_root/features/errors.feature +32 -0
- data/examples/rails_root/features/example.feature +62 -0
- data/examples/rails_root/features/step_definitions/user_steps.rb +26 -0
- data/examples/rails_root/features/step_definitions/web_steps.rb +273 -0
- data/examples/rails_root/features/support/env.rb +58 -0
- data/examples/rails_root/features/support/env_ext.rb +6 -0
- data/examples/rails_root/features/support/paths.rb +33 -0
- data/examples/rails_root/lib/tasks/cucumber.rake +47 -0
- data/examples/rails_root/public/404.html +30 -0
- data/examples/rails_root/public/422.html +30 -0
- data/examples/rails_root/public/500.html +33 -0
- data/examples/rails_root/public/dispatch.rb +10 -0
- data/examples/rails_root/public/favicon.ico +0 -0
- data/examples/rails_root/public/images/rails.png +0 -0
- data/examples/rails_root/public/javascripts/application.js +2 -0
- data/examples/rails_root/public/javascripts/controls.js +963 -0
- data/examples/rails_root/public/javascripts/dragdrop.js +973 -0
- data/examples/rails_root/public/javascripts/effects.js +1128 -0
- data/examples/rails_root/public/javascripts/prototype.js +4320 -0
- data/examples/rails_root/public/robots.txt +5 -0
- data/examples/rails_root/script/about +4 -0
- data/examples/rails_root/script/autospec +5 -0
- data/examples/rails_root/script/console +3 -0
- data/examples/rails_root/script/cucumber +10 -0
- data/examples/rails_root/script/dbconsole +3 -0
- data/examples/rails_root/script/delayed_job +5 -0
- data/examples/rails_root/script/destroy +3 -0
- data/examples/rails_root/script/generate +3 -0
- data/examples/rails_root/script/performance/benchmarker +3 -0
- data/examples/rails_root/script/performance/profiler +3 -0
- data/examples/rails_root/script/performance/request +3 -0
- data/examples/rails_root/script/plugin +3 -0
- data/examples/rails_root/script/process/inspector +3 -0
- data/examples/rails_root/script/process/reaper +3 -0
- data/examples/rails_root/script/process/spawner +3 -0
- data/examples/rails_root/script/runner +3 -0
- data/examples/rails_root/script/server +3 -0
- data/examples/rails_root/script/spec +5 -0
- data/examples/rails_root/script/spec_server +125 -0
- data/examples/rails_root/spec/controllers/welcome_controller_spec.rb +15 -0
- data/examples/rails_root/spec/model_factory.rb +6 -0
- data/examples/rails_root/spec/models/user_mailer_spec.rb +58 -0
- data/examples/rails_root/spec/models/user_spec.rb +5 -0
- data/examples/rails_root/spec/rcov.opts +2 -0
- data/examples/rails_root/spec/spec.opts +4 -0
- data/examples/rails_root/spec/spec_helper.rb +51 -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/sinatra/features/step_definitions/user_steps.rb +26 -0
- data/examples/sinatra/features/step_definitions/web_steps.rb +273 -0
- data/examples/sinatra/features/support/env.rb +39 -0
- data/examples/sinatra/features/support/paths.rb +24 -0
- data/install.rb +0 -0
- data/lib/email-spec.rb +1 -0
- data/lib/email_spec.rb +15 -0
- data/lib/email_spec/address_converter.rb +29 -0
- data/lib/email_spec/background_processes.rb +45 -0
- data/lib/email_spec/cucumber.rb +26 -0
- data/lib/email_spec/deliveries.rb +87 -0
- data/lib/email_spec/email_viewer.rb +87 -0
- data/lib/email_spec/helpers.rb +164 -0
- data/lib/email_spec/matchers.rb +225 -0
- data/lib/generators/email_spec/steps/USAGE +5 -0
- data/lib/generators/email_spec/steps/steps_generator.rb +14 -0
- data/lib/generators/email_spec/steps/templates/email_steps.rb +194 -0
- data/rails_generators/email_spec/email_spec_generator.rb +17 -0
- data/rails_generators/email_spec/templates/email_steps.rb +182 -0
- data/spec/email_spec/helpers_spec.rb +21 -0
- data/spec/email_spec/matchers_spec.rb +430 -0
- data/spec/spec_helper.rb +16 -0
- metadata +407 -0
@@ -0,0 +1,32 @@
|
|
1
|
+
# This file is auto-generated from the current state of the database. Instead of editing this file,
|
2
|
+
# please use the migrations feature of Active Record to incrementally modify your database, and
|
3
|
+
# then regenerate this schema definition.
|
4
|
+
#
|
5
|
+
# Note that this schema.rb definition is the authoritative source for your database schema. If you need
|
6
|
+
# to create the application database on another system, you should be using db:schema:load, not running
|
7
|
+
# all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
8
|
+
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
9
|
+
#
|
10
|
+
# It's strongly recommended to check this file into your version control system.
|
11
|
+
|
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
|
26
|
+
|
27
|
+
create_table "users", :force => true do |t|
|
28
|
+
t.string "email"
|
29
|
+
t.string "name"
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# This file should contain all the record creation needed to seed the database with its default values.
|
2
|
+
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
|
3
|
+
#
|
4
|
+
# Examples:
|
5
|
+
#
|
6
|
+
# cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
|
7
|
+
# Mayor.create(:name => 'Daley', :city => cities.first)
|
@@ -0,0 +1,27 @@
|
|
1
|
+
Feature: Attachment testing support
|
2
|
+
In order for developers to test attachments in emails
|
3
|
+
I want to be able to provide working steps which inspect attachments
|
4
|
+
|
5
|
+
Scenario: Email with Attachments
|
6
|
+
Given no emails have been sent
|
7
|
+
And I go to request attachments be sent to me
|
8
|
+
Then I should receive an email
|
9
|
+
When I open the email
|
10
|
+
Then I should see 2 attachments with the email
|
11
|
+
And there should be an attachment named "image.png"
|
12
|
+
And there should be an attachment named "document.pdf"
|
13
|
+
And attachment 1 should be named "image.png"
|
14
|
+
And attachment 2 should be named "document.pdf"
|
15
|
+
And there should be an attachment of type "image/png"
|
16
|
+
And there should be an attachment of type "application/pdf"
|
17
|
+
And attachment 1 should be of type "image/png"
|
18
|
+
And attachment 2 should be of type "application/pdf"
|
19
|
+
And all attachments should not be blank
|
20
|
+
|
21
|
+
Scenario: Email without Attachments
|
22
|
+
Given no emails have been sent
|
23
|
+
And I am on the homepage
|
24
|
+
And I submit my registration information
|
25
|
+
Then I should receive an email
|
26
|
+
When I open the email
|
27
|
+
Then I should see no attachments with the 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
|
@@ -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
|
@@ -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
|
+
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
|
+
page.should 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
|
+
Then "I should see \"#{text}\""
|
26
|
+
end
|
@@ -0,0 +1,202 @@
|
|
1
|
+
# IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
|
2
|
+
# It is recommended to regenerate this file in the future when you upgrade to a
|
3
|
+
# newer version of cucumber-rails. Consider adding your own code to a new file
|
4
|
+
# instead of editing this one. Cucumber will automatically load all features/**/*.rb
|
5
|
+
# files.
|
6
|
+
|
7
|
+
|
8
|
+
require 'uri'
|
9
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
|
10
|
+
|
11
|
+
module WithinHelpers
|
12
|
+
def with_scope(locator)
|
13
|
+
locator ? within(locator) { yield } : yield
|
14
|
+
end
|
15
|
+
end
|
16
|
+
World(WithinHelpers)
|
17
|
+
|
18
|
+
Given /^(?:|I )am on (.+)$/ do |page_name|
|
19
|
+
visit path_to(page_name)
|
20
|
+
end
|
21
|
+
|
22
|
+
When /^(?:|I )go to (.+)$/ do |page_name|
|
23
|
+
visit path_to(page_name)
|
24
|
+
end
|
25
|
+
|
26
|
+
When /^(?:|I )press "([^\"]*)"(?: within "([^\"]*)")?$/ do |button, selector|
|
27
|
+
with_scope(selector) do
|
28
|
+
click_button(button)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
When /^(?:|I )follow "([^\"]*)"(?: within "([^\"]*)")?$/ do |link, selector|
|
33
|
+
with_scope(selector) do
|
34
|
+
click_link(link)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
When /^(?:|I )fill in "([^\"]*)" with "([^\"]*)"(?: within "([^\"]*)")?$/ do |field, value, selector|
|
39
|
+
with_scope(selector) do
|
40
|
+
fill_in(field, :with => value)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
When /^(?:|I )fill in "([^\"]*)" for "([^\"]*)"(?: within "([^\"]*)")?$/ do |value, field, selector|
|
45
|
+
with_scope(selector) do
|
46
|
+
fill_in(field, :with => value)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# Use this to fill in an entire form with data from a table. Example:
|
51
|
+
#
|
52
|
+
# When I fill in the following:
|
53
|
+
# | Account Number | 5002 |
|
54
|
+
# | Expiry date | 2009-11-01 |
|
55
|
+
# | Note | Nice guy |
|
56
|
+
# | Wants Email? | |
|
57
|
+
#
|
58
|
+
# TODO: Add support for checkbox, select og option
|
59
|
+
# based on naming conventions.
|
60
|
+
#
|
61
|
+
When /^(?:|I )fill in the following(?: within "([^\"]*)")?:$/ do |selector, fields|
|
62
|
+
with_scope(selector) do
|
63
|
+
fields.rows_hash.each do |name, value|
|
64
|
+
When %{I fill in "#{name}" with "#{value}"}
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
When /^(?:|I )select "([^\"]*)" from "([^\"]*)"(?: within "([^\"]*)")?$/ do |value, field, selector|
|
70
|
+
with_scope(selector) do
|
71
|
+
select(value, :from => field)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
When /^(?:|I )check "([^\"]*)"(?: within "([^\"]*)")?$/ do |field, selector|
|
76
|
+
with_scope(selector) do
|
77
|
+
check(field)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
When /^(?:|I )uncheck "([^\"]*)"(?: within "([^\"]*)")?$/ do |field, selector|
|
82
|
+
with_scope(selector) do
|
83
|
+
uncheck(field)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
When /^(?:|I )choose "([^\"]*)"(?: within "([^\"]*)")?$/ do |field, selector|
|
88
|
+
with_scope(selector) do
|
89
|
+
choose(field)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
When /^(?:|I )attach the file "([^\"]*)" to "([^\"]*)"(?: within "([^\"]*)")?$/ do |path, field, selector|
|
94
|
+
with_scope(selector) do
|
95
|
+
attach_file(field, path)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
Then /^(?:|I )should see "([^\"]*)"(?: within "([^\"]*)")?$/ do |text, selector|
|
100
|
+
with_scope(selector) do
|
101
|
+
if defined?(Spec::Rails::Matchers)
|
102
|
+
page.should have_content(text)
|
103
|
+
else
|
104
|
+
assert page.has_content?(text)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
Then /^(?:|I )should see \/([^\/]*)\/(?: within "([^\"]*)")?$/ do |regexp, selector|
|
110
|
+
regexp = Regexp.new(regexp)
|
111
|
+
with_scope(selector) do
|
112
|
+
if defined?(Spec::Rails::Matchers)
|
113
|
+
page.should have_xpath('//*', :text => regexp)
|
114
|
+
else
|
115
|
+
assert page.has_xpath?('//*', :text => regexp)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
Then /^(?:|I )should not see "([^\"]*)"(?: within "([^\"]*)")?$/ do |text, selector|
|
121
|
+
with_scope(selector) do
|
122
|
+
if defined?(Spec::Rails::Matchers)
|
123
|
+
page.should have_no_content(text)
|
124
|
+
else
|
125
|
+
assert page.has_no_content?(text)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
Then /^(?:|I )should not see \/([^\/]*)\/(?: within "([^\"]*)")?$/ do |regexp, selector|
|
131
|
+
regexp = Regexp.new(regexp)
|
132
|
+
with_scope(selector) do
|
133
|
+
if defined?(Spec::Rails::Matchers)
|
134
|
+
page.should have_no_xpath('//*', :text => regexp)
|
135
|
+
else
|
136
|
+
assert page.has_no_xpath?('//*', :text => regexp)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
Then /^the "([^\"]*)" field(?: within "([^\"]*)")? should contain "([^\"]*)"$/ do |field, selector, value|
|
142
|
+
with_scope(selector) do
|
143
|
+
if defined?(Spec::Rails::Matchers)
|
144
|
+
find_field(field).value.should =~ /#{value}/
|
145
|
+
else
|
146
|
+
assert_match(/#{value}/, field_labeled(field).value)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
Then /^the "([^\"]*)" field(?: within "([^\"]*)")? should not contain "([^\"]*)"$/ do |field, selector, value|
|
152
|
+
with_scope(selector) do
|
153
|
+
if defined?(Spec::Rails::Matchers)
|
154
|
+
find_field(field).value.should_not =~ /#{value}/
|
155
|
+
else
|
156
|
+
assert_no_match(/#{value}/, find_field(field).value)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
Then /^the "([^\"]*)" checkbox(?: within "([^\"]*)")? should be checked$/ do |label, selector|
|
162
|
+
with_scope(selector) do
|
163
|
+
if defined?(Spec::Rails::Matchers)
|
164
|
+
find_field(label)['checked'].should == 'checked'
|
165
|
+
else
|
166
|
+
assert_equal 'checked', field_labeled(label)['checked']
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
Then /^the "([^\"]*)" checkbox(?: within "([^\"]*)")? should not be checked$/ do |label, selector|
|
172
|
+
with_scope(selector) do
|
173
|
+
if defined?(Spec::Rails::Matchers)
|
174
|
+
find_field(label)['checked'].should_not == 'checked'
|
175
|
+
else
|
176
|
+
assert_not_equal 'checked', field_labeled(label)['checked']
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
Then /^(?:|I )should be on (.+)$/ do |page_name|
|
182
|
+
if defined?(Spec::Rails::Matchers)
|
183
|
+
URI.parse(current_url).path.should == path_to(page_name)
|
184
|
+
else
|
185
|
+
assert_equal path_to(page_name), URI.parse(current_url).path
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
Then /^(?:|I )should have the following query string:$/ do |expected_pairs|
|
190
|
+
actual_params = CGI.parse(URI.parse(current_url).query)
|
191
|
+
expected_params = Hash[expected_pairs.rows_hash.map{|k,v| [k,[v]]}]
|
192
|
+
|
193
|
+
if defined?(Spec::Rails::Matchers)
|
194
|
+
actual_params.should == expected_params
|
195
|
+
else
|
196
|
+
assert_equal expected_params, actual_params
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
Then /^show me the page$/ do
|
201
|
+
save_and_open_page
|
202
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
|
2
|
+
# It is recommended to regenerate this file in the future when you upgrade to a
|
3
|
+
# newer version of cucumber-rails. Consider adding your own code to a new file
|
4
|
+
# instead of editing this one. Cucumber will automatically load all features/**/*.rb
|
5
|
+
# files.
|
6
|
+
|
7
|
+
ENV["RAILS_ENV"] ||= "test"
|
8
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../config/environment')
|
9
|
+
|
10
|
+
require 'cucumber/formatter/unicode' # Remove this line if you don't want Cucumber Unicode support
|
11
|
+
require 'cucumber/rails/rspec'
|
12
|
+
require 'cucumber/rails/world'
|
13
|
+
require 'cucumber/rails/active_record'
|
14
|
+
require 'cucumber/web/tableish'
|
15
|
+
|
16
|
+
require 'capybara/rails'
|
17
|
+
require 'capybara/cucumber'
|
18
|
+
require 'capybara/session'
|
19
|
+
require 'cucumber/rails/capybara_javascript_emulation' # Lets you click links with onclick javascript handlers without using @culerity or @javascript
|
20
|
+
# Capybara defaults to XPath selectors rather than Webrat's default of CSS3. In
|
21
|
+
# order to ease the transition to Capybara we set the default here. If you'd
|
22
|
+
# prefer to use XPath just remove this line and adjust any selectors in your
|
23
|
+
# steps to use the XPath syntax.
|
24
|
+
Capybara.default_selector = :css
|
25
|
+
|
26
|
+
# If you set this to false, any error raised from within your app will bubble
|
27
|
+
# up to your step definition and out to cucumber unless you catch it somewhere
|
28
|
+
# on the way. You can make Rails rescue errors and render error pages on a
|
29
|
+
# per-scenario basis by tagging a scenario or feature with the @allow-rescue tag.
|
30
|
+
#
|
31
|
+
# If you set this to true, Rails will rescue all errors and render error
|
32
|
+
# pages, more or less in the same way your application would behave in the
|
33
|
+
# default production environment. It's not recommended to do this for all
|
34
|
+
# of your scenarios, as this makes it hard to discover errors in your application.
|
35
|
+
ActionController::Base.allow_rescue = false
|
36
|
+
|
37
|
+
# If you set this to true, each scenario will run in a database transaction.
|
38
|
+
# You can still turn off transactions on a per-scenario basis, simply tagging
|
39
|
+
# a feature or scenario with the @no-txn tag. If you are using Capybara,
|
40
|
+
# tagging with @culerity or @javascript will also turn transactions off.
|
41
|
+
#
|
42
|
+
# If you set this to false, transactions will be off for all scenarios,
|
43
|
+
# regardless of whether you use @no-txn or not.
|
44
|
+
#
|
45
|
+
# Beware that turning transactions off will leave data in your database
|
46
|
+
# after each scenario, which can lead to hard-to-debug failures in
|
47
|
+
# subsequent scenarios. If you do this, we recommend you create a Before
|
48
|
+
# block that will explicitly put your database in a known state.
|
49
|
+
Cucumber::Rails::World.use_transactional_fixtures = true
|
50
|
+
|
51
|
+
# How to clean your database when transactions are turned off. See
|
52
|
+
# http://github.com/bmabey/database_cleaner for more info.
|
53
|
+
if defined?(ActiveRecord::Base)
|
54
|
+
begin
|
55
|
+
require 'database_cleaner'
|
56
|
+
DatabaseCleaner.strategy = :truncation
|
57
|
+
rescue LoadError => ignore_if_database_cleaner_not_present
|
58
|
+
end
|
59
|
+
end
|