我正在将我的用户身份验证从头开始转换为设计 gem。一切都已完成,似乎工作正常。我改变了我的 rspec 测试,但是我有一个反复出现的问题,我已经搜索过一个解决方案。
错误
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 测试失败。