Extract all routes and test their views?

Hey,

I'm trying to add some more tests to my application and was wondering what's the best way to test all my routes/views of my application. I'm using HAML which can lead to some typos since I'm new to it and of course the Ruby code itself in the views.

How would you test the views? Does it make sense to somehow extract all routes and "surf" on every possible route to check if it's a 200 or not?

Hi Zoran,

Hey,

I'm trying to add some more tests to my application and was wondering what's the best way to test all my routes/views of my application. I'm using HAML which can lead to some typos since I'm new to it and of course the Ruby code itself in the views.

How would you test the views? Does it make sense to somehow extract all routes and "surf" on every possible route to check if it's a 200 or not?

I would recommend building up a set of integration tests using Cucumber or similar: http://cukes.info/. This will allow you to check that all the "moving parts" of your applications are working together correctly, including that your routes/redirections/views are free from errors. You can find a list of tutorials here: http://wiki.github.com/aslakhellesoy/cucumber/tutorials-and-related-blog-posts

Cheers, Jon

I'm not sure how to get all routes (I guess you wanna test all routes from "rake routes"?) but route testing is quite easy.

Should look somehow like this: test "should route to post" do   assert_routing '/pages/1', { :controller => "pages", :action => "show", :id => "1" } end

That's not really what I was looking for but I'll give it a shot. Thanks!

Jon Leighton wrote:

I would recommend building up a set of integration tests using Cucumber or similar: http://cukes.info/. This will allow you to check that all the "moving parts" of your applications are working together correctly, including that your routes/redirections/views are free from errors. You can find a list of tutorials here: http://wiki.github.com/aslakhellesoy/cucumber/tutorials-and-related-blog-posts

An alternative, or more likely in combination with cucumber stories, RSSpec provides routing expectations:

Examples: route_for(:controller => "hello", :action => "world").should == "/hello/world" params_from(:get, "/hello/world").should == {:controller => "hello", :action => "world"}

So one could list all routes with "rake routes" and then write RSpec examples to test them.

Robert Walker wrote:

An alternative, or more likely in combination with cucumber stories, RSSpec provides routing expectations:

Examples: route_for(:controller => "hello", :action => "world").should == "/hello/world" params_from(:get, "/hello/world").should == {:controller => "hello", :action => "world"}

So one could list all routes with "rake routes" and then write RSpec examples to test them.

Alright, thank you. But there's no way to let it test all routes automatically extracted from "rake routes"?