update cucumber and refactor some of the stories

inspired by the railscasts about cucumber. Also fix a problem with ZenTest on case sensitive platforms
This commit is contained in:
Reinier Balt 2009-05-22 23:14:40 +02:00
parent bdddac5020
commit 2073f84cd8
11 changed files with 90 additions and 128 deletions

View file

@ -47,7 +47,7 @@ config.after_initialize do
end end
config.gem "flexmock" config.gem "flexmock"
config.gem "ZenTest" config.gem "ZenTest", :lib => "zentest"
config.gem "hpricot" config.gem "hpricot"
config.gem "hoe" config.gem "hoe"
@ -55,4 +55,5 @@ config.gem "hoe"
# the rspec.task file # the rspec.task file
config.gem "rspec-rails", :lib => false, :version => ">=1.2.2" config.gem "rspec-rails", :lib => false, :version => ">=1.2.2"
config.gem "webrat", :lib => false, :version => ">=0.4.3" config.gem "webrat", :lib => false, :version => ">=0.4.3"
config.gem "cucumber", :lib => false, :version => ">=0.2.2" config.gem "cucumber", :lib => false, :version => ">=0.3.0"
config.gem "thoughtbot-factory_girl", :lib => "factory_girl", :source => "http://gems.github.com"

View file

@ -4,29 +4,33 @@ Feature: Signup new users
As a user who just installed Tracks As a user who just installed Tracks
I want to create an admin account I want to create an admin account
Background:
Given the following user records
| login | password | is_admin |
| testuser | secret | false |
| admin | secret | true |
Scenario: Successful signup Scenario: Successful signup
Given no users exists Given no users exists
When I go to the homepage When I go to the homepage
Then I should be redirected to the signup page Then I should be redirected to the signup page
When I successfully submit the signup form When I submit the signup form with username "admin", password "secret" and confirm with "secret"
Then I should be on the homepage Then I should be on the homepage
And I should be an admin And I should be an admin
Scenario: Signup should be refused when password and confirmation is not the same Scenario: Signup should be refused when password and confirmation is not the same
Given no users exists Given no users exists
When I go to the signup page When I go to the signup page
And I submit signup form with dissimmilar password and confirmation And I submit the signup form with username "admin", password "secret" and confirm with "error"
Then I should be redirected to the signup page Then I should be redirected to the signup page
And I should see "Password doesn't match confirmation" And I should see "Password doesn't match confirmation"
Scenario: With public signups turned off, signup should be refused when an admin user exists Scenario: With public signups turned off, signup should be refused when an admin user exists
Given public signups are turned off Given public signups are turned off
And an admin user exists
When I go to the signup page When I go to the signup page
Then I should see "You don't have permission to sign up for a new account." Then I should see "You don't have permission to sign up for a new account."
Scenario: With public signups turned on, signup should possible when an admin user exists Scenario: With public signups turned on, signup should possible when an admin user exists
Given public signups are turned on Given public signups are turned on
And an admin user exists
When I go to the signup page When I go to the signup page
Then I should see "Sign up a new user" Then I should see "Sign up a new user"

View file

@ -4,22 +4,23 @@ Feature: Existing user logging in
As an existing user As an existing user
I want to log in with my username and password I want to log in with my username and password
Scenario: Succesfull login Background:
Given an admin user exists Given the following user records
When I go to the login page | login | password | is_admin |
And I successfully submit the login form as an admin user | testuser | secret | false |
Then I should be redirected to the home page | admin | secret | true |
And I should see "Login successful"
Scenario: Unsuccesfull login Scenario Outline: Succesfull and unsuccesfull login
Given an admin user exists
When I go to the login page When I go to the login page
And I submit the login form as an admin user with an incorrect password And I submit the login form as user "<user>" with password "<password>"
Then I should be on the login page Then I should be <there>
And I should see "Login unsuccessful" And I should see "<message>"
Examples:
| user | password | there | message |
| admin | secret | redirected to the home page | Login successful |
| admin | wrong | on the login page | Login unsuccessful |
Scenario: Accessing a secured page when not logged in Scenario: Accessing a secured page when not logged in
Given an admin user exists
When I go to the home page When I go to the home page
Then I should be redirected to the login page Then I should be redirected to the login page

View file

@ -1,17 +1,22 @@
Feature Show statistics Feature Show statistics
In order to see what I have got done In order to see what I have got done
As an user As an user
I want see my statistic I want see my statistics
Background:
Given the following user record
| login | password | is_admin |
| testuser | secret | false |
Scenario: Show statistics with no history Scenario: Show statistics with no history
Given I am logged in Given I have logged in as "testuser" with password "secret"
And I have no todos And I have no todos
When I go to the statistics page When I go to the statistics page
Then I should see "Totals" Then I should see "Totals"
And I should see " More statistics will appear here once you have added some actions." And I should see " More statistics will appear here once you have added some actions."
Scenario: Show statistics with history Scenario: Show statistics with history
Given I am logged in Given I have logged in as "testuser" with password "secret"
And I have 5 todos And I have 5 todos
And I have 2 deferred todos And I have 2 deferred todos
And I have 2 completed todos And I have 2 completed todos
@ -27,7 +32,7 @@ Feature Show statistics
And I should see "Tags" And I should see "Tags"
Scenario: Click through to see chart of all actions per month Scenario: Click through to see chart of all actions per month
Given I am logged in Given I have logged in as "testuser" with password "secret"
And I have 5 todos And I have 5 todos
When I go to the statistics page When I go to the statistics page
And I click on the chart for actions done in the last 12 months And I click on the chart for actions done in the last 12 months
@ -35,7 +40,7 @@ Feature Show statistics
And I should see "to return to the statistics page" And I should see "to return to the statistics page"
Scenario: Click through to see all incomplete actions of a week Scenario: Click through to see all incomplete actions of a week
Given I am logged in Given I have logged in as "testuser" with password "secret"
And I have 5 todos And I have 5 todos
And I have 2 deferred todos And I have 2 deferred todos
When I go to the statistics page When I go to the statistics page
@ -47,7 +52,7 @@ Feature Show statistics
And I should see "to show the actions from week 0 and further" And I should see "to show the actions from week 0 and further"
Scenario: Click through to see all incomplete visible actions of a week Scenario: Click through to see all incomplete visible actions of a week
Given I am logged in Given I have logged in as "testuser" with password "secret"
And I have 5 todos And I have 5 todos
And I have 3 deferred todos And I have 3 deferred todos
When I go to the statistics page When I go to the statistics page

View file

@ -1,69 +1,14 @@
Given /^I am logged in$/ do Given /^I have logged in as "(.*)" with password "(.*)"$/ do |username, password|
@current_user = User.create!(:login => "testuser", :password => "secret", :password_confirmation => "secret")
@current_user.create_preference
visit login_path visit login_path
fill_in "login", :with => "testuser" fill_in "login", :with => username
fill_in "password", :with => "secret" fill_in "password", :with => password
click_button "Sign in" click_button "Sign in"
response.body.should =~ /Login successful/m response.body.should =~ /Login successful/m
@current_user = User.find_by_login(username)
end end
Given /^public signups are turned (.*)$/ do |state| When /^I submit the login form as user "([^\"]*)" with password "([^\"]*)"$/ do |username, password|
case state fill_in 'Login', :with => username
when 'on' fill_in 'Password', :with => password
SITE_CONFIG['open_signups'] = true
when 'off'
SITE_CONFIG['open_signups'] = false
else
raise "public signups should be either 'on' or 'off'"
end
end
When "I successfully submit the signup form" do
fill_in 'Desired login', :with => 'reinier'
fill_in 'Choose password', :with => 'abracadabra'
fill_in 'Confirm password', :with => 'abracadabra'
click_button click_button
end end
When "I submit signup form with dissimmilar password and confirmation" do
fill_in 'Desired login', :with => 'reinier'
fill_in 'Choose password', :with => 'abracadabra'
fill_in 'Confirm password', :with => 'somethingelse'
click_button
end
Then "I should be an admin" do
# just check on the presence of the menu item for managing users
Then "I should see \"Manage users\""
end
When "I submit the login form as an admin user with an incorrect password" do
Given "an admin user exists"
fill_in 'Login', :with => 'admin'
fill_in 'Password', :with => 'incorrectpass'
click_button
end
When "I successfully submit the login form as an admin user" do
Given "an admin user exists"
fill_in 'Login', :with => 'admin'
fill_in 'Password', :with => 'abracadabra'
click_button
end
When "Reinier visits the site" do
visits '/'
end
Then "Reinier should see the tasks listing page" do
response.should have_tag('title', /list tasks/i)
end
Then "Reinier should see the login page again" do
response.should have_tag('title', /login/i)
end
Then "Reinier should see the message Login unsuccessful" do
should_see 'Login unsuccessful'
end

View file

@ -0,0 +1,17 @@
Given /^public signups are turned (.*)$/ do |state|
case state
when 'on'
SITE_CONFIG['open_signups'] = true
when 'off'
SITE_CONFIG['open_signups'] = false
else
raise "public signups should be either 'on' or 'off'"
end
end
When /^I submit the signup form with username "([^\"]*)", password "([^\"]*)" and confirm with "([^\"]*)"$/ do |username, password, confirm|
fill_in 'Desired login', :with => username
fill_in 'Choose password', :with => password
fill_in 'Confirm password', :with => confirm
click_button
end

View file

@ -1,37 +1,15 @@
Given /^the following user records?$/ do |table|
table.hashes.each do |hash|
user = Factory(:user, hash)
user.create_preference
end
end
Given "no users exists" do Given "no users exists" do
User.delete_all User.delete_all
end end
Given "an admin user exists" do Then "I should be an admin" do
if @admin_user # just check on the presence of the menu item for managing users
@admin_user.destroy Then "I should see \"Manage users\""
end
@admin_user = User.create!(:login => 'admin', :password => 'abracadabra', :password_confirmation => 'abracadabra')
@admin_user.is_admin = true # is_admin is protected in user model
@admin_user.create_preference
@admin_user.preference.save
@admin_user.save
end
Given "an admin user Reinier with the password abracadabra" do
@reinier = User.create!(:login => 'reinier', :password => 'abracadabra', :password_confirmation => 'abracadabra', :is_admin => true)
@reinier.create_preference
end
Given "an admin user Reinier" do
Given "an admin user Reinier with the password abracadabra"
end
Given "a logged in user Luis" do
@luis = User.create!(:login => 'luis', :password => 'sesame', :password_confirmation => 'sesame', :is_admin => false)
@luis.create_preference
logged_in_as @luis
end
Given "Reinier is not logged in" do
#nothing to do
end
Given "a visitor named Reinier" do
#nothing to do
end end

View file

@ -98,6 +98,14 @@ Then /^I should not see "([^\"]*)"$/ do |text|
response.should_not contain(text) response.should_not contain(text)
end end
Then /^the "([^\"]*)" field should contain "([^\"]*)"$/ do |field, value|
field_labeled(field).value.should =~ /#{value}/
end
Then /^the "([^\"]*)" field should not contain "([^\"]*)"$/ do |field, value|
field_labeled(field).value.should_not =~ /#{value}/
end
Then /^the "([^\"]*)" checkbox should be checked$/ do |label| Then /^the "([^\"]*)" checkbox should be checked$/ do |label|
field_labeled(label).should be_checked field_labeled(label).should be_checked
end end

View file

@ -22,7 +22,4 @@ module NavigationHelpers
end end
end end
World do |world| World(NavigationHelpers)
world.extend NavigationHelpers
world
end

6
spec/factories.rb Normal file
View file

@ -0,0 +1,6 @@
Factory.define :user do |u|
u.sequence(:login) { |n| "testuser#{n}" }
u.password "secret"
u.password_confirmation { |user| user.password }
u.is_admin false
end