Cool Test::Unit results with TURN

October 29 2009 - Los Angeles

There is something about nice output that makes you feel good inside. Like the guarantee written on the outside of a box, green characters are reassuring.

1. The gems

There is a great turn gem – Test::Unit Reporter (New). As the readme notes, if you also install the facets gem turn will produce colored output.

sudo gem install facets
sudo gem install turn

You can check out the turn repo here: http://github.com/TwP/turn

2. Add a quick require to your test/test_helper.rb

Since we’re running rails tests you want to add the folowing line to test/test_helper.rb to require turn.

begin; require 'turn'; rescue LoadError; end

3. A little more color

While turn is great by default I kind of like a little more color to help distinguish meaning quickly. For example you can dig into the gem and add a line to TestRunner.t_test_started in lib/turn.rb:

file = COLORIZE ? ::ANSICode.yellow(file) : file

4. Removing a little excess information

Test::Unit::UI::Console::TestRunner likes to ramble about which suite it is loading at various times. So in the same file as above, lib/turn.rb you can redefine setup_mediator to not display superfluous output. Just add:

private
def setup_mediator
  @mediator = create_mediator(@suite)
  suite_name = @suite.to_s
  if ( @suite.kind_of?(Module) )
    suite_name = @suite.name
  end
  output("\n")#put some undetermined formatting preference here.
end

5. Getting rails to quiet down

In your rails directory, whether it be in a gem or vendor, you’ll want to make a slight change to /lib/tasks/testing.rake. If you’re using vim, you might use :%s/t.verbose = true/t.verbose = false/g to replace true with false when setting Rake::TestTask.verbose.