我正在尝试使用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
这是测试结果
Failure/Error: page.should have_content "hello"
Capybara::ElementNotFound:
Unable to find xpath "/html"
我在谷歌上搜索这个问题,但只发现webrat可以是一个问题的信息,但是我没有安装这个gem。谢谢你的建议。
发布于 2012-07-17 13:19:26
测试类型错误。这看起来像一个控制器测试,它使用get和post等方法进行测试,位于spec/ controller文件夹中。使用水豚的请求规范驻留在spec/requests中。运行$ rails generate scaffold SomeModel
查看它们各自的外观。
如果您了解上述内容,但仍希望使用水豚进行控制器测试,请修改describe块:
describe AdminPanelController, :type => :request do
...
end
https://stackoverflow.com/questions/11382415
复制相似问题