Joh*_*ohn 5 ruby-on-rails capybara
我正在尝试使用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可能是一个问题的信息,但我没有安装这个宝石.谢谢你的任何建议.
Tan*_*ili 14
错误的测试类型.这看起来像一个控制器测试,它使用get和post等方法进行测试,并且位于spec/controllers文件夹中.请求规格,使用capybara,驻留在spec/requests中.运行$ rails generate scaffold SomeModel以查看它们的外观.
如果您了解上述内容但仍想使用capybara进行控制器测试,请修改您的描述块:
describe AdminPanelController, :type => :request do
  ...
end