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
config.gem "flexmock"
config.gem "ZenTest"
config.gem "ZenTest", :lib => "zentest"
config.gem "hpricot"
config.gem "hoe"
@ -55,4 +55,5 @@ config.gem "hoe"
# the rspec.task file
config.gem "rspec-rails", :lib => false, :version => ">=1.2.2"
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

@ -3,30 +3,34 @@ Feature: Signup new users
In order to be able to administer Tracks
As a user who just installed Tracks
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
Given no users exists
When I go to the homepage
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
And I should be an admin
Scenario: Signup should be refused when password and confirmation is not the same
Given no users exists
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
And I should see "Password doesn't match confirmation"
Scenario: With public signups turned off, signup should be refused when an admin user exists
Given public signups are turned off
And an admin user exists
When I go to the signup page
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
Given public signups are turned on
And an admin user exists
When I go to the signup page
Then I should see "Sign up a new user"

View file

@ -3,23 +3,24 @@ Feature: Existing user logging in
In order to keep my things private
As an existing user
I want to log in with my username and password
Scenario: Succesfull login
Given an admin user exists
Background:
Given the following user records
| login | password | is_admin |
| testuser | secret | false |
| admin | secret | true |
Scenario Outline: Succesfull and unsuccesfull login
When I go to the login page
And I successfully submit the login form as an admin user
Then I should be redirected to the home page
And I should see "Login successful"
Scenario: Unsuccesfull login
Given an admin user exists
When I go to the login page
And I submit the login form as an admin user with an incorrect password
Then I should be on the login page
And I should see "Login unsuccessful"
And I submit the login form as user "<user>" with password "<password>"
Then I should be <there>
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
Given an admin user exists
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
In order to see what I have got done
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
Given I am logged in
Given I have logged in as "testuser" with password "secret"
And I have no todos
When I go to the statistics page
Then I should see "Totals"
And I should see " More statistics will appear here once you have added some actions."
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 2 deferred todos
And I have 2 completed todos
@ -27,7 +32,7 @@ Feature Show statistics
And I should see "Tags"
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
When I go to the statistics page
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"
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 2 deferred todos
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"
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 3 deferred todos
When I go to the statistics page

View file

@ -1,69 +1,14 @@
Given /^I am logged in$/ do
@current_user = User.create!(:login => "testuser", :password => "secret", :password_confirmation => "secret")
@current_user.create_preference
Given /^I have logged in as "(.*)" with password "(.*)"$/ do |username, password|
visit login_path
fill_in "login", :with => "testuser"
fill_in "password", :with => "secret"
fill_in "login", :with => username
fill_in "password", :with => password
click_button "Sign in"
response.body.should =~ /Login successful/m
@current_user = User.find_by_login(username)
end
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 successfully submit the signup form" do
fill_in 'Desired login', :with => 'reinier'
fill_in 'Choose password', :with => 'abracadabra'
fill_in 'Confirm password', :with => 'abracadabra'
When /^I submit the login form as user "([^\"]*)" with password "([^\"]*)"$/ do |username, password|
fill_in 'Login', :with => username
fill_in 'Password', :with => password
click_button
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
User.delete_all
end
Given "an admin user exists" do
if @admin_user
@admin_user.destroy
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
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

View file

@ -98,6 +98,14 @@ Then /^I should not see "([^\"]*)"$/ do |text|
response.should_not contain(text)
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|
field_labeled(label).should be_checked
end

View file

@ -14,4 +14,4 @@ Webrat.configure do |config|
end
require 'cucumber/rails/rspec'
require 'webrat/core/matchers'
require 'webrat/core/matchers'

View file

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

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