我正在尝试使用rspec和capybara测试登录表单,如果用户选中remember me
复选框,那么他关闭浏览器并重新打开它,他仍然连接,这是我的测试看起来像:< / p>
it "still connected if remember me is checked" do
user = FactoryGirl.create(:user)
fill_in "Email", with: user.email
fill_in "Password", with: user.password
check "Remember me"
click_button submit
page.should have_link("sign out", signout_path)
# here i should do something to close the browser
visit signin_path
page.should have_link("Sign out", signout_path)
end
我正在搜索如何用capybara关闭浏览器,但任何解决方案对我都有用,有一种简单的方法可以做到这一点吗?
答案 0 :(得分:1)
您无需关闭浏览器即可删除会话。在测试中,您可以让服务器清除它。
it "still connected if remember me is checked" do
user = FactoryGirl.create(:user)
fill_in "Email", with: user.email
fill_in "Password", with: user.password
check "Remember me"
click_button submit
page.should have_link("sign out", signout_path)
controller.reset_session
visit signin_path
page.should have_link("Sign out", signout_path)
end
答案 1 :(得分:0)
实际上你需要的是一个宝石电话show_me_the_cookies。有一个名为expire_cookies
的方法,您可以模拟关闭浏览器&amp;打开浏览器动作。
所以你的情况:
it "still connected if remember me is checked" do
user = FactoryGirl.create(:user)
fill_in "Email", with: user.email
fill_in "Password", with: user.password
check "Remember me"
click_button submit
page.should have_link("sign out", signout_path)
# here i should do something to close the browser
expire_cookies
visit signin_path
page.should have_link("Sign out", signout_path)
end