Unit Testing Routes

Posted by ryan
at 3:41 AM on Wednesday, July 05, 2006

From the “I didn’t know this existed but now that I’ve found it I will use it more often file” – did’cha know you can actually unit test your routes using the assert_routing assertion?

Assuming a vanilla people_controller and this routes.rb:

map.connect '/:id', :controller => 'people', :action => 'show', :nother => 'woohoo'

You can test routing in your people_controller_test functional test with:

assert_routing "/#{model.id}", :action => 'show', :id => model.id, :nother => 'woohoo'

Good to know…

Comments

Leave a response

  1. Ryan DaigleJuly 04, 2006 @ 07:43 AM
    Great point, Jeremy. (And don't be afraid to use Textile formatting in your comments anymore...)
  2. Jeremy VoorhisJuly 04, 2006 @ 07:43 AM
    assert_recognizes is key as well. The simply_restful unit tests contain one of the best examples I've seen for using these assertions - "http://dev.rubyonrails.org/browser/plugins/simply_restful/test/routing_test.rb":http://dev.rubyonrails.org/browser/plugins/simply_restful/test/routing_test.rb