0
我正在将我的用户认证从头开始转换到设计宝石的过程。所有已完成,似乎工作正常。我改变了我的rspec测试,但我有一个反复出现的问题,我已经寻找解决方案。转换为设计 - 水豚:: ElementNotFound:
的错误
2) AuthenticationPages authorization for non-signed-in users when attempting to visit a protected page after signing in should render the desired protected page
Failure/Error: fill_in :email, with: user.email
Capybara::ElementNotFound:
cannot fill in, no text field, text area or password field with id, name, or label 'email' found
# (eval):2:in `fill_in'
# ./spec/requests/authentication_pages_spec.rb:53:in `block (5 levels) in <top (required)>'
测试
describe "for non-signed-in users" do
let(:user) { FactoryGirl.create(:user)}
describe "when attempting to visit a protected page" do
before do
visit edit_user_registration_path(user)
fill_in "Email", with: user.email
fill_in "Password", with: user.password
click_button "Sign in"
end
describe "after signing in" do
it "should render the desired protected page" do
page.should have_selector('title', text: 'Edit user')
end
end
end
的设计形式(new_user_session - 被允许看到编辑用户信息出现之前)
<%= form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>
<%= f.label :email %>
<%= f.email_field :email, :autofocus => true %>
<%= f.label :password %>
<%= f.password_field :password %>
<% if devise_mapping.rememberable? -%>
<%= f.check_box :remember_me %> <%= f.label :remember_me %>
<% end -%>
<%= f.submit "Sign in", class: "btn btn-large btn-primary" %>
<% end %>
<%= render "devise/shared/links" %>
在浏览器中测试时,该行为实际上正常工作,但rspec测试失败。
好,测试是针对当前未登录的用户尝试访问其编辑表单。它不应该允许这个,而是有一个签名的形式(这是我附加的形式 - new_user_session)。用户创建一个新的会话后,他们被重定向到他们最初打算去的编辑表单。然后测试应该验证在视图中登录后应该显示“编辑用户”。在看到编辑表单之前,我无法让水豚签署用户。 – 2013-05-08 17:31:02
对不起@SeanL,我了解流程,你说得对。你能检查什么页面到达水豚吗?你的“访问edit_user_registration_path(user)”步骤正在传递,所以它到达某处。 – Galen 2013-05-08 18:20:31
我对水豚的去向感到相当困惑。我试着从fill_in(用户信息)注释中点击按钮 - 并更改测试的底部,看看页面是否应该有h1,文本:'登录'。它失败说它登录不显示。网络净我不知道水豚要去哪里。除非您有任何其他建议,否则我现在要放弃并评论测试。谢谢 – 2013-05-08 18:55:39