Permalink
Browse files

Updated koan directory from src.

  • Loading branch information...
1 parent ed2ef0f commit b0a01786f42bfd26da6eea5709a8fc7938e4f80f @jimweirich jimweirich committed Aug 27, 2010
Showing with 59 additions and 22 deletions.
  1. +3 −0 koans/autotest/discover.rb
  2. +24 −0 koans/autotest/rubykoan.rb
  3. +32 −22 koans/edgecase.rb
View
3 koans/autotest/discover.rb
@@ -0,0 +1,3 @@
+Autotest.add_discovery do
+ "rubykoan" if File.exist? 'path_to_enlightenment.rb'
+end
View
24 koans/autotest/rubykoan.rb
@@ -0,0 +1,24 @@
+require 'autotest'
+
+class Autotest::Rubykoan < Autotest
+ def initialize
+ super
+ @exceptions = /\.txt|Rakefile|\.rdoc/
+
+ self.order = :alpha
+ self.add_mapping(/^about_.*rb$/) do |filename, _|
+ filename
+ end
+
+ end
+
+ def make_test_cmd files_to_test
+ "#{ruby} 'path_to_enlightenment.rb'"
+ end
+
+ # quiet test/unit chatter
+ def handle_results(results)
+ end
+
+end
+
View
54 koans/edgecase.rb
@@ -43,23 +43,31 @@ def ____(method=nil)
end
module EdgeCase
+
module Color
#shamelessly stolen (and modified) from redgreen
- COLORS = { :clear => 0, :red => 31, :green => 32, :yellow => 33, :blue => 34, :magenta => 35, :cyan => 36 }
+ COLORS = {
+ :clear => 0, :black => 30, :red => 31,
+ :green => 32, :yellow => 33, :blue => 34,
+ :magenta => 35, :cyan => 36,
+ }
+
+ module_function
COLORS.each do |color, value|
- class_eval "def self.#{color}(string); colorize(string, #{value}); end"
+ module_eval "def #{color}(string); colorize(string, #{value}); end"
+ module_function color
end
- def self.colorize(string, color_value)
+ def colorize(string, color_value)
if ENV['NO_COLOR']
string
else
color(color_value) + string + color(COLORS[:clear])
end
end
- def self.color(color_value)
+ def color(color_value)
"\e[#{color_value}m"
end
end
@@ -88,9 +96,9 @@ def initialize
def accumulate(test)
if test.passed?
@pass_count += 1
- puts " #{test.name} has expanded your awareness."
+ puts Color.green(" #{test.name} has expanded your awareness.")
else
- puts " #{test.name} has damaged your karma."
+ puts Color.red(" #{test.name} has damaged your karma.")
@failed_test = test
@failure = test.failure
throw :edgecase_exit
@@ -108,18 +116,19 @@ def assert_failed?
def report
if failed?
puts
- puts "You have not yet reached enlightenment ..."
- puts failure.message
+ puts Color.green("You have not yet reached enlightenment ...")
+ puts Color.red(failure.message)
puts
- puts "Please meditate on the following code:"
+ puts Color.green("Please meditate on the following code:")
if assert_failed?
- puts find_interesting_lines(failure.backtrace)
+ #puts find_interesting_lines(failure.backtrace)
+ puts find_interesting_lines(failure.backtrace).collect {|l| Color.red(l) }
else
- puts failure.backtrace
+ puts Color.red(failure.backtrace)
end
puts
end
- say_something_zenlike
+ puts Color.green(a_zenlike_statement)
end
def find_interesting_lines(backtrace)
@@ -130,26 +139,27 @@ def find_interesting_lines(backtrace)
# Hat's tip to Ara T. Howard for the zen statements from his
# metakoans Ruby Quiz (http://rubyquiz.com/quiz67.html)
- def say_something_zenlike
+ def a_zenlike_statement
puts
if !failed?
- puts "Mountains are again merely mountains"
+ zen_statement = "Mountains are again merely mountains"
else
- case (@pass_count % 10)
+ zen_statement = case (@pass_count % 10)
when 0
- puts "mountains are merely mountains"
+ "mountains are merely mountains"
when 1, 2
- puts "learn the rules so you know how to break them properly"
+ "learn the rules so you know how to break them properly"
when 3, 4
- puts "remember that silence is sometimes the best answer"
+ "remember that silence is sometimes the best answer"
when 5, 6
- puts "sleep is the best meditation"
+ "sleep is the best meditation"
when 7, 8
- puts "when you lose, don't lose the lesson"
+ "when you lose, don't lose the lesson"
else
- puts "things are not what they appear to be: nor are they otherwise"
+ "things are not what they appear to be: nor are they otherwise"
end
end
+ zen_statement
end
end
@@ -189,7 +199,7 @@ def method_added(name)
def run_tests(accumulator)
puts
- puts "Thinking #{self}"
+ puts Color.green("Thinking #{self}")
testmethods.each do |m|
self.run_test(m, accumulator) if Koan.test_pattern =~ m.to_s
end

0 comments on commit b0a0178

Please sign in to comment.