2011-09-24 70 views
0

我的路線是這樣的鋼軌rspec的控制測試的ActionController :: RoutingError

resources :stores, :except => [:destroy] do 
    resources :toys, :member => {:destroy => :delete} 
    end 

我的對象控制器的規格看起來像這樣

require 'spec_helper' 

describe ToysController do 

    describe "GET index" do 
     it "assigns all toys as @toys" do 
      toy11 = Factory(:toy, :is_shiny => true) 
      toy12 = Factory(:toy,:is_shiny => false) 
      get :index 
      assigns(:toys).should eq([toy12,toy11 ]) 
     end 
     end 
    end 
end 

我有以下錯誤

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

由於玩具資源嵌套在商店資源下,無法獲取玩具路徑路線,所以我認爲這是規範我失敗。

我該如何通過規範?

謝謝

回答

0

錯誤是由於未將store_id發送到tyos索引。 如果我發送

:store_id => @store.id in get :index 

它會通過。