Skip to content

Commit 8663abf

Browse files
committed
Orginize step definitions
1 parent 2222df1 commit 8663abf

File tree

1 file changed

+77
-71
lines changed

1 file changed

+77
-71
lines changed

features/step_definitions/user_steps.rb

Lines changed: 77 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,4 @@
1-
Given /^I am not logged in$/ do
2-
visit '/users/sign_out'
3-
end
4-
5-
Then /^I should be signed in$/ do
6-
page.should have_content "Logout"
7-
page.should_not have_content "Sign up"
8-
page.should_not have_content "Login"
9-
end
10-
11-
Then /^I should be signed out$/ do
12-
page.should have_content "Sign up"
13-
page.should have_content "Login"
14-
page.should_not have_content "Logout"
15-
end
16-
17-
Then /^I sign out$/ do
18-
visit '/users/sign_out'
19-
end
20-
1+
### UTILITY METHODS ###
212
def valid_user
223
@user ||= { :name => "Testy McUserton", :email => "testy@userton.com",
234
:password => "please", :password_confirmation => "please"}
@@ -32,107 +13,132 @@ def sign_up user
3213
click_button "Sign up"
3314
end
3415

35-
When /^I sign up with valid user data$/ do
16+
def sign_in user
17+
visit '/users/sign_in'
18+
fill_in "Email", :with => user[:email]
19+
fill_in "Password", :with => user[:password]
20+
click_button "Sign in"
21+
end
22+
23+
### GIVEN ###
24+
Given /^I am not logged in$/ do
25+
visit '/users/sign_out'
26+
end
27+
28+
Given /^I am logged in$/ do
3629
sign_up valid_user
3730
end
3831

39-
Then /^I should see a succesfull sign up message$/ do
40-
page.should have_content "Welcome! You have signed up successfully."
32+
Given /^I exist as a user$/ do
33+
sign_up valid_user
34+
visit '/users/sign_out'
4135
end
4236

43-
When /^I sign up with an invalid email$/ do
44-
user = valid_user.merge(:email => "notanemail")
45-
sign_up user
37+
Given /^I do not exist as a user$/ do
38+
User.find(:first, :conditions => { :email => valid_user[:email] }).should be_nil
39+
visit '/users/sign_out'
4640
end
4741

48-
Then /^I should see an invalid email message$/ do
49-
page.should have_content "Email is invalid"
42+
### WHEN ###
43+
When /^I sign out$/ do
44+
visit '/users/sign_out'
5045
end
5146

52-
When /^I sign up without a password$/ do
53-
user = valid_user.merge(:password => "")
54-
sign_up user
47+
When /^I sign up with valid user data$/ do
48+
sign_up valid_user
5549
end
5650

57-
Then /^I should see a missing password message$/ do
58-
page.should have_content "Password can't be blank"
51+
When /^I sign up with an invalid email$/ do
52+
user = valid_user.merge(:email => "notanemail")
53+
sign_up user
5954
end
6055

6156
When /^I sign up without a confirmed password$/ do
6257
user = valid_user.merge(:password_confirmation => "")
6358
sign_up user
6459
end
6560

66-
Then /^I should see a missing password confirmation message$/ do
67-
page.should have_content "Password doesn't match confirmation"
61+
When /^I sign up without a password$/ do
62+
user = valid_user.merge(:password => "")
63+
sign_up user
6864
end
6965

7066
When /^I sign up with a mismatched password confirmation$/ do
7167
user = valid_user.merge(:password_confirmation => "please123")
7268
sign_up user
7369
end
7470

75-
Then /^I should see a mismatched password message$/ do
76-
page.should have_content "Password doesn't match confirmation"
71+
When /^I return to the site$/ do
72+
visit '/'
7773
end
7874

79-
Given /^I am logged in$/ do
80-
sign_up valid_user
75+
When /^I sign in with a wrong password$/ do
76+
user = valid_user.merge(:password => "wrongpass")
77+
sign_in user
8178
end
8279

83-
Then /^I should see a signed out message$/ do
84-
page.should have_content "Signed out"
80+
When /^I sign in with valid credintials$/ do
81+
sign_in valid_user
8582
end
8683

87-
When /^I return to the site$/ do
84+
When /^I edit my account details$/ do
85+
click_link "Edit account"
86+
fill_in "Name", :with => "newname"
87+
fill_in "Current password", :with => valid_user[:password]
88+
click_button "Update"
89+
end
90+
91+
When /^I look at the list of users$/ do
8892
visit '/'
8993
end
9094

91-
Given /^I exist as a user$/ do
92-
sign_up valid_user
93-
visit '/users/sign_out'
95+
### THEN ###
96+
Then /^I should be signed in$/ do
97+
page.should have_content "Logout"
98+
page.should_not have_content "Sign up"
99+
page.should_not have_content "Login"
94100
end
95101

96-
Given /^I do not exist as a user$/ do
97-
User.find(:first, :conditions => { :email => valid_user[:email] }).should be_nil
98-
visit '/users/sign_out'
102+
Then /^I should be signed out$/ do
103+
page.should have_content "Sign up"
104+
page.should have_content "Login"
105+
page.should_not have_content "Logout"
99106
end
100107

101-
When /^I sign in with a wrong password$/ do
102-
visit '/users/sign_in'
103-
fill_in "Email", :with => valid_user[:email]
104-
fill_in "Password", :with => "wrongpass"
105-
click_button "Sign in"
108+
Then /^I should see a succesfull sign up message$/ do
109+
page.should have_content "Welcome! You have signed up successfully."
106110
end
107111

108-
Then /^I see an invalid login message$/ do
109-
page.should have_content "Invalid email or password."
112+
Then /^I should see an invalid email message$/ do
113+
page.should have_content "Email is invalid"
110114
end
111115

112-
When /^I sign in with valid credintials$/ do
113-
visit '/users/sign_in'
114-
fill_in "Email", :with => valid_user[:email]
115-
fill_in "Password", :with => valid_user[:password]
116-
click_button "Sign in"
116+
Then /^I should see a missing password message$/ do
117+
page.should have_content "Password can't be blank"
117118
end
118119

119-
Then /^I see a successfull sign in message$/ do
120-
page.should have_content "Signed in successfully."
120+
Then /^I should see a missing password confirmation message$/ do
121+
page.should have_content "Password doesn't match confirmation"
121122
end
122123

123-
When /^I edit my account details$/ do
124-
click_link "Edit account"
125-
fill_in "Name", :with => "newname"
126-
fill_in "Current password", :with => valid_user[:password]
127-
click_button "Update"
124+
Then /^I should see a mismatched password message$/ do
125+
page.should have_content "Password doesn't match confirmation"
128126
end
129127

130-
Then /^I should see an account edited message$/ do
131-
page.should have_content "You updated your account successfully."
128+
Then /^I should see a signed out message$/ do
129+
page.should have_content "Signed out"
132130
end
133131

134-
When /^I look at the list of users$/ do
135-
visit '/'
132+
Then /^I see an invalid login message$/ do
133+
page.should have_content "Invalid email or password."
134+
end
135+
136+
Then /^I see a successfull sign in message$/ do
137+
page.should have_content "Signed in successfully."
138+
end
139+
140+
Then /^I should see an account edited message$/ do
141+
page.should have_content "You updated your account successfully."
136142
end
137143

138144
Then /^I should see my name$/ do

0 commit comments

Comments
 (0)