Skip to content

Commit 14b9b7b

Browse files
committed
test: Harden feature specs
We need to wait for the page to load before clicking links or making assumptions about its content.
1 parent 9247cb6 commit 14b9b7b

9 files changed

Lines changed: 15 additions & 0 deletions

File tree

spec/features/account_spec.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
fill_in "Email", with: user.email
1010
fill_in "Password", with: user.password
1111
click_button "Login"
12+
expect(page).to have_text "Logged in successfully"
1213

1314
click_link "My Account"
1415
expect(page).to have_text "admin@person.com"
@@ -22,6 +23,7 @@
2223
fill_in "Password", with: "password"
2324
fill_in "Password Confirmation", with: "password"
2425
click_button "Create"
26+
expect(page).to have_text "You have signed up successfully"
2527

2628
click_link "My Account"
2729
expect(page).to have_text "email@person.com"
@@ -43,6 +45,7 @@
4345
fill_in "Email", with: user.email
4446
fill_in "Password", with: user.password
4547
click_button "Login"
48+
expect(page).to have_text "Logged in successfully"
4649

4750
click_link "My Account"
4851
expect(page).to have_text "email@person.com"

spec/features/admin/sign_out_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# Regression test for #1257
1313
check "Remember me"
1414
click_button "Login"
15+
expect(page).to have_text "Logged in successfully"
1516
end
1617

1718
scenario "allows a signed in user to logout" do

spec/features/admin_permissions_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
fill_in "Email", with: user.email
1111
fill_in "Password", with: user.password
1212
click_button "Login"
13+
expect(page).to have_text "Logged in successfully"
1314
end
1415

1516
context "admin is restricted from accessing orders" do

spec/features/change_email_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
fill_in "spree_user[email]", with: user.email
1212
fill_in "spree_user[password]", with: "secret"
1313
click_button "Login"
14+
expect(page).to have_text "Logged in successfully"
1415

1516
visit spree.edit_account_path
1617
end

spec/features/checkout_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,13 @@
7979
user = create(:user, email: "email@person.com", password: "password", password_confirmation: "password")
8080
click_link "RoR Mug"
8181
click_button "Add To Cart"
82+
within("h1") { expect(page).to have_text "Shopping Cart" }
8283

8384
click_link "Login"
8485
fill_in "Email", with: user.email
8586
fill_in "Password", with: user.password
8687
click_button "Login"
88+
expect(page).to have_text "Logged in successfully"
8789
click_link "Cart"
8890

8991
expect(page).to have_text "RoR Mug"
@@ -112,6 +114,7 @@
112114
create(:user, email: "email@person.com", password: "password", password_confirmation: "password")
113115
click_link "RoR Mug"
114116
click_button "Add To Cart"
117+
within("h1") { expect(page).to have_text "Shopping Cart" }
115118

116119
click_link "Login"
117120
click_link "Forgot Password?"
@@ -142,6 +145,7 @@
142145
scenario "allow a user to register during checkout" do
143146
click_link "RoR Mug"
144147
click_button "Add To Cart"
148+
within("h1") { expect(page).to have_text "Shopping Cart" }
145149
click_button "Checkout"
146150

147151
expect(page).to have_text "Registration"

spec/features/order_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
fill_in "Email", with: user.email
4141
fill_in "Password", with: user.password
4242
click_button "Login"
43+
expect(page).to have_text "Logged in successfully"
4344

4445
# Order should have been merged with first session
4546
click_link "Cart"

spec/features/sign_in_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
fill_in "Email", with: @user.email
4949
fill_in "Password", with: @user.password
5050
click_button "Login"
51+
expect(page).to have_text "Logged in successfully"
5152
expect(current_path).to eq "/account"
5253
end
5354
end

spec/features/sign_out_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# Regression test for #1257
1616
check "Remember me"
1717
click_button "Login"
18+
expect(page).to have_text "Logged in successfully"
1819
end
1920

2021
scenario "allow a signed in user to logout" do

spec/support/features/fill_addresses_fields.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ def fill_addresses_fields_with(address)
1414
%w[firstname lastname]
1515
end
1616

17+
expect(page).to have_text "Billing Address"
18+
1719
fields.each do |field|
1820
fill_in "order_bill_address_attributes_#{field}", with: address.send(field).to_s
1921
end

0 commit comments

Comments
 (0)