我正在尝试使用rspec 2.10.0 + capybara 1.1.2测试我的rails应用程序.这是我的测试文件
require 'spec_helper'
describe AdminPanelController do
describe "index" do
it "should have return code 200" do
visit '/admin'
page.should have_content "hello"
#response.status.should be(200)
end
end
end
Run Code Online (Sandbox Code Playgroud)
这是测试结果
Failure/Error: page.should have_content "hello"
Capybara::ElementNotFound:
Unable to find xpath "/html"
Run Code Online (Sandbox Code Playgroud)
我谷歌关于这个问题,但只找到webrat可能是一个问题的信息,但我没有安装这个宝石.谢谢你的任何建议.
我不能让Capybara在我的许多集成测试中工作.
当我访问某些页面时,我得到以下html:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
Run Code Online (Sandbox Code Playgroud)
所以当我尝试使用have_content()选择器时,它会引发以下错误:
Failure/Error: page.should have_content("HELLO")
Capybara::ElementNotFound:
Unable to find xpath "/html"
Run Code Online (Sandbox Code Playgroud)
我可以访问的应用程序的某些页面很好,但其他一些我不能.甚至有些页面可以在某些地方使用,而不是在其他地方使用:
require 'spec_helper'
describe HomeController do
it "shows the website description" do
visit root_path
puts page.html.length # ==> 108 (no html)
...
end
end
require 'spec_helper'
describe FlowsController do
it "should do stuff" do
visit root_path
puts page.html.length # ==> 4459, works even if the exact same one didn't work in home_controller_spec!
visit flows_path
puts page.html.length # ==> …Run Code Online (Sandbox Code Playgroud)