migrate login stories to cucumber features

This commit is contained in:
Reinier Balt 2009-04-17 08:56:11 +02:00
parent 7bdd365ff3
commit 6d1f034111
10 changed files with 166 additions and 122 deletions

View file

@ -7,3 +7,63 @@ Given /^I am logged in$/ do
click_button "Sign in"
response.body.should =~ /Login successful/m
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'
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,6 @@
Then /^I should be redirected to (.+?)$/ do |page_name|
request.headers['HTTP_REFERER'].should_not be_nil
request.headers['HTTP_REFERER'].should_not == request.request_uri
Then "I should be on #{page_name}"
end

View file

@ -0,0 +1,37 @@
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