O'Reilly logo

Ruby on Rails® for Microsoft Developers by Antonio Cangiano

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

8.9. Testing Controllers

Testing is an important component of performing Agile Web development. In fact, as stressed multiple times before, one of the fundamental principles of the Agile methodologies is the ability to change the software code base to respond to changes in requirements.

It's easy enough to verify that routing and controllers are working as expected by firing up your favorite browser and trying out paths within the application. But this approach is not systematic and won't provide you with any level of confidence, as you continue to change and evolve your application. Furthermore, working on a code base that doesn't have good test coverage is risky and tends to require much more time and effort while debugging.

As a reminder, at any time you can check your test coverage and other interesting statistics about your project by running rake stats.

For these reasons, this chapter concludes with a brief tour of what Rails bakes-in for testing routes and controllers.

8.9.1. Testing Routes

Route testing consists of writing unit tests that verify that the mapping between paths and the controllers' code works as expected.

Your routing tests can be stored in test\unit\routing_test.rb, which is just going to be a regular test case (within the context of Rails):

require 'test_helper'

class RoutingTest < ActiveSupport::TestCase

 #... Your routing tests...

end

This file is not generated automatically by Rails and must be manually created by developers who intend to test routes. ...

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