我正在按照 Rails 教程开发我的 rails4 应用程序。测试我的身份验证登录页面时失败。错误信息说:
Failure/Error: fill_in "email", with: user.email.upcase
Capybara::ElementNotFound:
Unable to find field "email"
# ./spec/requests/authentication_pages_spec.rb:35:in `block (3 levels) in <top (required)>'
虽然我的 session#new.html.erb 有这样的元素:
<%= form_for(:session, url: sessions_path) do |f| %>
<%= f.label :email %>
<%= f.text_field :email %>
<%= f.label :password %>
<%= f.password_field :password %>
<%= f.submit "Sign in", class: "btn btn-large btn-primary" %>
<% end %>
这是我的 authentication_pages_spec.rb 相关测试部分:
describe "with valid information" do # signin with valid information
let(:user) { FactoryGirl.create(:user) }
before do
fill_in "email", with: user.email.upcase
fill_in "password", with: user.password
click_button "Sign in"
end
it { should have_title(user.name) }
it { should have_link('Profile', href: user_path(user)) }
it { should have_link('Sign out', href: signout_path) }
it { should_not have_link('Sign in', href: signin_path) }
describe "followed by signout" do
before { click_link "Sign out" }
it { should have_link('Sign in') }
end
end
我尝试将“访问登录路径”添加到测试部分,但仍然失败并显示相同的消息。有人可以帮我弄清楚我在哪里犯了错误吗?非常感谢。