rails 3.2 capybara Capybara :: ElementNotFound:无法找到xpath“ / html” [英] rails 3.2 capybara Capybara::ElementNotFound:Unable to find xpath "/html"
问题描述
我正在尝试使用rspec 2.10.0 + capybara 1.1.2测试Rails应用程序。这是我的测试文件
I am trying to test my rails app with rspec 2.10.0 + capybara 1.1.2. Here is my test file
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
这是测试结果
Failure/Error: page.should have_content "hello"
Capybara::ElementNotFound:
Unable to find xpath "/html"
我在Google上搜索了此问题,但只找到了有关webrat可能是问题的信息我没有安装此宝石。谢谢您的建议。
I google about this issue but find only information that webrat can be a problem however i do not have this gem installed. Thanks for any suggestions.
推荐答案
错误的测试类型。这看起来像是控制器测试,它使用诸如get和post之类的方法进行测试,并且位于spec / controllers文件夹中。使用水豚的请求规格位于规格/请求中。运行 $ rails生成支架SomeModel
来查看它们各自的外观。
Wrong type of test. This looks like a controller test, which does tests with methods like get and post and is in the spec/controllers folder. Request specs, which use capybara, reside in spec/requests. Run $ rails generate scaffold SomeModel
to see how they each should look.
如果您理解上述内容,但仍然会要使用Capybara进行控制器测试,请修改您的describe块:
If you understood the above but would still like to use capybara for your controller test, modify your describe block:
describe AdminPanelController, :type => :request do
...
end
这篇关于rails 3.2 capybara Capybara :: ElementNotFound:无法找到xpath“ / html”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!