This covers just auth-related app-level features, atm. I have it set up now, so when anyone else writes a new feature or scenario that requires login, they can reuse the bits in here (as in, reference them not duplicate). There may be some tweaking needed for that as we go forward, but this should be a good starting point. Eventually we will probably use cucmber features in place of most or all of the rspec controller tests, as that is a current area of duplication.
Tests can be run from the src directory with either: cucumber or rake cucumber --- src/features/authentication.feature | 51 +++++++++++++++++++++++ src/features/step_definitions/authentication.rb | 37 ++++++++++++++++ src/features/support/paths.rb | 18 ++++++++ 3 files changed, 106 insertions(+), 0 deletions(-) create mode 100644 src/features/authentication.feature create mode 100644 src/features/step_definitions/authentication.rb
diff --git a/src/features/authentication.feature b/src/features/authentication.feature new file mode 100644 index 0000000..2ee925c --- /dev/null +++ b/src/features/authentication.feature @@ -0,0 +1,51 @@ +Feature: User authentication + In order to access the site + As a user + I must register and log in + + Scenario: Register as new user + Given I am on the homepage + When I follow "Register" + Then I should be on the new account page + When I fill in the following: + | login | testuser | + | email | testuser@example.com | + | password | secret | + | password confirmation | secret | + And I press "Register" + Then I should be on the account page + And I should see "User registered!" + + Scenario: Log in as registered user + Given I am a registered user + And I am on the login page + When I login + Then I should see "Login successful!" + And I should be on the account page + + Scenario: Log in without password + Given I am a registered user + And I am on the login page + When I forget to enter my password + Then I should see "Password cannot be blank" + And I should be on the login error page + + Scenario: Edit profile + Given I am logged in + And I am on the homepage + When I want to edit my profile + And I follow "Edit" + Then I should see "Edit My Profile" + When I fill in "email" with "changed@example.com" + And I press "Update" + Then I should be on the account page + And I should see "User updated!" + + Scenario: log out + Given I am logged in + And I am on the homepage + When I follow "Log out" + Then I should be logged out + And I should see "Logout successful!" + And I should see "Register" + And I should see "Login" diff --git a/src/features/step_definitions/authentication.rb b/src/features/step_definitions/authentication.rb new file mode 100644 index 0000000..6f45e90 --- /dev/null +++ b/src/features/step_definitions/authentication.rb @@ -0,0 +1,37 @@ +def user + @user ||= Factory :user +end + +def login(login, password) + user + visit path_to("the login page") + fill_in "Login", :with => login + fill_in "Password", :with => password + click_button "Login" +end + +Given /^I am a registered user$/ do + user +end + +When /^I login$/ do + login(user.login, user.password) +end + +Given /^I am logged in$/ do + login(user.login, user.password) + UserSession.find.should_not == nil +end + +When /^I forget to enter my password$/ do + login(user.login, nil) +end + +When /^I want to edit my profile$/ do + click_link "Hi, #{user.login}" + response.should contain("User Profile for #{user.login}") +end + +Then /^I should be logged out$/ do + UserSession.find.should == nil +end diff --git a/src/features/support/paths.rb b/src/features/support/paths.rb index e79cd9d..87497ab 100644 --- a/src/features/support/paths.rb +++ b/src/features/support/paths.rb @@ -11,6 +11,24 @@ module NavigationHelpers when /the home\s?page/ '/'
+ when /the new account page/ + register_path + + when /the provider list page/ + '/' + + when /the login page/ + login_path + + when /the account page/ + account_path + + when /the login error page/ + user_session_path + + when /the new provider page/ + new_provider_path + # Add more mappings here. # Here is an example that pulls values out of the Regexp: #