rspec-rails:失败/错误:获取“ /”没有路由匹配

|| 试用rspec-rails。我收到一个怪异的错误-即使在运行rails时可以在浏览器中正常访问它们,也未找到任何路由。 我什至只是/
Failure/Error: get \"/\"
     ActionController::RoutingError:
       No route matches {:controller=>\"action_view/test_case/test\", :action=>\"/\"}
我绝对可以在浏览器中访问/和其他资源。设置rspec时,我会错过什么吗?我将其放入Gemfile并运行rspec:install。 谢谢, 先生 编辑:这是我的测试
  1 require \'spec_helper\'
  2 
  3 describe \"resource\" do
  4   describe \"GET\" do
  5     it \"contains /\" do
  6       get \"/\"
  7       response.should have_selector(\"h1\", :content => \"Project\")
  8     end
  9   end
 10 end
这是我的路线文件:
myApp::Application.routes.draw do

  resources :groups do
    resources :projects
  end 

  resources :projects do
    resources :variants
    resources :steps

    member do
      get \'compare\'
    end 
  end 

  resources :steps do
    resources :costs
  end 

  resources :variants do
    resources :costs
  end 

  resources :costs

  root :to => \"home#index\"

end
我的spec_helper.rb:
ENV[\"RAILS_ENV\"] ||= \'test\'
require File.expand_path(\"../../config/environment\", __FILE__)
require \'rspec/rails\'    

Dir[Rails.root.join(\"spec/support/**/*.rb\")].each {|f| require f}

RSpec.configure do |config|

  config.mock_with :rspec
  config.include RSpec::Rails::ControllerExampleGroup


  config.fixture_path = \"#{::Rails.root}/spec/fixtures\"


  config.use_transactional_fixtures = true
end
我认为这里真的没有任何改变。     
已邀请:
据我所知,您正在尝试将两个测试合并为一个。在rspec中,应该分两个步骤解决。在一个规范中,您测试了路由,在另一个规范中,您测试了控制器。 因此,添加文件
spec/routing/root_routing_spec.rb
require \"spec_helper\"

describe \"routes for Widgets\" do
  it \"routes /widgets to the widgets controller\" do
    { :get => \"/\" }.should route_to(:controller => \"home\", :action => \"index\")
  end
end
然后添加一个文件“ 6”,我正在使用由单身或非凡的人定义的扩展匹配器。
require \'spec_helper\'

describe HomeController do

  render_views

  context \"GET index\" do
    before(:each) do
      get :index
    end
    it {should respond_with :success }
    it {should render_template(:index) }

    it \"has the right title\" do
      response.should have_selector(\"h1\", :content => \"Project\")
    end

  end
end  
实际上,我几乎从不使用
render_views
,而是始终尽可能地隔离测试我的组件。视图是否包含正确的标题,我在视图规范中测试了该视图。 我使用rspec分别测试每个组件(模型,控制器,视图,路由),并使用Cucumber编写高级测试以遍历所有层。 希望这可以帮助。     
您必须“ 9”个控制器才能进行控制器测试。另外,由于您是在控制器测试中测试视图的内容,而不是在单独的视图规范中进行测试,因此您必须ѭ8。
describe SomeController, \"GET /\" do
  render_views

  it \"does whatever\" do
    get \'/\'
    response.should have_selector(...)
  end
end
    

要回复问题请先登录注册