O'Reilly logo

Instant RSpec Test-Driven Development How-to by Charles Feduke

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Testing Rails routes (Intermediate)

In this recipe, we'll see how to properly test drive and verify routes in a Rails application. Routes determine which controller handles a particular request based on the data provided by the client's browser.

Getting ready

To spec controller routes, we'll first need an actual controller. Without it, Rails won't properly route requests and we won't be able to validate our specs:

$ rails g controller locations --no-helper

As a part of controller generation, if the --no-helper option wasn't passed, an empty helper and spec file with pending examples would be created.

How to do it...

  1. First, we'll need to register routes to the controller. This is not only easy to do but can be test-driven as well. Create a new file, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required