我正试图在rails应用程序上使用ruby来做一些内容测试,以及我使用设计gem来实现用户身份验证。我无法登录到我的应用程序来执行我的测试用例。在rails应用程序中通过水豚身份验证
最初,我的情况如下:
scenario "User arrives at main page" do
visit "purchase_orders#index"
page.should have_content("All")
# some more tests and checks
end
凡purchase_orders#指数是通过身份验证的根,其中用户的采购订单中。 但是当我运行测试,我发现了以下错误:
expected to find text "All" in "Log in to manage your orders * Email * Password Forgot your password? Remember me Sign up • Didn't receive confirmation instructions? About Us • Contact Us •
它告诉我,它没有得到过去的登录页面。接下来我尝试添加以下到我的情况下,在运行测试之前,使其登录:
visit "purchase_orders#index"
fill_in('Email', :with => '[email protected]')
fill_in('Password', :with => 'password')
click_button('Log in')
其中用户名和密码是实际创建的帐户,但它再次失败,而且不会让过去的标志页。最后,我尝试了以前添加(:每个)方法,如下所示,试图在测试用例签署用户:
before(:each) do
visit "users/sessions#new"
fill_in('Email', :with => '[email protected]')
fill_in('Password', :with => 'password')
click_button('Log in')
end
这又没有为我工作。所以我的问题是:通过登录页面和实际应用程序的最佳做法和语法是什么?我查找了文档和答案,但没有找到任何东西。
谢谢!