【问题标题】:RSpec: testing path to route mapping (but not the other way around)RSpec:测试路由映射的路径(但不是相反)
【发布时间】:2010-07-15 09:53:25
【问题描述】:

我需要使用已弃用的params_from 的功能。现在route_to 结合了params_fromroute_for 的行为。但我不想测试 route 是否生成 path,因为它不会,而且这是故意的(为了在旧电子邮件中向后兼容,我需要“别名”正确控制器/动作的旧路径,但新路由生成的路径会有所不同。我知道,令人困惑;)

当使用 params_fromroute_to 时,我得到了相互矛盾的结果(也许 params_for 被破坏了?):

# params_from(:get, 'user/tasks').should == { :controller => 'user', :action => 'tasks' }
No route matches "user/tasks" with {:method=>:get} 

# { :get => 'user/tasks' }.should_not be_routable
Expected 'GET user/tasks' to fail, but it routed to {"action"=>"tasks", "controller"=>"user"} instead

路由确实存在,我可以通过UI成功使用路径。

IMO 这种params_fromroute_for 的组合是个坏主意,除非仍然支持单独的匹配项。但也许我错过了一些明显的东西;)

【问题讨论】:

    标签: ruby-on-rails rspec routes


    【解决方案1】:

    这就是我一直在寻找的东西,并在破解源代码时找到了它: assert_recognizes({ :controller => 'user', :action => 'tasks'}, 'user/tasks', {}, nil)

    我可能会将它包装在params_for matcher 下。

    【讨论】:

      【解决方案2】:

      明确测试你的路由集有什么价值?

      如果你为你的控制器写一个最小的功能测试,你应该可以免费获得这个。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-07-13
        • 1970-01-01
        • 1970-01-01
        • 2011-11-05
        • 1970-01-01
        • 2018-10-01
        • 2014-08-02
        • 1970-01-01
        相关资源
        最近更新 更多