Coloration in Autotest with TestUnit 2.0.3 1
I recently discovered that even though TestUnit 2.0.3 has support for for coloration, coloration does not show in Autotest. Previously, the redgreen gem had taken care of this, but now that TestUnit itself supports coloration the redgreen gem is no longer necessary (not to mention the fact that it’s broken with Ruby 1.9 and TestUnit 2.0.3). TestUnit supports a –use-color flag, but because of the unique way in which Autotest loads the tests I was unable to figure out how I could pass this flag. Furthermore, –use-color defaults to false when the command is passed to a pipe, which Autotest also does.
The easy solution I figured was to then override the method that sets the –use-color defaults. The best place I found to do this is in the Rails test_helper.rb file itself. I know this isn’t the most flexible location, but I couldn’t find anywhere else to inject it, so for now it will have to do. All you need to do is add the following code:
require 'test/unit/ui/console/testrunner'
module Test
module Unit
module UI
module Console
class TestRunner
def guess_color_availability; true; end
end
end
end
end
endIf anyone comes up with a more seamless way to do this, please let me know.
Thanks for documenting this.
The following works as well: