Root Route Testing in Rails
19 Feb 2011
This one took a little bit for me to figure out and I thought that I'd share the solution.
it "should route root to home page" do
opts = { :controller => 'home', :action => 'index'}
assert_recognizes opts, '/'
end
If you read the testing Rails guide you'll notice that they make a brief mention of the assert_routing. That code takes the hash key and composes a route based on the parameters. This doesn't necessarily work for the root, though. In order to do that, you need to compose the route hash from a relative URL. That is what assert_recognizes does for us.
About Derek Hammer
Derek Hammer writes code for a living. He loves to travel, share a good beer and try new things. He currently lives in Chicago, Illinois and works for ThoughtWorks.