Ruby on rails rails 3.2 capybara capybara::ElementNotFound:找不到xpath“/html";
我正在尝试用RSpec2.10.0+Capybara1.1.2测试我的rails应用程序。这是我的测试文件Ruby on rails rails 3.2 capybara capybara::ElementNotFound:找不到xpath“/html";,ruby-on-rails,capybara,Ruby On Rails,Capybara,我正在尝试用RSpec2.10.0+Capybara1.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
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"
我在谷歌上搜索了这个问题,但只找到了webrat可能成为问题的信息,但我没有安装这个gem。谢谢您的建议。错误的测试类型。这看起来像控制器测试,它使用get和post等方法进行测试,并且位于spec/controllers文件夹中。使用capybara的请求规范驻留在spec/requests中。运行
$rails generate scaffold SomeModel
,查看它们的外观
如果您理解上述内容,但仍希望在控制器测试中使用capybara,请修改描述块:
describe AdminPanelController, :type => :request do
...
end
到处寻找这个答案。快一点!对于Capybara 2.0,这不应该是
type::request
,而是type::feature
。