Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 资源创建路由的rspec_Ruby On Rails_Ruby_Rspec - Fatal编程技术网

Ruby on rails 资源创建路由的rspec

Ruby on rails 资源创建路由的rspec,ruby-on-rails,ruby,rspec,Ruby On Rails,Ruby,Rspec,我有这个规格: specify { expect(:post => admin_featured_path()).to route_to(:controller => 'admin/featured', :action => 'create')} 我不能让它通过,但它似乎合乎逻辑的路线后,应路由到创建行动 这是我的路线文件: namespace :admin do resources :featured, only: [:index, :update, :destro

我有这个规格:

specify { expect(:post => admin_featured_path()).to route_to(:controller => 'admin/featured', :action => 'create')}
我不能让它通过,但它似乎合乎逻辑的路线后,应路由到创建行动

这是我的路线文件:

namespace :admin do
    resources :featured, only: [:index, :update, :destroy, :create]
end

这是失败消息:

1) Featured routes 
     Failure/Error: specify { expect(:post => admin_featured_path()).to route_to(:controller => 'admin/featured', :action => 'create')}
     ActionController::UrlGenerationError:
       No route matches {:action=>"update", :controller=>"admin/featured"} missing required keys: [:id]
     # ./spec/routing/featured_spec.rb:7:in `block (2 levels) in <top (required)>'
1)特色路线
失败/错误:指定{expect(:post=>admin_-characterized_-path())。将_路由到(:controller=>'admin/characterized',:action=>'create')}
ActionController::UrlGenerationError:
没有路由匹配{:action=>“update”,:controller=>“admin/featured”}缺少必需的键:[:id]
#./spec/routing/featured_spec.rb:7:in‘block(2层)in’
这应该有效(未经测试):

page = post admin_featured_path
expect(page).to route_to(:controller => 'admin/featured', :action => 'create')
{:post => admin_featured_path}.should route_to(:controller => 'admin/featured', :action => 'create')
{:post => "admin/featured"}.should route_to(:controller => "admin/featured", :action => 'create')