7.7. Summary

Test-driven development is a critical part of the software building process, and has an amazing amount of support within Rails. This support can be augmented with a number of other tools. You can use rcov to measure the amount of your code that is covered by your tests — a necessary but not sufficient condition for good tests.

Mock objects are a standard mechanism for simulating object behavior that would otherwise be hard to specify in a unit test. FlexMock is a Ruby mock object toolkit that enables you to extend the reach of your tests.

RSpec has some definite advantages over standard Rails unit and functional testing. Using RSpec to test controllers, views, and helpers separately greatly enhances your ability to use automatic testing to verify your program's behavior. The naming conventions and structure of an RSpec test can make the tests more readable and easier to describe both within and outside a programming team.

If you like some of the features of RSpec, but don't feel the need to jump all the way into it, other tools can cover much of RSpec's functionality. Both Test::Rails and view_test allow improved testing of views. Other plugins, such as Dust and Shoulda, allow you to mimic RSpec's syntax. The FixtureScenario plugin enables you to specify more-granular sets of fixture data. You can roll your own tests for helper methods.

Get Professional Ruby on Rails™ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.