【问题标题】:How to write rspec test for custom routes如何为自定义路由编写 rspec 测试
【发布时间】:2012-02-07 06:07:07
【问题描述】:

我有以下自定义路线:

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

rspec 中的 'get' 方法只接受动作名称,但这样做:

get :display, id: 1000

我得到:

RoutingError: 没有路线匹配 {:id=>"1000", :controller=>"planes", :action=>"display"}

并且没有选项可以在测试中获取“/boeing-737”。

【问题讨论】:

  • 请发布您的控制器代码。

标签: ruby-on-rails rspec


【解决方案1】:

找到了解决方案,id 必须是字符串值,我会在这里发布,因为我认为这个用例在 rspec 中没有足够的文档记录:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-27
    • 1970-01-01
    • 2013-07-13
    • 1970-01-01
    • 2015-03-29
    • 1970-01-01
    相关资源
    最近更新 更多