方法
实例公共方法
with_routing(&block) 链接
一个辅助方法,使测试不同的路由配置更加容易。此方法在每次测试之前,临时将 @routes 替换为新的 RouteSet 实例。
新实例将被传递给块。通常,块将使用 set.draw { match ... } 创建一些路由。
with_routing do |set| set.draw do resources :users end end
来源: 显示 | 在 GitHub 上
# File actionpack/lib/action_dispatch/testing/assertions/routing.rb, line 101 def with_routing(&block) old_routes, old_controller = nil setup do old_routes, old_controller = @routes, @controller create_routes(&block) end teardown do reset_routes(old_routes, old_controller) end end