Sha256: b7b5924617907a748f49204d5074760b148c2fe466e88b3f98883daa4984144f
Contents?: true
Size: 1.71 KB
Versions: 11
Compression:
Stored size: 1.71 KB
Contents
# stolen from redgreen # http://on-ruby.blogspot.com/2006/05/red-and-green-for-ruby.html require 'test/unit' require 'test/unit/ui/console/testrunner' # cute. module Color COLORS = { :clear => 0, :red => 31, :green => 32, :yellow => 33 } def self.method_missing(color_name, *args) color(color_name) + args.first + color(:clear) end def self.color(color) "\e[#{COLORS[color.to_sym]}m" end end class Test::Unit::UI::Console::RedGreenTestRunner < Test::Unit::UI::Console::TestRunner def initialize(suite, output_level=NORMAL, io=$stdout) super end def output_single(something, level=NORMAL) return unless (output?(level)) something = case something when '.' then Color.green('.') when 'F' then Color.red("F") when 'E' then Color.yellow("E") else something end @io.write(something) @io.flush end def finished(*args) @result = @result.to_s super end end class Test::Unit::AutoRunner alias :old_initialize :initialize def initialize(standalone) old_initialize(standalone) @runner = proc do |r| Test::Unit::UI::Console::RedGreenTestRunner end end end class Test::Unit::TestResult alias :old_to_s :to_s def to_s if old_to_s =~ /\d+ tests, \d+ assertions, (\d+) failures, (\d+) errors/ Color.send($1.to_i != 0 || $2.to_i != 0 ? :red : :green, $&) end end end class Test::Unit::Failure alias :old_long_display :long_display def long_display old_long_display.sub('Failure', Color.red('Failure')) end end class Test::Unit::Error alias :old_long_display :long_display def long_display old_long_display.sub('Error', Color.yellow('Error')) end end
Version data entries
11 entries across 11 versions & 1 rubygems