# Extract all routes and test their views?

**URL:** <https://www.ruby-forum.com/t/extract-all-routes-and-test-their-views/195119>\
**Category:** Rails\
**Created:** [September 17, 2010, 9:28am UTC](https://www.ruby-forum.com/t/extract-all-routes-and-test-their-views/195119 "2010-09-17T09:28:26Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![zoran](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e47c2d/32.png) [@zoran](https://www.ruby-forum.com/u/zoran)\
**Post date:** [September 17, 2010, 9:28am UTC](https://www.ruby-forum.com/t/extract-all-routes-and-test-their-views/195119/1 "2010-09-17T09:28:26Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![zoran](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e47c2d/32.png) [@zoran](https://www.ruby-forum.com/u/zoran)\
**Post date:** [September 17, 2010, 11:11am UTC](https://www.ruby-forum.com/t/extract-all-routes-and-test-their-views/195119/2 "2010-09-17T11:11:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![zoran](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e47c2d/32.png) [@zoran](https://www.ruby-forum.com/u/zoran)\
**Post date:** [September 17, 2010, 12:08pm UTC](https://www.ruby-forum.com/t/extract-all-routes-and-test-their-views/195119/3 "2010-09-17T12:08:08Z")

</div>

Hi Zoran,

On Fri, 2010-09-17 at 09:28 +0200, Zoran Szagaski wrote:

> 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/](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](http://wiki.github.com/aslakhellesoy/cucumber/tutorials-and-related-blog-posts)

Cheers,  
Jon

–  
[http://jonathanleighton.com/](http://jonathanleighton.com/)

---

<div class="post-metadata">

**Author:** ![zoran](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e47c2d/32.png) [@zoran](https://www.ruby-forum.com/u/zoran)\
**Post date:** [September 29, 2010, 8:05pm UTC](https://www.ruby-forum.com/t/extract-all-routes-and-test-their-views/195119/4 "2010-09-29T20:05:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![zoran](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e47c2d/32.png) [@zoran](https://www.ruby-forum.com/u/zoran)\
**Post date:** [September 30, 2010, 1:49pm UTC](https://www.ruby-forum.com/t/extract-all-routes-and-test-their-views/195119/5 "2010-09-30T13:49:57Z")

</div>

Robert W. 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”?

---

<div class="post-metadata">

**Author:** ![zoran](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e47c2d/32.png) [@zoran](https://www.ruby-forum.com/u/zoran)\
**Post date:** [September 29, 2010, 10:15pm UTC](https://www.ruby-forum.com/t/extract-all-routes-and-test-their-views/195119/6 "2010-09-29T22:15:19Z")

</div>

Jon L. wrote:

> I would recommend building up a set of integration tests using Cucumber  
> or similar: [http://cukes.info/](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](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.
