Hi I'm writing a spec and i need to setup a test route from inside the spec however when i use Rails::Application.routes.draw it overwrites all the other r开发者_开发知识库outes.
Is there a way to do this in rails 3?
Cheers
Dan
The general solution is to use some method to actually switch our the route set - namely, either using mocking or just making the scope that uses the routes to return a new ActionDispatch::Routing::RouteSet.new - this prevents you from using the default routes but in the scenario where you're testing a something that revolves around the routes, it works perfectly.
If, alternatively, you're testing code e.g. helpers that use a route, you'll either need to look at saving the state of the routes or something similar to prevent it from clearing them. When in doubt, I suggest looking at the ActionDispatch code and tests (e.g. http://github.com/rails/rails/blob/master/actionpack/test/dispatch/url_generation_test.rb)
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论