Ruby on rails 如何测试命名路由?

Ruby on rails 如何测试命名路由?,ruby-on-rails,testing,tdd,Ruby On Rails,Testing,Tdd,我在测试命名路由时遇到以下错误 1) Failure: test_settings_route(ProjectsControllerTest) [/test/functional/projects_controller_test.rb:15]: The generated path <"/projects/1/edit"> did not match <"/projects/1/settings"> 我在routes.rb中有map.resources:projects

我在测试命名路由时遇到以下错误

1) Failure:
test_settings_route(ProjectsControllerTest) [/test/functional/projects_controller_test.rb:15]:
The generated path <"/projects/1/edit"> did not match <"/projects/1/settings">

我在routes.rb中有map.resources:projects位于我的命名路线之上。将我的命名路由移动到顶部修复了我的测试。

根据路由上的RailsGuide,当收到请求时,将从上到下处理routes.rb文件。请求将被发送到第一个匹配的路由。因此,您可能希望在更一般的RESTful路由之前保留更具体的命名路由。
# projects_controller_test.rb
require 'test_helper'
class ProjectsControllerTest < ActionController::TestCase
def test_settings_route
  assert_routing '/projects/1/settings', :controller => 'projects', :action => 'edit', :id => '1'
end

# routes.rb
map.settings '/projects/:id/settings', :controller => 'projects', :action => 'edit'
should_route :get, "/projects/1/settings", :controller => 'projects', :action => 'edit', :id => '1'