Module: Bacon

Defined in:
lib/greeneggs.rb

Overview

GreenEggs – small red/green patch for Bacon

“I do not like Green Eggs and Ham.” —Sam I Am

Copyright © 2009 Michael Fleet <disinnovate.com>

GreenEggs is freely distributable under the terms of the MIT license. See LICENSE or www.opensource.org/licenses/mit-license.php for details.

Defined Under Namespace

Modules: SpecDoxOutput, TestUnitOutput

Constant Summary collapse

COLORS =

ANSI terminal colors

{ 'F' => 31,	'E' => 35, 'M' => 33, :ok => 32	}

Class Method Summary collapse

Class Method Details

.colorize_result(out) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/greeneggs.rb', line 17

def colorize_result(out)
	return out if PLATFORM =~ /win32/ 

	requirement_color = case out
	when /(FAILED|ERROR|MISSING)/ then $1[0..0] # SpecDox, Tap, Knock
	when /\A([FME])\Z/ then $1 # TestUnit
	else :ok
	end

	summary_color = out.match(/0 failures, 0 errors/).nil? ? 'F' : :ok

	out.sub(/^(.|(ok|not ok|-) .+)$/, 
		colorize_string('\0', requirement_color)).sub(/^.+\d+ failures, \d+ errors$/, 
			colorize_string('\0', summary_color))
end

.colorize_string(text, color) ⇒ Object



15
# File 'lib/greeneggs.rb', line 15

def colorize_string(text, color); "\e[1m\e[#{COLORS[color]}m#{text}\e[0m"; end


38
39
40
41
# File 'lib/greeneggs.rb', line 38

def print(*args)
	args.map! { |arg| arg.instance_of?(String) ? colorize_result(arg) : arg }
	super(args)
end

.puts(*args) ⇒ Object



33
34
35
36
# File 'lib/greeneggs.rb', line 33

def puts(*args)
	args.map! { |arg| arg.instance_of?(String) ? colorize_result(arg) : arg }
	super(args)
end