99 :password_confirmation => password ) . save!
1010end
1111
12- Then /^I should be already signed in$/ do
13- page . should have_content "Logout"
14- end
15-
1612Given /^I am not logged in$/ do
1713 visit '/users/sign_out'
1814end
2521 click_button "Sign in"
2622end
2723
24+ When /^I go to the homepage$/ do
25+ visit '/'
26+ end
27+
2828Then /^I should be signed in$/ do
2929 page . should have_content "Logout"
3030 page . should_not have_content "Sign up"
3131 page . should_not have_content "Login"
3232end
3333
34- When /^I return next time$/ do
35- visit '/'
36- end
37-
3834Then /^I should be signed out$/ do
3935 page . should have_content "Sign up"
4036 page . should have_content "Login"
4541 visit '/users/sign_out'
4642end
4743
48- When /^I go to the sign in page$/ do
49- visit '/users/sign_in'
50- end
51-
5244Then /^I should see "([^"]*)"$/ do |text |
5345 page . should have_content ( text )
5446end
5547
56- Then /^I go to the home page$/ do
57- visit '/'
58- end
59-
6048When /^I press "([^"]*)"$/ do |label |
6149 click_button label
6250end
6553 fill_in ( field , :with => value )
6654end
6755
68- When /^I go to the homepage$/ do
69- visit '/'
70- end
71-
7256When /^I follow "([^"]*)"$/ do |text |
7357 click_link text
7458end
7559
60+ def valid_user
61+ @user ||= { :name => "Testy McUserton" , :email => "testy@userton.com" ,
62+ :password => "please" , :password_confirmation => "please" }
63+ end
64+
7665def sign_up user
7766 visit '/users/sign_up'
7867 fill_in "Name" , :with => user [ :name ]
@@ -83,18 +72,15 @@ def sign_up user
8372end
8473
8574When /^I sign up with valid user data$/ do
86- user = { :name => "Testy McUserton" , :email => "testy@userton.com" ,
87- :password => "please" , :password_confirmation => "please" }
88- sign_up user
75+ sign_up valid_user
8976end
9077
9178Then /^I should see a succesfull sign up message$/ do
9279 page . should have_content "Welcome! You have signed up successfully."
9380end
9481
9582When /^I sign up with an invalid email$/ do
96- user = { :name => "Testy McUserton" , :email => "notanemail" ,
97- :password => "please" , :password_confirmation => "please" }
83+ user = valid_user . merge ( :email => "notanemail" )
9884 sign_up user
9985end
10086
@@ -103,8 +89,7 @@ def sign_up user
10389end
10490
10591When /^I sign up without a password$/ do
106- user = { :name => "Testy McUserton" , :email => "notanemail" ,
107- :password => "" , :password_confirmation => "please" }
92+ user = valid_user . merge ( :password => "" )
10893 sign_up user
10994end
11095
@@ -113,8 +98,7 @@ def sign_up user
11398end
11499
115100When /^I sign up without a confirmed password$/ do
116- user = { :name => "Testy McUserton" , :email => "notanemail" ,
117- :password => "please" , :password_confirmation => "" }
101+ user = valid_user . merge ( :password_confirmation => "" )
118102 sign_up user
119103end
120104
@@ -123,8 +107,7 @@ def sign_up user
123107end
124108
125109When /^I sign up with a mismatched password confirmation$/ do
126- user = { :name => "Testy McUserton" , :email => "notanemail" ,
127- :password => "please" , :password_confirmation => "please123" }
110+ user = valid_user . merge ( :password_confirmation => "please123" )
128111 sign_up user
129112end
130113
@@ -133,9 +116,7 @@ def sign_up user
133116end
134117
135118Given /^I am logged in$/ do
136- user = { :name => "Testy McUserton" , :email => "testy@userton.com" ,
137- :password => "please" , :password_confirmation => "please" }
138- sign_up user
119+ sign_up valid_user
139120end
140121
141122Then /^I should see a signed out message$/ do
@@ -147,22 +128,18 @@ def sign_up user
147128end
148129
149130Given /^I exist as a user$/ do
150- @user = { :name => "Testy McUserton" , :email => "testy@userton.com" ,
151- :password => "please" , :password_confirmation => "please" }
152- sign_up @user
131+ sign_up valid_user
153132 visit '/users/sign_out'
154133end
155134
156135Given /^I do not exist as a user$/ do
157- @user = { :name => "Testy McUserton" , :email => "testy@userton.com" ,
158- :password => "please" , :password_confirmation => "please" }
159- User . find ( :first , :conditions => { :email => @user [ :email ] } ) . should be_nil
136+ User . find ( :first , :conditions => { :email => valid_user [ :email ] } ) . should be_nil
160137 visit '/users/sign_out'
161138end
162139
163140When /^I sign in with a wrong password$/ do
164141 visit '/users/sign_in'
165- fill_in "Email" , :with => @user [ :email ]
142+ fill_in "Email" , :with => valid_user [ :email ]
166143 fill_in "Password" , :with => "wrongpass"
167144 click_button "Sign in"
168145end
@@ -173,8 +150,8 @@ def sign_up user
173150
174151When /^I sign in with valid credintials$/ do
175152 visit '/users/sign_in'
176- fill_in "Email" , :with => @user [ :email ]
177- fill_in "Password" , :with => @user [ :password ]
153+ fill_in "Email" , :with => valid_user [ :email ]
154+ fill_in "Password" , :with => valid_user [ :password ]
178155 click_button "Sign in"
179156end
180157
0 commit comments