简体   繁体   English

如何为自定义路由编写RSpec测试

[英]How to write rspec test for custom routes

I have the following custom route: 我有以下自定义路线:

match '/boeing-737', controller: :planes, action: :display, id: 1000

The 'get' method in rspec only accepts action name, but doing this: rspec中的'get'方法仅接受动作名称,但是可以这样做:

get :display, id: 1000

I am getting: 我正进入(状态:

RoutingError: No route matches {:id=>"1000", :controller=>"planes", :action=>"display"} RoutingError:没有路线与{:id =>“ 1000”,:controller =>“ planes”,:action =>“ display”}匹配

And there is no option to do get '/boeing-737' in the test. 而且没有选择可以在测试中获得“ / boeing-737”。

找到解决方案后,id必须是字符串值,我将其发布在这里,因为我认为该用例在rspec中没有足够的文档说明:

match '/boeing-737', controller: :planes, action: :display, id: '1000'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM