Rails 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"}
,因为玩具资源嵌套在商店资源下,所以它无法获取toys_path路线,所以我认为规范失败了。
我如何通过规范?
谢谢
My routes looks like this
resources :stores, :except => [:destroy] do
resources :toys, :member => {:destroy => :delete}
end
my objects controller spec look like this
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
I got the following error
Failure/Error: get :index
ActionController::RoutingError:
No route matches {:controller=>"toys"}
Since the toys resource is nested under stores resources its not able to get toys_path route so i think so the spec is failing.
How do i pass the spec?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该错误是由于未将 store_id 发送到 tyos 索引造成的。
如果我发送
它就会过去。
The error is due to not sending store_id to tyos index.
Had i sent
it would have passed.