Skip to content

Instantly share code, notes, and snippets.

@ehosick
Created March 14, 2011 08:49
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save ehosick/868903 to your computer and use it in GitHub Desktop.
Save ehosick/868903 to your computer and use it in GitHub Desktop.
Devise Behavior Driven Development (BDD) Features using cucumber, pickle, machinist
# Note: This does not yet align 100% with out of the box devise. I will work on that.
Feature: Authentication
In order to protect my assets stored within a system
As any user
I would like to be verified as the rightful owner of those assets through authentication
Scenario: No authenticated user within the system
Given a user exists with email: "someuser@someuser.com"
And I am not authenticated
When I go to the home page
Then I should not see "Signed in as someuser@somewhere.com."
And I should see "Authenticate"
And I should see "Sign in"
And I should not see "Sign up"
Scenario: An authenticated user within the system
Given a user exists with email: "someuser@someuser.com", password: "somepassword"
And I am not authenticated
When I go to the sign in page
Then I should not see "Sign up"
And I should see "Forgot your password?"
When I fill in "user_email" with "someuser@someuser.com"
And I fill in "user_password" with "somepassword"
And I press "Sign in"
Then I should see "Signed in as someuser@someuser.com."
And I should not see "Sign in"
Scenario: Sign in but wrong password and no email address
Given I am not authenticated
When I go to the sign in page
And I fill in "user_email" with "someuser@someuser.com"
And I fill in "user_password" with "somepassword"
And I press "Sign in"
Then I should see "Invalid email or password."
And I should not see "Signed in as someuser@someuser.com."
And the "user_password" field should equal ""
And the "user_email" field should equal "someuser@someuser.com"
# Make sure a user is not logged in
Given(/^I am not authenticated$/) do
visit('/users/sign_out')
end
Feature: User creation
In order to protect my assets stored within a system and always have access
As any user
I would like to be added as a user of the system in case I can no longer be authenticated via a 3rd party Open ID
Scenario: Create a new account
Given I am not authenticated
When I go to the sign up page
And I fill in "user_email" with "somenewuser@someuser.com"
And I fill in "user_password" with "somepassword"
And I fill in "user_password_confirmation" with "somepassword"
And I press "Sign up"
Then I should see "Signed in as somenewuser@someuser.com"
And I should see "Welcome! You have signed up successfully."
And I should not see "Sign in"
Scenario: Create a new account but the email exists
Given I am not authenticated
And a user exists with email: "somenewuser@someuser.com"
When I go to the sign up page
And I fill in "user_email" with "somenewuser@someuser.com"
And I fill in "user_password" with "somepassword"
And I fill in "user_password_confirmation" with "somepassword"
And I press "Sign up"
Then I should see "Email has already been taken"
And I should see "1 error prohibited this user from being saved:"
Scenario: Create a new account but the email exists and password is too short
Given I am not authenticated
And a user exists with email: "somenewuser@someuser.com"
When I go to the sign up page
And I fill in "user_email" with "somenewuser@someuser.com"
And I fill in "user_password" with "a"
And I fill in "user_password_confirmation" with "a"
And I press "Sign up"
Then I should see "Email has already been taken"
And I should see "Password is too short (minimum is 6 characters)"
And I should see "2 errors prohibited this user from being saved:"
Scenario: Create a new account but the input fields are blank
Given I am not authenticated
And a user exists with email: "somenewuser@someuser.com"
When I go to the sign up page
And I press "Sign up"
Then I should see "Email can't be blank"
And I should see "Password can't be blank"
And I should see "2 errors prohibited this user from being saved:"
Feature: Forget password
In order to gain access to assets stored within a system
As any user
I would like to be able to get a new password if I forget my password
# TODO: Check passwords are not the same
Scenario: Forgot password and email is found
Given I am not authenticated
And all email has been delivered
And a user exists with email: "someuser@someuser.com", password: "somePassword"
And I go to the forgot password page
When I fill in "user_email" with "someuser@someuser.com"
And I press "Send me reset password instructions"
Then I should see "You will receive an email with instructions about how to reset your password in a few minutes."
And 1 email should be delivered to someuser@someuser.com
And the email should contain "Hello someuser@someuser.com!"
And show me the emails
When I click the first link in the email
Then I should see "Change your password"
And I should see "Sign in"
And I should not see "Sign up"
When I fill in "user_password" with "some_new_password"
And I fill in "user_password_confirmation" with "some_new_password"
And I press "Change my password"
Then I should not see "Reset password token is invalid"
Given I am not authenticated
When I go to the sign in page
And I fill in "user_email" with "someuser@someuser.com"
And I fill in "user_password" with "some_new_password"
And I press "Sign in"
Then I should see "Signed in as someuser@someuser.com."
#TODO: Should change error message for this one
Scenario: Forgot password email is blank
Given I am not authenticated
And I go to the forgot password page
Then I should see "Forgot your password?"
When I press "Send me reset password instructions"
Then I should see "Email can't be blank"
And I should see "1 error prohibited this user from being saved:"
Scenario: Forgot password and email not found
Given I am not authenticated
And I go to the forgot password page
When I fill in "user_email" with "somenewuser@someuser.com"
And I press "Send me reset password instructions"
Then I should see "Email not found"
Scenario: Forgot password and email not found
Given I am not authenticated
And I go to the forgot password page
When I fill in "user_email" with "somenewuser@someuser.com"
And I press "Send me reset password instructions"
Then I should see "Email not found"
# Don't overwrite this paths.rb with your paths.rb. Add the stuff below to your paths.rb file.
when /the authentications\s?page/
'/authentications'
when /the sign in\s?page/
'/users/sign_in'
when /the sign up\s?page/
'/users/sign_up'
when /the forgot password\s?page/
'/users/password/new'
Then /^the "([^"]*)" field(?: within "([^"]*)")? should equal "([^"]*)"$/ do |field, selector, value|
with_scope(selector) do
field = find_field(field)
field_value = (field.tag_name == 'textarea') ? field.text : field.value
field_value = "" if field_value.nil?
assert_match(/#{value}/, field_value)
end
end
Then /^the "([^"]*)" field(?: within "([^"]*)")? should not equal "([^"]*)"$/ do |field, selector, value|
with_scope(selector) do
field = find_field(field)
field_value = (field.tag_name == 'textarea') ? field.text : field.value
field_value = "" if field_value.nil?
assert_no_match(/#{value}/, field_value)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment