|
1 | | -Given /^no user exists with an email of "(.*)"$/ do |email| |
2 | | - User.find(:first, :conditions => { :email => email }).should be_nil |
| 1 | +### UTILITY METHODS ### |
| 2 | +def valid_user |
| 3 | + @user ||= { :name => "Testy McUserton", :email => "testy@userton.com", |
| 4 | + :password => "please", :password_confirmation => "please"} |
3 | 5 | end |
4 | 6 |
|
5 | | -Given /^I am a user named "([^"]*)" with an email "([^"]*)" and password "([^"]*)"$/ do |name, email, password| |
6 | | - User.new(:name => name, |
7 | | - :email => email, |
8 | | - :password => password, |
9 | | - :password_confirmation => password).save! |
| 7 | +def sign_up user |
| 8 | + visit '/users/sign_up' |
| 9 | + fill_in "Name", :with => user[:name] |
| 10 | + fill_in "Email", :with => user[:email] |
| 11 | + fill_in "Password", :with => user[:password] |
| 12 | + fill_in "Password confirmation", :with => user[:password_confirmation] |
| 13 | + click_button "Sign up" |
10 | 14 | end |
11 | 15 |
|
12 | | -Then /^I should be already signed in$/ do |
13 | | - step %{I should see "Logout"} |
| 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" |
14 | 21 | end |
15 | 22 |
|
16 | | -Given /^I am signed up as "(.*)\/(.*)"$/ do |email, password| |
17 | | - step %{I am not logged in} |
18 | | - step %{I go to the sign up page} |
19 | | - step %{I fill in "Email" with "#{email}"} |
20 | | - step %{I fill in "Password" with "#{password}"} |
21 | | - step %{I fill in "Password confirmation" with "#{password}"} |
22 | | - step %{I press "Sign up"} |
23 | | - step %{I should see "You have signed up successfully. If enabled, a confirmation was sent to your e-mail."} |
24 | | - step %{I am logout} |
| 23 | +### GIVEN ### |
| 24 | +Given /^I am not logged in$/ do |
| 25 | + visit '/users/sign_out' |
25 | 26 | end |
26 | 27 |
|
27 | | -Given /^I am logout$/ do |
28 | | - step %{I sign out} |
| 28 | +Given /^I am logged in$/ do |
| 29 | + sign_up valid_user |
29 | 30 | end |
30 | 31 |
|
31 | | -Given /^I am not logged in$/ do |
32 | | - step %{I sign out} |
| 32 | +Given /^I exist as a user$/ do |
| 33 | + sign_up valid_user |
| 34 | + visit '/users/sign_out' |
33 | 35 | end |
34 | 36 |
|
35 | | -When /^I sign in as "(.*)\/(.*)"$/ do |email, password| |
36 | | - step %{I am not logged in} |
37 | | - step %{I go to the sign in page} |
38 | | - step %{I fill in "Email" with "#{email}"} |
39 | | - step %{I fill in "Password" with "#{password}"} |
40 | | - step %{I press "Sign in"} |
| 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' |
41 | 40 | end |
42 | 41 |
|
43 | | -Then /^I should be signed in$/ do |
44 | | - step %{I should see "Signed in successfully."} |
| 42 | +### WHEN ### |
| 43 | +When /^I sign out$/ do |
| 44 | + visit '/users/sign_out' |
45 | 45 | end |
46 | 46 |
|
47 | | -When /^I return next time$/ do |
48 | | - step %{I go to the home page} |
| 47 | +When /^I sign up with valid user data$/ do |
| 48 | + sign_up valid_user |
49 | 49 | end |
50 | 50 |
|
51 | | -Then /^I should be signed out$/ do |
52 | | - step %{I should see "Sign up"} |
53 | | - step %{I should see "Login"} |
54 | | - step %{I should not see "Logout"} |
| 51 | +When /^I sign up with an invalid email$/ do |
| 52 | + user = valid_user.merge(:email => "notanemail") |
| 53 | + sign_up user |
55 | 54 | end |
56 | 55 |
|
57 | | -Then /^I sign out$/ do |
58 | | - visit '/users/sign_out' |
| 56 | +When /^I sign up without a confirmed password$/ do |
| 57 | + user = valid_user.merge(:password_confirmation => "") |
| 58 | + sign_up user |
59 | 59 | end |
60 | 60 |
|
61 | | -When /^I go to the sign in page$/ do |
62 | | - visit '/users/sign_in' |
| 61 | +When /^I sign up without a password$/ do |
| 62 | + user = valid_user.merge(:password => "") |
| 63 | + sign_up user |
| 64 | +end |
| 65 | + |
| 66 | +When /^I sign up with a mismatched password confirmation$/ do |
| 67 | + user = valid_user.merge(:password_confirmation => "please123") |
| 68 | + sign_up user |
63 | 69 | end |
64 | 70 |
|
65 | | -Then /^I should see "([^"]*)"$/ do |text| |
66 | | - page.should have_content(text) |
| 71 | +When /^I return to the site$/ do |
| 72 | + visit '/' |
67 | 73 | end |
68 | 74 |
|
69 | | -Then /^I should not see "([^"]*)"$/ do |text| |
70 | | - page.should_not have_content(text) |
| 75 | +When /^I sign in with a wrong password$/ do |
| 76 | + user = valid_user.merge(:password => "wrongpass") |
| 77 | + sign_in user |
71 | 78 | end |
72 | 79 |
|
73 | | -Then /^I go to the home page$/ do |
74 | | - visit '/' |
| 80 | +When /^I sign in with valid credintials$/ do |
| 81 | + sign_in valid_user |
| 82 | +end |
| 83 | + |
| 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" |
75 | 89 | end |
76 | 90 |
|
77 | | -Given /^I am on the home page$/ do |
| 91 | +When /^I look at the list of users$/ do |
78 | 92 | visit '/' |
79 | 93 | end |
80 | 94 |
|
81 | | -Given /^I go to the sign up page$/ do |
82 | | - visit '/users/sign_up' |
| 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" |
83 | 100 | end |
84 | 101 |
|
85 | | -Given /^I fill in the following:$/ do |table| |
86 | | - # table is a Cucumber::Ast::Table |
87 | | - table.rows_hash.each do |key, value| |
88 | | - fill_in(key, :with => value) |
89 | | - end |
| 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" |
90 | 106 | end |
91 | 107 |
|
92 | | -When /^I press "([^"]*)"$/ do |label| |
93 | | - click_button label |
| 108 | +Then /^I should see a succesfull sign up message$/ do |
| 109 | + page.should have_content "Welcome! You have signed up successfully." |
94 | 110 | end |
95 | 111 |
|
96 | | -When /^I fill in "([^"]*)" with "([^"]*)"$/ do |field, value| |
97 | | - fill_in(field, :with => value) |
| 112 | +Then /^I should see an invalid email message$/ do |
| 113 | + page.should have_content "Email is invalid" |
98 | 114 | end |
99 | 115 |
|
100 | | -When /^I go to the homepage$/ do |
101 | | - visit '/' |
| 116 | +Then /^I should see a missing password message$/ do |
| 117 | + page.should have_content "Password can't be blank" |
| 118 | +end |
| 119 | + |
| 120 | +Then /^I should see a missing password confirmation message$/ do |
| 121 | + page.should have_content "Password doesn't match confirmation" |
| 122 | +end |
| 123 | + |
| 124 | +Then /^I should see a mismatched password message$/ do |
| 125 | + page.should have_content "Password doesn't match confirmation" |
| 126 | +end |
| 127 | + |
| 128 | +Then /^I should see a signed out message$/ do |
| 129 | + page.should have_content "Signed out" |
| 130 | +end |
| 131 | + |
| 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." |
102 | 142 | end |
103 | 143 |
|
104 | | -When /^I follow "([^"]*)"$/ do |text| |
105 | | - click_link text |
| 144 | +Then /^I should see my name$/ do |
| 145 | + page.should have_content valid_user[:name] |
106 | 146 | end |
0 commit comments