rails rspec controller test ActionController :: RoutingError

时间:2011-09-24 18:52:26

标签: testing rspec controller nested-routes

我的路线看起来像这样

  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"}

由于玩具资源嵌套在商店资源下,因此无法获得toys_path路线,所以我认为规格失败了。

我如何通过规范?

由于

1 个答案:

答案 0 :(得分:0)

错误是由于没有将store_id发送到tyos索引。 我发了

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

它会过去。

相关问题