2011-10-22 75 views
0

这可能是一个非常基本的错误,但我仍然在学习。 =)简单路由RSpec控制器测试失败

我的routes.rb只包括

WebPortal::Application.routes.draw do 
    resources :categories 
end 

如果我理解正确这,这应该(等等)地图/categoriesCategoriesController.index。该控制器看起来像

class CategoriesController < ApplicationController 
    def index 
    end 
end 

相应的视图文件存在,并且轨服务器为这一页罚款。但我的RSpec的测试

describe CategoriesController do 
    describe "GET :index" do 
    it "should be succesful" do 
     get :index 
     response.should be_succes 
    end 
    end 
end 

失败的消息

Failure/Error: get :index 
    ActionController::RoutingError: 
    No route matches {:controller=>"categories"} 

我在做什么错在这里?

编辑:

rake routes 
    categories GET /categories(.:format)   {:action=>"index", :controller=>"categories"} 
       POST /categories(.:format)   {:action=>"create", :controller=>"categories"} 
new_category GET /categories/new(.:format)  {:action=>"new", :controller=>"categories"} 
edit_category GET /categories/:id/edit(.:format) {:action=>"edit", :controller=>"categories"} 
    category GET /categories/:id(.:format)  {:action=>"show", :controller=>"categories"} 
       PUT /categories/:id(.:format)  {:action=>"update", :controller=>"categories"} 
       DELETE /categories/:id(.:format)  {:action=>"destroy", controller=>"categories"} 
+0

当你在项目文件夹中运行“耙路”时,你会得到什么? – Rasmus

+0

@Rasmus:我用输出编辑了我的问题。 – Jens

+0

我自己还是个新人,我正在看一个简单的项目。我的代码和你的代码唯一的区别在于我的索引是'索引'而不是索引。但是我不认为会这样做 – Rasmus

回答

0

我使用的RSpec版本2.6.1,因为我用的Gemfile从滑轨教程在http://ruby.railstutorial.org/命令rake routes给出。切换到2.7版解决了我的问题。

+0

版本2.6.1是什么?到版本2.7的什么? – pjmorse

+0

是的,那是缺少的。 =)RSpec。 – Jens

+0

谢谢!该编辑澄清了事情。 – pjmorse