Ruby 使用rspec测试时未找到Capybara::Element
我正在编写rails4应用程序,学习Rails教程。测试我的身份验证登录页时出错。错误消息显示:Ruby 使用rspec测试时未找到Capybara::Element,ruby,rspec,ruby-on-rails-4,Ruby,Rspec,Ruby On Rails 4,我正在编写rails4应用程序,学习Rails教程。测试我的身份验证登录页时出错。错误消息显示: 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
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)>'
我尝试将“访问登录路径”添加到测试部分,但仍然失败,并显示相同的消息。
有人能帮我找出哪里出了错吗?非常感谢。我相信如果你搬家的话
describe "followed by signout" do
before { click_link "Sign out" }
it { should have_link('Sign in') }
end
在
it{should have_title(user.name)}
块之前,它应该通过。我有同样的问题,这为我解决了 这个错误可能有很多不同的原因,所以我宁愿给你一些提示来检查什么:a)水豚通常搜索区分大小写的,并在“email”中填写标签、名称或id为“email”的字段。在您的案例中,表单字段的id应该是“session_email”,名称为“session[email]”,因此只剩下标签。默认情况下,它将是“电子邮件”而不是“电子邮件”。b) 任何错误的重定向、错误等都会导致此错误,因为capybara找不到登录表单。如果您使用launchy,您可以随时调用save_和open_page并在浏览器中检查页面,这可能会有所帮助。谢谢,@trueunlessfalse。在发布此查询之前,我尝试了一个解决方案,但没有达到预期效果。对不起,我不太明白解决方案b,你是说我应该在“”部分添加一些标记吗?
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
describe "followed by signout" do
before { click_link "Sign out" }
it { should have_link('Sign in') }
end