From cb3d1438dca19d7a078a646fccfa050eb1d0fcf6 Mon Sep 17 00:00:00 2001 From: "Colin T.A. Gray" Date: Thu, 13 Jun 2013 10:24:04 -0600 Subject: [PATCH] adds `output=colorized` option --- lib/motion/spec.rb | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/lib/motion/spec.rb b/lib/motion/spec.rb index 44bb31ac..3cf216a5 100644 --- a/lib/motion/spec.rb +++ b/lib/motion/spec.rb @@ -155,6 +155,41 @@ module Bacon end end + module ColorizedOutput + GREEN = "\033[0;32m" + RED = "\033[0;31m" + RESET = "\033[00m" + + def handle_specification_begin(name); end + def handle_specification_end ; end + + def handle_requirement_begin(description) end + def handle_requirement_end(error) + if error.empty? + print "#{GREEN}.#{RESET}" + else + print "#{RED}#{error[0..0]}#{RESET}" + end + end + + def handle_summary + puts "" + puts "", ErrorLog if Backtraces && ! ErrorLog.empty? + + duration = "%0.2f" % (Time.now - @timer) + puts "", "Finished in #{duration} seconds." + + color = GREEN + if Counter[:errors] > 0 || Counter[:failed] > 0 + color = RED + end + + puts "#{color}%d tests, %d assertions, %d failures, %d errors#{RESET}" % + Counter.values_at(:specifications, :requirements, :failed, :errors) + puts "" + end + end + module FastOutput def handle_specification_begin(name); end def handle_specification_end; end @@ -238,6 +273,7 @@ module Bacon 'tap' => TapOutput, 'knock' => KnockOutput, 'rubymine' => RubyMineOutput + 'colorized' => ColorizedOutput } extend(Outputs[ENV['output']] || SpecDoxOutput)