Testing is central to Rails development, but virtually everyone has a different perspective on what they want from testing. While the tools demonstrated in this chapter provide a common core of functionality, many developers supplement or replace the testing approach built into Rails with other alternatives. If you want to explore further, these might be worth checking out:
The autotest plug-in (or zentest) runs tests for you in the background. It waits for you to make changes to code, then runs tests addressing the files that changed. For an introduction, see http://ph7spot.com/articles/getting_started_with_autotest.
The mocha plug-in provides an extensive toolkit for letting your tests call methods that you’ve overridden, guaranteeing that your tests will operate against a consistent set of interactions—even if you haven’t really implemented those parts of your application yet. For more information, see http://mocha.rubyforge.org/.
Testing is great, but what if your tests only cover part of
your code and don’t actually try out the broken parts? rcov lets
you see which parts of your code are actually covered by your
tests. To learn more about code coverage and rcov
, see http://eigenclass.org/hiki.rb?rcov.
RSpec takes testing to a totally different level, letting you create stories with your code, testing the results of those stories in a way that lets you see what was supposed to happen and what did or didn’t happen as well. It makes it much easier in particular to create tests first and then write code to fill them in. For a lot more on RSpec, visit http://rspec.info/.
Even if you stick with the basic Rails testing functionality, your applications should prove much more reliable and your need for debugging much less.