Skip to content

Commit 512346a

Browse files
committed
Cleanup steps after sign in feature refactor
1 parent 7bfa087 commit 512346a

File tree

1 file changed

+20
-43
lines changed

1 file changed

+20
-43
lines changed

features/step_definitions/user_steps.rb

Lines changed: 20 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@
99
:password_confirmation => password).save!
1010
end
1111

12-
Then /^I should be already signed in$/ do
13-
page.should have_content "Logout"
14-
end
15-
1612
Given /^I am not logged in$/ do
1713
visit '/users/sign_out'
1814
end
@@ -25,16 +21,16 @@
2521
click_button "Sign in"
2622
end
2723

24+
When /^I go to the homepage$/ do
25+
visit '/'
26+
end
27+
2828
Then /^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"
3232
end
3333

34-
When /^I return next time$/ do
35-
visit '/'
36-
end
37-
3834
Then /^I should be signed out$/ do
3935
page.should have_content "Sign up"
4036
page.should have_content "Login"
@@ -45,18 +41,10 @@
4541
visit '/users/sign_out'
4642
end
4743

48-
When /^I go to the sign in page$/ do
49-
visit '/users/sign_in'
50-
end
51-
5244
Then /^I should see "([^"]*)"$/ do |text|
5345
page.should have_content(text)
5446
end
5547

56-
Then /^I go to the home page$/ do
57-
visit '/'
58-
end
59-
6048
When /^I press "([^"]*)"$/ do |label|
6149
click_button label
6250
end
@@ -65,14 +53,15 @@
6553
fill_in(field, :with => value)
6654
end
6755

68-
When /^I go to the homepage$/ do
69-
visit '/'
70-
end
71-
7256
When /^I follow "([^"]*)"$/ do |text|
7357
click_link text
7458
end
7559

60+
def valid_user
61+
@user ||= { :name => "Testy McUserton", :email => "testy@userton.com",
62+
:password => "please", :password_confirmation => "please"}
63+
end
64+
7665
def sign_up user
7766
visit '/users/sign_up'
7867
fill_in "Name", :with => user[:name]
@@ -83,18 +72,15 @@ def sign_up user
8372
end
8473

8574
When /^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
8976
end
9077

9178
Then /^I should see a succesfull sign up message$/ do
9279
page.should have_content "Welcome! You have signed up successfully."
9380
end
9481

9582
When /^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
9985
end
10086

@@ -103,8 +89,7 @@ def sign_up user
10389
end
10490

10591
When /^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
10994
end
11095

@@ -113,8 +98,7 @@ def sign_up user
11398
end
11499

115100
When /^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
119103
end
120104

@@ -123,8 +107,7 @@ def sign_up user
123107
end
124108

125109
When /^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
129112
end
130113

@@ -133,9 +116,7 @@ def sign_up user
133116
end
134117

135118
Given /^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
139120
end
140121

141122
Then /^I should see a signed out message$/ do
@@ -147,22 +128,18 @@ def sign_up user
147128
end
148129

149130
Given /^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'
154133
end
155134

156135
Given /^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'
161138
end
162139

163140
When /^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"
168145
end
@@ -173,8 +150,8 @@ def sign_up user
173150

174151
When /^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"
179156
end
180157

0 commit comments

Comments
 (0)