@@ -43,23 +43,31 @@ def ____(method=nil)
4343end
4444
4545module EdgeCase
46+
4647 module Color
4748 #shamelessly stolen (and modified) from redgreen
48- COLORS = { :clear => 0 , :red => 31 , :green => 32 , :yellow => 33 , :blue => 34 , :magenta => 35 , :cyan => 36 }
49+ COLORS = {
50+ :clear => 0 , :black => 30 , :red => 31 ,
51+ :green => 32 , :yellow => 33 , :blue => 34 ,
52+ :magenta => 35 , :cyan => 36 ,
53+ }
54+
55+ module_function
4956
5057 COLORS . each do |color , value |
51- class_eval "def self.#{ color } (string); colorize(string, #{ value } ); end"
58+ module_eval "def #{ color } (string); colorize(string, #{ value } ); end"
59+ module_function color
5260 end
5361
54- def self . colorize ( string , color_value )
62+ def colorize ( string , color_value )
5563 if ENV [ 'NO_COLOR' ]
5664 string
5765 else
5866 color ( color_value ) + string + color ( COLORS [ :clear ] )
5967 end
6068 end
6169
62- def self . color ( color_value )
70+ def color ( color_value )
6371 "\e [#{ color_value } m"
6472 end
6573 end
@@ -88,9 +96,9 @@ def initialize
8896 def accumulate ( test )
8997 if test . passed?
9098 @pass_count += 1
91- puts " #{ test . name } has expanded your awareness."
99+ puts Color . green ( " #{ test . name } has expanded your awareness." )
92100 else
93- puts " #{ test . name } has damaged your karma."
101+ puts Color . red ( " #{ test . name } has damaged your karma." )
94102 @failed_test = test
95103 @failure = test . failure
96104 throw :edgecase_exit
@@ -108,18 +116,19 @@ def assert_failed?
108116 def report
109117 if failed?
110118 puts
111- puts "You have not yet reached enlightenment ..."
112- puts failure . message
119+ puts Color . green ( "You have not yet reached enlightenment ..." )
120+ puts Color . red ( failure . message )
113121 puts
114- puts "Please meditate on the following code:"
122+ puts Color . green ( "Please meditate on the following code:" )
115123 if assert_failed?
116- puts find_interesting_lines ( failure . backtrace )
124+ #puts find_interesting_lines(failure.backtrace)
125+ puts find_interesting_lines ( failure . backtrace ) . collect { |l | Color . red ( l ) }
117126 else
118- puts failure . backtrace
127+ puts Color . red ( failure . backtrace )
119128 end
120129 puts
121130 end
122- say_something_zenlike
131+ puts Color . green ( a_zenlike_statement )
123132 end
124133
125134 def find_interesting_lines ( backtrace )
@@ -130,26 +139,27 @@ def find_interesting_lines(backtrace)
130139
131140 # Hat's tip to Ara T. Howard for the zen statements from his
132141 # metakoans Ruby Quiz (http://rubyquiz.com/quiz67.html)
133- def say_something_zenlike
142+ def a_zenlike_statement
134143 puts
135144 if !failed?
136- puts "Mountains are again merely mountains"
145+ zen_statement = "Mountains are again merely mountains"
137146 else
138- case ( @pass_count % 10 )
147+ zen_statement = case ( @pass_count % 10 )
139148 when 0
140- puts "mountains are merely mountains"
149+ "mountains are merely mountains"
141150 when 1 , 2
142- puts "learn the rules so you know how to break them properly"
151+ "learn the rules so you know how to break them properly"
143152 when 3 , 4
144- puts "remember that silence is sometimes the best answer"
153+ "remember that silence is sometimes the best answer"
145154 when 5 , 6
146- puts "sleep is the best meditation"
155+ "sleep is the best meditation"
147156 when 7 , 8
148- puts "when you lose, don't lose the lesson"
157+ "when you lose, don't lose the lesson"
149158 else
150- puts "things are not what they appear to be: nor are they otherwise"
159+ "things are not what they appear to be: nor are they otherwise"
151160 end
152161 end
162+ zen_statement
153163 end
154164 end
155165
@@ -189,7 +199,7 @@ def method_added(name)
189199
190200 def run_tests ( accumulator )
191201 puts
192- puts "Thinking #{ self } "
202+ puts Color . green ( "Thinking #{ self } " )
193203 testmethods . each do |m |
194204 self . run_test ( m , accumulator ) if Koan . test_pattern =~ m . to_s
195205 end
0 commit comments