Datasheet

Chapter 1: Building Resources
21
Rails Testing Tip
The default test runner text is fine as far as it goes, but sometimes it’s not very easy to
tell which methods have failed. If you include diagnostic print statements in your tests
while debugging, it can be difficult to tell which output goes with which tests.
There are a few options for more useful test output. Most IDEs include some kind of
graphical text runner, and over the past year or so, several Java IDEs have added Rails
support — Aptana for Eclipse, NetBeans, and IntelliJ all have graphical Rails test run-
ners. There are also a couple of available stand-alone GUI test runners, depending on
the operating system you are running.
I’ve come to like a little gem called
turn, which you can install and then place the line
require ’turn’ in your test_helper.rb file. It produces somewhat more useful
and verbose test-runner output. The error message for each test is associated with that
test, as is any diagnostic output. And if your command shell supports it, tests that pass
are in green and tests that fail are in red. Here is some sample output:
IngredientsControllerTest
test_should_create_ingredient PASS
test_should_destroy_ingredient PASS
test_should_get_edit PASS
test_should_get_index PASS
test_should_get_new PASS
test_should_show_ingredient PASS
test_should_update_ingredient PASS
RecipesControllerTest
test_should_create_recipe PASS
test_should_destroy_recipe PASS
test_should_get_edit PASS
test_should_get_index PASS
test_should_get_new PASS
test_should_show_recipe PASS
test_should_update_recipe PASS
====================================================================
pass: 14, fail: 0, error: 0
total: 14 tests with 25 assertions in 1.768561 seconds
====================================================================
Because turn changes the format of your text output, other plugins or tools that
depend on the test output — most notably Autotest (see Chapter 7) — might have
problems.
c01.indd 21c01.indd 21 1/30/08 4:02:27 PM1/30/08 4:02:27 PM