Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Updated koan directory from src.

  • Loading branch information...
commit b0a01786f42bfd26da6eea5709a8fc7938e4f80f 1 parent ed2ef0f
Jim Weirich jimweirich authored
3  koans/autotest/discover.rb
... ... @@ -0,0 +1,3 @@
  1 +Autotest.add_discovery do
  2 + "rubykoan" if File.exist? 'path_to_enlightenment.rb'
  3 +end
24 koans/autotest/rubykoan.rb
... ... @@ -0,0 +1,24 @@
  1 +require 'autotest'
  2 +
  3 +class Autotest::Rubykoan < Autotest
  4 + def initialize
  5 + super
  6 + @exceptions = /\.txt|Rakefile|\.rdoc/
  7 +
  8 + self.order = :alpha
  9 + self.add_mapping(/^about_.*rb$/) do |filename, _|
  10 + filename
  11 + end
  12 +
  13 + end
  14 +
  15 + def make_test_cmd files_to_test
  16 + "#{ruby} 'path_to_enlightenment.rb'"
  17 + end
  18 +
  19 + # quiet test/unit chatter
  20 + def handle_results(results)
  21 + end
  22 +
  23 +end
  24 +
54 koans/edgecase.rb
@@ -43,15 +43,23 @@ def ____(method=nil)
43 43 end
44 44
45 45 module EdgeCase
  46 +
46 47 module Color
47 48 #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
49 56
50 57 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
52 60 end
53 61
54   - def self.colorize(string, color_value)
  62 + def colorize(string, color_value)
55 63 if ENV['NO_COLOR']
56 64 string
57 65 else
@@ -59,7 +67,7 @@ def self.colorize(string, color_value)
59 67 end
60 68 end
61 69
62   - def self.color(color_value)
  70 + def color(color_value)
63 71 "\e[#{color_value}m"
64 72 end
65 73 end
@@ -88,9 +96,9 @@ def initialize
88 96 def accumulate(test)
89 97 if test.passed?
90 98 @pass_count += 1
91   - puts " #{test.name} has expanded your awareness."
  99 + puts Color.green(" #{test.name} has expanded your awareness.")
92 100 else
93   - puts " #{test.name} has damaged your karma."
  101 + puts Color.red(" #{test.name} has damaged your karma.")
94 102 @failed_test = test
95 103 @failure = test.failure
96 104 throw :edgecase_exit
@@ -108,18 +116,19 @@ def assert_failed?
108 116 def report
109 117 if failed?
110 118 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)
113 121 puts
114   - puts "Please meditate on the following code:"
  122 + puts Color.green("Please meditate on the following code:")
115 123 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) }
117 126 else
118   - puts failure.backtrace
  127 + puts Color.red(failure.backtrace)
119 128 end
120 129 puts
121 130 end
122   - say_something_zenlike
  131 + puts Color.green(a_zenlike_statement)
123 132 end
124 133
125 134 def find_interesting_lines(backtrace)
@@ -130,26 +139,27 @@ def find_interesting_lines(backtrace)
130 139
131 140 # Hat's tip to Ara T. Howard for the zen statements from his
132 141 # metakoans Ruby Quiz (http://rubyquiz.com/quiz67.html)
133   - def say_something_zenlike
  142 + def a_zenlike_statement
134 143 puts
135 144 if !failed?
136   - puts "Mountains are again merely mountains"
  145 + zen_statement = "Mountains are again merely mountains"
137 146 else
138   - case (@pass_count % 10)
  147 + zen_statement = case (@pass_count % 10)
139 148 when 0
140   - puts "mountains are merely mountains"
  149 + "mountains are merely mountains"
141 150 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"
143 152 when 3, 4
144   - puts "remember that silence is sometimes the best answer"
  153 + "remember that silence is sometimes the best answer"
145 154 when 5, 6
146   - puts "sleep is the best meditation"
  155 + "sleep is the best meditation"
147 156 when 7, 8
148   - puts "when you lose, don't lose the lesson"
  157 + "when you lose, don't lose the lesson"
149 158 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"
151 160 end
152 161 end
  162 + zen_statement
153 163 end
154 164 end
155 165
@@ -189,7 +199,7 @@ def method_added(name)
189 199
190 200 def run_tests(accumulator)
191 201 puts
192   - puts "Thinking #{self}"
  202 + puts Color.green("Thinking #{self}")
193 203 testmethods.each do |m|
194 204 self.run_test(m, accumulator) if Koan.test_pattern =~ m.to_s
195 205 end

0 comments on commit b0a0178

Please sign in to comment.
Something went wrong with that request. Please try again.