2011-10-22 109 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