Improve for Capybara timing rails7/depot_r/test/test_helper.rb (Chapter 14. Task I: Logging In • 218).
Also stopped using “delete” method as not supported in latest capybara when using selenium.
module AuthenticationHelpers
def login_as(user)
if respond_to? :visit
visit login_url
fill_in :name, with: user.name
fill_in :password, with: "secret"
click_on "Login"
> find 'h1', text: "Welcome", wait: 5 # add a wait for page switching.
else
post login_url, params: { name: user.name, password: "secret" }
end
end
def logout
> click_on "Logout"
> # delete logout_url
end
end