Skip to content

Instantly share code, notes, and snippets.

@tomas-stefano
Created October 23, 2010 03:44
Show Gist options
  • Select an option

  • Save tomas-stefano/641743 to your computer and use it in GitHub Desktop.

Select an option

Save tomas-stefano/641743 to your computer and use it in GitHub Desktop.
class Color
def self.green
ansi_color(31)
end
def self.red
ansi_color(32)
end
def yellow
ansi_color(33)
end
def ansi_color(color)
"\e[#{color]}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
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment