Skip to content

Commit

Permalink
with dependency on cucumber's web_steps, paths, and selectors gone, w…
Browse files Browse the repository at this point in the history
…e need to use more capybara directly in the step definitions and use higher-level steps to describe what actions we're taking
  • Loading branch information
Dan Croak committed Oct 10, 2011
1 parent bb2e919 commit e01f366
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 113 deletions.
34 changes: 11 additions & 23 deletions features/engine/visitor_resets_password.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,48 +5,36 @@ Feature: Password reset
I want to reset my password

Scenario: User is not signed up
Given no user exists with an email of "email@example.com"
When I request password reset link to be sent to "email@example.com"
Then I should see "Unknown email"
When I reset the password for "unknown.email@example.com"
Then I am told email is unknown

Scenario: User is signed up and requests password reset
Given I signed up with "email@example.com"
When I request password reset link to be sent to "email@example.com"
Then I should see "instructions for changing your password"
And a password reset message should be sent to "email@example.com"
When I reset the password for "email@example.com"
Then instructions for changing my password are emailed to "email@example.com"

Scenario: User tries to reset his password with a blank password
Given I signed up with "email@example.com"
And I go to the password reset request page
Then I should see an email field
And I fill in "Email address" with "email@example.com"
And I press "Reset password"
When I follow the password reset link sent to "email@example.com"
When I reset the password for "email@example.com"
And I follow the password reset link sent to "email@example.com"
And I update my password with ""
Then I should see "Password can't be blank."
Then I am told to enter a password
And I should be signed out

Scenario: User is signed up and updates his password
Given I signed up with "email@example.com"
And I go to the password reset request page
And I fill in "Email address" with "email@example.com"
And I press "Reset password"
When I follow the password reset link sent to "email@example.com"
When I reset the password for "email@example.com"
And I follow the password reset link sent to "email@example.com"
And I update my password with "newpassword"
Then I should be signed in
When I sign out
Then I should be signed out
When I go to the sign in page
And I fill in "Email" with "email@example.com"
And I fill in "Password" with "newpassword"
And I press "Sign in"
When I sign in with "email@example.com" and "newpassword"
Then I should be signed in

Scenario: User who was created before Clearance was installed creates password for first time
Given a user "email@example.com" exists without a salt, remember token, or password
When I go to the password reset request page
And I fill in "Email address" with "email@example.com"
And I press "Reset password"
When I reset the password for "email@example.com"
When I follow the password reset link sent to "email@example.com"
And I update my password with "newpassword"
Then I should be signed in
Expand Down
20 changes: 6 additions & 14 deletions features/engine/visitor_signs_in.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,22 @@ Feature: Sign in
I want to sign in

Scenario: Visitor is not signed up
Given no user exists with an email of "email@example.com"
When I go to the sign in page
And I sign in as "email@example.com"
Then I should see "Bad email or password"
When I sign in as "unknown.email@example.com"
Then I am told email or password is bad
And I should be signed out

Scenario: Visitor enters wrong password
Given I am signed up as "email@example.com"
When I go to the sign in page
And I fill in "Email" with "email@example.com"
And I fill in "Password" with "badpassword"
And I press "Sign in"
Then I should see "Bad email or password"
When I sign in as "email@example.com" and "badpassword"
Then I am told email or password is bad
And I should be signed out

Scenario: Visitor signs in successfully
Given I am signed up as "email@example.com"
When I go to the sign in page
Then I should see an email field
And I sign in as "email@example.com"
When I sign in as "email@example.com"
Then I should be signed in

Scenario: Visitor signs in successfully with uppercase email
Given I am signed up as "email@example.com"
When I go to the sign in page
And I sign in as "Email@example.com"
When I sign in as "Email@example.com"
Then I should be signed in
2 changes: 1 addition & 1 deletion features/engine/visitor_signs_out.feature
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ Feature: Sign out
Given I am signed up as "email@example.com"
When I sign in as "email@example.com"
Then I should be signed in
And I sign out
When I sign out
Then I should be signed out
22 changes: 6 additions & 16 deletions features/engine/visitor_signs_up.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,14 @@ Feature: Sign up
As a visitor
I want to sign up

Background:
When I go to the sign up page
Then I should see an email field

Scenario: Visitor signs up with invalid email
When I fill in "Email" with "invalidemail"
And I fill in "Password" with "password"
And I press "Sign up"
Then I should see "Must be a valid email address"
When I sign up with "invalidemail" and "password"
Then I am told to enter a valid email address

Scenario: Visitor signs up with blank password
When I fill in "Email" with "email@example.com"
And I fill in "Password" with ""
And I press "Sign up"
Then I should see "Password can't be blank"
When I sign up with "email@example.com" and ""
Then I am told to enter a password

Scenario: Visitor signs up with valid data
When I fill in "Email" with "email@example.com"
And I fill in "Password" with "password"
And I press "Sign up"
Then I should be on the home page
When I sign up with "email@example.com" and "password"
Then I should be signed in
133 changes: 74 additions & 59 deletions features/step_definitions/engine/clearance_steps.rb
Original file line number Diff line number Diff line change
@@ -1,63 +1,70 @@
# General
# Existing users

Then /^I should see error messages$/ do
Then %{I should see "errors prohibited"}
Given /^(?:I am|I have|I) signed up (?:as|with) "(.*)"$/ do |email|
Factory(:user, :email => email)
end

Then /^I should see an error message$/ do
Then %{I should see "error prohibited"}
Given /^a user "([^"]*)" exists without a salt, remember token, or password$/ do |email|
user = Factory(:user, :email => email)
sql = "update users set salt = NULL, encrypted_password = NULL, remember_token = NULL where id = #{user.id}"
ActiveRecord::Base.connection.update(sql)
end

Then /^I should see an email field$/ do
if page.respond_to?(:should)
page.should have_css("input[type='email']")
else
assert page.has_css("input[type='email']")
end
end
# Sign up

# Database
When /^I sign up (?:with|as) "(.*)" and "(.*)"$/ do |email, password|
visit sign_up_path
page.should have_css("input[type='email']")

Given /^no user exists with an email of "(.*)"$/ do |email|
assert_nil User.find_by_email(email)
fill_in "Email", :with => email
fill_in "Password", :with => password
click_button "Sign up"
end

Given /^(?:I am|I have|I) signed up (?:as|with) "(.*)"$/ do |email|
Factory(:user, :email => email)
# Sign in

Given /^I sign in$/ do
email = Factory.next(:email)
steps %{
I have signed up with "#{email}"
I sign in with "#{email}"
}
end

Given /^a user "([^"]*)" exists without a salt, remember token, or password$/ do |email|
user = Factory(:user, :email => email)
sql = "update users set salt = NULL, encrypted_password = NULL, remember_token = NULL where id = #{user.id}"
ActiveRecord::Base.connection.update(sql)
When /^I sign in (?:with|as) "([^"]*)"$/ do |email|
When %{I sign in with "#{email}" and "password"}
end

# Session
When /^I sign in (?:with|as) "([^"]*)" and "([^"]*)"$/ do |email, password|
visit sign_in_path
page.should have_css("input[type='email']")

Then /^I should be signed in$/ do
Given %{I am on the homepage}
Then %{I should see "Sign out"}
fill_in "Email", :with => email
fill_in "Password", :with => password
click_button "Sign in"
end

Then /^I should be signed out$/ do
Given %{I am on the homepage}
Then %{I should see "Sign in"}
end
# Sign out

Given /^(?:I am|I have|I) signed in (?:with|as) "(.*)"$/ do |email|
Given %{I am signed up as "#{email}"}
And %{I sign in as "#{email}"}
When "I sign out" do
visit "/"
click_link "Sign out"
end

Given /^I sign in$/ do
email = Factory.next(:email)
Given %{I have signed in with "#{email}"}
# Reset password

When /^I reset the password for "(.*)"$/ do |email|
visit new_password_path
page.should have_css("input[type='email']")

fill_in "Email address", :with => email
click_button "Reset password"
end

# Emails
Then /^instructions for changing my password are emailed to "(.*)"$/ do |email|
page.should have_content("instructions for changing your password")

Then /^a password reset message should be sent to "(.*)"$/ do |email|
user = User.find_by_email(email)
user = User.find_by_email!(email)
assert !user.confirmation_token.blank?
assert !ActionMailer::Base.deliveries.empty?
result = ActionMailer::Base.deliveries.any? do |email|
Expand All @@ -69,39 +76,47 @@
end

When /^I follow the password reset link sent to "(.*)"$/ do |email|
user = User.find_by_email(email)
user = User.find_by_email!(email)
visit edit_user_password_path(:user_id => user,
:token => user.confirmation_token)
end

When /^I try to change the password of "(.*)" without token$/ do |email|
user = User.find_by_email(email)
When /^I change the password of "(.*)" without token$/ do |email|
user = User.find_by_email!(email)
visit edit_user_password_path(:user_id => user)
end

# Actions
When /^I update my password with "(.*)"$/ do |password|
fill_in "Choose password", :with => password
click_button "Save this password"
end

When /^I sign in (?:with|as) "(.*)"$/ do |email|
When %{I go to the sign in page}
And %{I fill in "Email" with "#{email}"}
And %{I fill in "Password" with "password"}
And %{I press "Sign in"}
# Flashes

Then /^I am told email or password is bad$/ do
page.should have_content("Bad email or password")
end

When "I sign out" do
steps %{
When I go to the homepage
And I follow "Sign out"
}
Then /^I am told email is unknown$/ do
page.should have_content("Unknown email")
end

When /^I request password reset link to be sent to "(.*)"$/ do |email|
When %{I go to the password reset request page}
And %{I fill in "Email address" with "#{email}"}
And %{I press "Reset password"}
Then /^I am told to enter a valid email address$/ do
page.should have_content("Must be a valid email address")
end

When /^I update my password with "(.*)"$/ do |password|
And %{I fill in "Choose password" with "#{password}"}
And %{I press "Save this password"}
Then /^I am told to enter a password$/ do
page.should have_content("Password can't be blank")
end

# Verification

Then /^I should be signed in$/ do
visit "/"
page.should have_content "Sign out"
end

Then /^I should be signed out$/ do
visit "/"
page.should have_content "Sign in"
end

0 comments on commit e01f366

Please sign in to comment.