Cleaning up Cucumber features

- removing tag actions and replacing with background tasks
- adding some sample pickle steps
- added some basic pickle documentation
This commit is contained in:
Jacques Crocker 2010-08-01 03:37:49 -07:00
parent 659c805ea9
commit fd6a13858c
10 changed files with 242 additions and 74 deletions

139
doc/PICKLE_STEPS Normal file
View File

@ -0,0 +1,139 @@
== API
==== Given steps
"Given <b>a model</b> exists", e.g.
Given a user exists
Given a user: "fred" exists
Given the user exists
"Given <b>a model</b> exists with <b>fields</b>", e.g.
Given a user exists with name: "Fred"
Given a user exists with name: "Fred", activated: false
You can refer to other models in the fields
Given a user exists
And a post exists with author: the user
Given a person: "fred" exists
And a person: "ethel" exists
And a fatherhood exists with parent: user "fred", child: user "ethel"
"Given <b>n models</b> exist", e.g.
Given 10 users exist
"Given <b>n models</b> exist with <b>fields</b>", examples:
Given 10 users exist with activated: false
"Given the following <b>models</b> exist:", examples:
Given the following users exist
| name | activated |
| Fred | false |
| Ethel | true |
==== Then steps
===== Asserting existence of models
"Then <b>a model</b> should exist", e.g.
Then a user should exist
"Then <b>a model</b> should exist with <b>fields</b>", e.g.
Then a user: "fred" should exist with name: "Fred" # we can label the found user for later use
You can use other models, booleans, numerics, and strings as fields
Then a person should exist with child: person "ethel"
Then a user should exist with activated: false
Then a user should exist with activated: true, email: "fred@gmail.com"
"Then <b>n models</b> should exist", e.g.
Then 10 events should exist
"Then <b>n models</b> should exist with <b>fields</b>", e.g.
Then 2 people should exist with father: person "fred"
"Then the following <b>models</b> exist". This allows the creation of multiple models
using a table syntax. Using a column with the singularized name of the model creates a referenceable model. E.g.
Then the following users exist:
| name | activated |
| Freddy | false |
Then the following users exist:
| user | name | activated |
| Fred | Freddy | false |
===== Asserting associations
One-to-one assocs: "Then <b>a model</b> should be <b>other model</b>'s <b>association</b>", e.g.
Then the person: "fred" should be person: "ethel"'s father
Many-to-one assocs: "Then <b>a model</b> should be [in|one of] <b>other model</b>'s <b>association</b>", e.g.
Then the person: "ethel" should be one of person: "fred"'s children
Then the comment should be in the post's comments
===== Asserting predicate methods
"Then <b>a model</b> should [be|have] [a|an] <b>predicate</b>", e.g.
Then the user should have a status # => user.status.should be_present
Then the user should have a stale password # => user.should have_stale_password
Then the car: "batmobile" should be fast # => car.should be_fast
"Then <b>a model</b> should not [be|have] [a|an] <b>predicate</b>", e.g.
Then person: "fred" should not be childless # => fred.should_not be_childless
=== Regexps for use in your own steps
By default you get some regexps available in the main namespace for use
in creating your own steps: `capture_model`, `capture_fields`, and others (see lib/pickle.rb)
(You can use any of the regexps that Pickle uses by using the Pickle.parser namespace, see
Pickle::Parser::Matchers for the methods available)
*capture_model*
Given /^#{capture_model} exists$/ do |model_name|
model(model_name).should_not == nil
end
Then /^I should be at the (.*?) page$/ |page|
if page =~ /#{capture_model}'s/
url_for(model($1))
else
# ...
end
end
Then /^#{capture_model} should be one of #{capture_model}'s posts$/ do |post, forum|
post = model!(post)
forum = model!(forum)
forum.posts.should include(post)
end
*capture_fields*
This is useful for setting attributes, and knows about pickle model names so that you
can build up composite objects with ease
Given /^#{capture_model} exists with #{capture_fields}$/ do |model_name, fields|
create_model(model_name, fields)
end
# example of use
Given a user exists
And a post exists with author: the user # this step will assign the above user as :author on the post

View File

@ -0,0 +1,26 @@
Feature: Cross Domain Authentication
In order to manage a new site I created
As an administrator signed in another site of mine
I want to bypass the authentication
Background:
Given I have the site: "test site" set up
And I have the site: "another site" set up
And I am an authenticated user
Scenario: Successful authentication
When I go to pages
Then I should see "Locomotive test website"
When I select "Locomotive test website #2" from "target_id"
And I press "Switch"
Then I should see "Cross-domain authentication"
When I press "Go"
Then I should see "Locomotive test website #2"
Scenario: Failed authentication because of an outdated token
When I go to pages
And I select "Locomotive test website #2" from "target_id"
And I press "Switch"
And I forget to press the button on the cross-domain notice page
And I press "Go"
Then I should see "You need to sign in"

View File

@ -1,24 +0,0 @@
@site_up
@another_site_up
@authenticated
Feature:
In order to manage a new site I created
As an administrator signed in another site of mine
I want to bypass the authentication
Scenario: Successful authentication
When I go to pages
Then I should see "Locomotive test website"
When I select "Locomotive test website #2" from "target_id"
And I press "Switch"
Then I should see "Cross-domain authentication"
When I press "Go"
Then I should see "Locomotive test website #2"
Scenario: Failed authentication because of an outdated token
When I go to pages
And I select "Locomotive test website #2" from "target_id"
And I press "Switch"
And I forget to press the button on the cross-domain notice page
And I press "Go"
Then I should see "You need to sign in"

View File

@ -1,19 +1,21 @@
@site_up
Feature: Login Feature: Login
In order to access locomotive admin panel In order to access locomotive admin panel
As an administrator As an administrator
I want to log in I want to log in
Scenario: Successful authentication Background:
When I go to login Given I have the site: "test site" set up
And I fill in "Email" with "admin@locomotiveapp.org"
And I fill in "Password" with "easyone"
And I press "Log in"
Then I should see "Listing pages"
Scenario: Failed authentication Scenario: Successful authentication
When I go to login When I go to login
And I fill in "Email" with "admin@locomotiveapp.org" And I fill in "Email" with "admin@locomotiveapp.org"
And I fill in "Password" with "" And I fill in "Password" with "easyone"
And I press "Log in" And I press "Log in"
Then I should not see "Listing pages" Then I should see "Listing pages"
Scenario: Failed authentication
When I go to login
And I fill in "Email" with "admin@locomotiveapp.org"
And I fill in "Password" with ""
And I press "Log in"
Then I should not see "Listing pages"

View File

@ -1,31 +1,33 @@
@site_up
@authenticated
Feature: Manage Pages Feature: Manage Pages
In order to manage pages In order to manage pages
As an administrator As an administrator
I want to add/edit/delete pages of my site I want to add/edit/delete pages of my site
Scenario: Pages list is not accessible for non authenticated accounts Background:
Given I am not authenticated Given I have the site: "test site" set up
When I go to pages And I am an authenticated user
Then I should see "Log in"
Scenario: Creating a valid page Scenario: Pages list is not accessible for non authenticated accounts
When I go to pages Given I am not authenticated
And I follow "new page" When I go to pages
And I fill in "Title" with "Test" Then I should see "Log in"
And I fill in "Slug" with "test"
And I select "Home page" from "Parent"
And I fill in "Body" with "Lorem ipsum...."
And I press "Create"
Then I should see "Page was successfully created."
And I should have "Lorem ipsum...." in the test page layout
Scenario: Updating a valid page Scenario: Creating a valid page
When I go to pages When I go to pages
And I follow "Home page" And I follow "new page"
And I fill in "Title" with "Home page !" And I fill in "Title" with "Test"
And I fill in "Body" with "My new content is here" And I fill in "Slug" with "test"
And I press "Update" And I select "Home page" from "Parent"
Then I should see "Page was successfully updated." And I fill in "Body" with "Lorem ipsum...."
And I should have "My new content is here" in the index page layout And I press "Create"
Then I should see "Page was successfully created."
And I should have "Lorem ipsum...." in the test page layout
Scenario: Updating a valid page
When I go to pages
And I follow "Home page"
And I fill in "Title" with "Home page !"
And I fill in "Body" with "My new content is here"
And I press "Update"
Then I should see "Page was successfully updated."
And I should have "My new content is here" in the index page layout

View File

@ -2,6 +2,9 @@ Feature: Engine
As a website user As a website user
I want to be able to view someones created locomotive pages I want to be able to view someones created locomotive pages
Background:
Given I have the site: "test site" set up with name: "Something2111"
@wip @wip
Scenario: Simple Page Scenario: Simple Page
Given I have a page created at "/hello_world" with the content: Given I have a page created at "/hello_world" with the content:

View File

@ -1,5 +1,4 @@
Before('@site_up') do Before('@site_up') do
create_site_and_admin_account
create_layout_samples create_layout_samples
end end
@ -7,10 +6,6 @@ Before('@another_site_up') do
add_new_site add_new_site
end end
Before('@authenticated') do
Given %{I am an authenticated user}
end
### Authentication ### Authentication
Given /^I am not authenticated$/ do Given /^I am not authenticated$/ do
@ -51,13 +46,6 @@ end
### Common ### Common
def create_site_and_admin_account
@site = Factory(:site, :name => 'Locomotive test website', :subdomain => 'test')
@admin = Factory(:account, { :name => 'Admin', :email => 'admin@locomotiveapp.org' })
@site.memberships.build :account => @admin, :admin => true
@site.save
end
def add_new_site def add_new_site
@another_site = Factory.build(:site, :name => 'Locomotive test website #2', :subdomain => 'test2') @another_site = Factory.build(:site, :name => 'Locomotive test website #2', :subdomain => 'test2')
@another_site.memberships.build :account => @admin, :admin => true @another_site.memberships.build :account => @admin, :admin => true

View File

@ -0,0 +1,4 @@
Given /^I have a page created at "([^"]*)" with the content:$/ do |page, page_contents|
pending # express the regexp above with the code you wish you had
end

View File

@ -0,0 +1,14 @@
# Creates a Site record
#
# examples:
# - I have the site: "some site" set up
# - I have the site: "some site" set up with name: "Something", domain: "test2"
#
Given /^I have the site: "([^"]*)" set up(?: with #{capture_fields})?$/ do |site_factory, fields|
@site = Factory(site_factory, parse_fields(fields))
@site.should_not be_nil
@admin = @site.memberships.first.account
@admin.should_not be_nil
end

View File

@ -9,10 +9,16 @@ Factory.define "test site", :parent => :site do |s|
s.name 'Locomotive test website' s.name 'Locomotive test website'
s.subdomain 'test' s.subdomain 'test'
s.after_build do |site_test| s.after_build do |site_test|
site_test.memberships.build :account => Factory("admin user"), :admin => true site_test.memberships.build :account => Account.where(:name => "Admin").first || Factory("admin user"), :admin => true
end end
end end
Factory.define "another site", :parent => "test site" do |s|
s.name "Locomotive test website #2"
s.subdomain "test2"
end
# Accounts ## # Accounts ##
Factory.define :account do |a| Factory.define :account do |a|
a.name 'Bart Simpson' a.name 'Bart Simpson'
@ -33,12 +39,14 @@ Factory.define "frenchy user", :parent => :account do |a|
a.locale 'fr' a.locale 'fr'
end end
## Memberships ## ## Memberships ##
Factory.define :membership do |m| Factory.define :membership do |m|
m.association :account, :factory => :account m.association :account, :factory => :account
m.admin true m.admin true
end end
## Pages ## ## Pages ##
Factory.define :page do |p| Factory.define :page do |p|
p.association :site, :factory => :site p.association :site, :factory => :site
@ -46,6 +54,7 @@ Factory.define :page do |p|
p.slug 'index' p.slug 'index'
end end
## Liquid templates ## ## Liquid templates ##
Factory.define :liquid_template do |t| Factory.define :liquid_template do |t|
t.association :site, :factory => :site t.association :site, :factory => :site
@ -54,6 +63,7 @@ Factory.define :liquid_template do |t|
t.value %{simple liquid template} t.value %{simple liquid template}
end end
## Layouts ## ## Layouts ##
Factory.define :layout do |l| Factory.define :layout do |l|
l.association :site, :factory => :site l.association :site, :factory => :site
@ -69,6 +79,7 @@ Factory.define :layout do |l|
</html>} </html>}
end end
## Snippets ## ## Snippets ##
Factory.define :snippet do |s| Factory.define :snippet do |s|
s.association :site, :factory => :site s.association :site, :factory => :site
@ -77,17 +88,20 @@ Factory.define :snippet do |s|
s.value %{<title>Acme</title>} s.value %{<title>Acme</title>}
end end
## Theme assets ## ## Theme assets ##
Factory.define :theme_asset do |a| Factory.define :theme_asset do |a|
a.association :site a.association :site
end end
## Asset collections ## ## Asset collections ##
Factory.define :asset_collection do |s| Factory.define :asset_collection do |s|
s.association :site, :factory => :site s.association :site, :factory => :site
s.name 'Trip to Chicago' s.name 'Trip to Chicago'
end end
## Content types ## ## Content types ##
Factory.define :content_type do |t| Factory.define :content_type do |t|
t.association :site, :factory => :site t.association :site, :factory => :site