Permalink
Browse files

Finish sign in

  • Loading branch information...
1 parent 3cad611 commit 518bd0290a1e243cdeec579e4265928a1891c104 Jason Kim committed Mar 16, 2012
Showing with 56 additions and 0 deletions.
  1. +13 −0 features/signing_in.feature
  2. +31 −0 features/step_definitions/authentication_steps.rb
  3. +12 −0 spec/support/utilities.rb
@@ -0,0 +1,13 @@
+Feature: Signing in
+
+ Scenario: Unsuccessful signin
+ Given a user visits the signin page
+ When he submits invalid signin information
+ Then he should see an error message
+
+ Scenario: Successful signin
+ Given a user visits the signin page
+ And the user has an account
+ And the user submits valid signin information
+ Then he should see his profile page
+ And he should see a signout link
@@ -0,0 +1,31 @@
+Given /^a user visits the signin page$/ do
+ visit signin_path
+end
+
+When /^he submits invalid signin information$/ do
+ click_button "Sign in"
+end
+
+Then /^he should see an error message$/ do
+ page.should have_selector('div.alert.alert-error')
+end
+
+Given /^the user has an account$/ do
+ @user = User.create(name: "Example User", email: "user@example.com",
+ password: "foobar", password_confirmation: "foobar")
+end
+
+When /^the user submits valid signin information$/ do
+ visit signin_path
+ fill_in "Email", with: @user.email
+ fill_in "Password", with: @user.password
+ click_button "Sign in"
+end
+
+Then /^he should see his profile page$/ do
+ page.should have_selector('title', text: @user.name)
+end
+
+Then /^he should see a signout link$/ do
+ page.should have_link('Sign out', href: signout_path)
+end
View
@@ -5,4 +5,16 @@ def full_title(page_title)
else
"#{base_title} | #{page_title}"
end
+end
+
+def valid_signin(user)
+ fill_in "Email", with: user.email
+ fill_in "Password", with: user.password
+ click_button "Sign in"
+end
+
+RSpec::Matchers.define :have_error_message do |message|
+ match do |page|
+ page.should have_selector('div.alert.alert-error', text: message)
+ end
end

0 comments on commit 518bd02

Please sign in to comment.