Skip to content
Browse files

Initial commit forked from original Ruby koans repo

  • Loading branch information...
0 parents commit d1494a64c08cc673c31d3403e262a1405ae7f18d @sathish316 sathish316 committed Aug 28, 2011
Showing with 846 additions and 0 deletions.
  1. +146 −0 README.rdoc
  2. +166 −0 Rakefile
  3. +12 −0 koans/Rakefile
  4. +471 −0 koans/edgecase.rb
  5. +3 −0 koans/path_to_enlightenment.rb
  6. +7 −0 koans/test_helper.rb
  7. +33 −0 rakelib/checks.rake
  8. +8 −0 rakelib/run.rake
146 README.rdoc
@@ -0,0 +1,146 @@
+= EdgeCase Ruby Koans
+
+The Ruby Koans walk you along the path to enlightenment in order to learn Ruby.
+The goal is to learn the Ruby language, syntax, structure, and some common
+functions and libraries. We also teach you culture. Testing is not just something we
+pay lip service to, but something we live. It is essential in your quest to learn
+and do great things in the language.
+
+== The Structure
+
+The koans are broken out into areas by file, hashes are covered in about_hashes.rb,
+modules are introduced in about_modules.rb, etc. They are presented in order in the
+path_to_enlightenment.rb file.
+
+Each koan builds up your knowledge of Ruby and builds upon itself. It will stop at
+the first place you need to correct.
+
+Some koans simply need to have the correct answer substituted for an incorrect one.
+Some, however, require you to supply your own answer. If you see the method +__+ (a
+double underscore) listed, it is a hint to you to supply your own code in order to
+make it work correctly.
+
+== Installing Ruby
+
+If you do not have Ruby setup, please visit http://ruby-lang.org/en/downloads/ for
+operating specific instructions. In order to run this you need ruby and rake
+installed. To check the installations simply type:
+
+*nix platforms from any terminal window:
+
+ [~] $ ruby --version
+ [~] $ rake --version
+
+Windows from the command prompt (cmd.exe)
+
+ c:\ruby --version
+ c:\rake --version
+
+If you don't have rake installed, just run `gem install rake`
+
+Any response for Ruby with a version number greater than 1.8 is fine (should be
+around 1.8.6 or more). Any version of rake will do.
+
+== The Path To Enlightenment
+
+You can run the tests through rake or by calling the file itself (rake is the
+recommended way to run them as we might build more functionality into this task).
+
+*nix platforms, from the koans directory
+
+ [ruby_koans] $ rake # runs the default target :walk_the_path
+ [ruby_koans] $ ruby path_to_enlightenment.rb # simply call the file directly
+
+Windows is the same thing
+
+ c:\ruby_koans\rake # runs the default target :walk_the_path
+ c:\ruby_koans\ruby path_to_enlightenment.rb # simply call the file directly
+
+=== Red, Green, Refactor
+
+In test-driven development the mantra has always been, red, green, refactor. Write a
+failing test and run it (red), make the test pass (green), then refactor it (that is
+look at the code and see if you can make it any better. In this case you will need
+to run the koan and see it fail (red), make the test pass (green), then take a
+moment and reflect upon the test to see what it is teaching you and improve the
+code to better communicate its intent (refactor).
+
+The very first time you run it you will see the following output:
+
+ [ ruby_koans ] $ rake
+ (in /Users/person/dev/ruby_koans)
+ cd koans
+
+ Thinking AboutAsserts
+ test_assert_truth has damaged your karma.
+
+ You have not yet reached enlightenment ...
+ <false> is not true.
+
+ Please meditate on the following code:
+ ./about_asserts.rb:10:in `test_assert_truth'
+ path_to_enlightenment.rb:27
+
+ mountains are merely mountains
+
+You have come to your first stage. If you notice it is telling you where to look for
+the first solution:
+
+ Please meditate on the following code:
+ ./about_asserts.rb:10:in `test_assert_truth'
+ path_to_enlightenment.rb:27
+
+We then open up the about_asserts.rb file and look at the first test:
+
+ # We shall contemplate truth by testing reality, via asserts.
+ def test_assert_truth
+ assert false # This should be true
+ end
+
+We then change the +false+ to +true+ and run the test again. After you are
+done, think about what you are learning. In this case, ignore everything except
+the method name (+test_assert_truth+) and the parts inside the method (everything
+before the +end+).
+
+In this case the goal is for you to see that if you pass a value to the +assert+
+method, it will either ensure it is +true+ and continue on, or fail if in fact
+the statement is +false+.
+
+== Inspiration
+
+A special thanks to Mike Clark and Ara Howard for inspiring this
+project. Mike Clark wrote an excellent blog post about learning Ruby
+through unit testing. This sparked an idea that has taken a bit to
+solidify, that of bringing new rubyists into the community through
+testing. Ara Howard then gave us the idea for the Koans in his ruby
+quiz entry on Meta Koans (a must for any rubyist wanting to improve
+their skills). Also, "The Little Lisper" taught us all the value of
+the short questions/simple answers style of learning.
+
+Mike Clark's post :: http://www.clarkware.com/cgi/blosxom/2005/03/18
+Meta Koans :: http://rubyquiz.com/quiz67.html
+The Little Lisper :: http://www.amazon.com/Little-LISPer-Third-Daniel-Friedman/dp/0023397632
+
+== Other Resources
+
+The Ruby Language :: http://ruby-lang.org
+Try Ruby in your browser :: http://tryruby.org
+
+Dave Thomas' introduction to Ruby Programming Ruby (the Pick Axe) :: http://pragprog.com/titles/ruby/programming-ruby
+
+Brian Marick's fantastic guide for beginners Everyday Scripting with Ruby :: http://pragprog.com/titles/bmsft/everyday-scripting-with-ruby
+
+= Other stuff
+
+Author :: Jim Weirich <jim@weirichhouse.org>
+Author :: Joe O'Brien <joe@edgecase.com>
+Issue Tracker :: http://www.pivotaltracker.com/projects/48111
+Requires :: Ruby 1.8.x or later and Rake (any recent version)
+
+= License
+
+http://i.creativecommons.org/l/by-nc-sa/3.0/88x31.png
+
+RubyKoans is released under a Creative Commons,
+Attribution-NonCommercial-ShareAlike, Version 3.0
+(http://creativecommons.org/licenses/by-nc-sa/3.0/) License.
166 Rakefile
@@ -0,0 +1,166 @@
+#!/usr/bin/env ruby
+# -*- ruby -*-
+
+require 'rake/clean'
+require 'rake/rdoctask'
+
+SRC_DIR = 'src'
+PROB_DIR = 'koans'
+DIST_DIR = 'dist'
+
+SRC_FILES = FileList["#{SRC_DIR}/*"]
+KOAN_FILES = SRC_FILES.pathmap("#{PROB_DIR}/%f")
+
+today = Time.now.strftime("%Y-%m-%d")
+TAR_FILE = "#{DIST_DIR}/rubykoans-#{today}.tgz"
+ZIP_FILE = "#{DIST_DIR}/rubykoans-#{today}.zip"
+
+CLEAN.include("**/*.rbc")
+CLOBBER.include(DIST_DIR)
+
+module Koans
+ # Remove solution info from source
+ # __(a,b) => __
+ # _n_(number) => __
+ # # __ =>
+ def Koans.remove_solution(line)
+ line = line.gsub(/\b____\([^\)]+\)/, "____")
+ line = line.gsub(/\b___\([^\)]+\)/, "___")
+ line = line.gsub(/\b__\([^\)]+\)/, "__")
+ line = line.gsub(/\b_n_\([^\)]+\)/, "_n_")
+ line = line.gsub(%r(/\#\{__\}/), "/__/")
+ line = line.gsub(/\s*#\s*__\s*$/, '')
+ line
+ end
+
+ def Koans.make_koan_file(infile, outfile)
+ if infile =~ /edgecase/
+ cp infile, outfile
+ elsif infile =~ /autotest/
+ cp_r infile, outfile
+ else
+ open(infile) do |ins|
+ open(outfile, "w") do |outs|
+ state = :copy
+ ins.each do |line|
+ state = :skip if line =~ /^ *#--/
+ case state
+ when :copy
+ outs.puts remove_solution(line)
+ else
+ # do nothing
+ end
+ state = :copy if line =~ /^ *#\+\+/
+ end
+ end
+ end
+ end
+ end
+end
+
+module RubyImpls
+ # Calculate the list of relevant Ruby implementations.
+ def self.find_ruby_impls
+ rubys = `rvm list`.gsub(/=>/,'').split(/\n/).sort
+ expected.map { |impl|
+ last = rubys.grep(Regexp.new(Regexp.quote(impl))).last
+ last ? last.split.first : nil
+ }.compact
+ end
+
+ # Return a (cached) list of relevant Ruby implementations.
+ def self.list
+ @list ||= find_ruby_impls
+ end
+
+ # List of expected ruby implementations.
+ def self.expected
+ %w(ruby-1.8.6 ruby-1.8.7 ruby-1.9.2 jruby ree)
+ end
+end
+
+task :default => :walk_the_path
+
+task :walk_the_path do
+ cd 'koans'
+ ruby 'path_to_enlightenment.rb'
+end
+
+Rake::RDocTask.new do |rd|
+ rd.main = "README.rdoc"
+ rd.rdoc_files.include("README.rdoc", "koans/*.rb")
+end
+
+directory DIST_DIR
+directory PROB_DIR
+
+file ZIP_FILE => KOAN_FILES + [DIST_DIR] do
+ sh "zip #{ZIP_FILE} #{PROB_DIR}/*"
+end
+
+file TAR_FILE => KOAN_FILES + [DIST_DIR] do
+ sh "tar zcvf #{TAR_FILE} #{PROB_DIR}"
+end
+
+desc "Create packaged files for distribution"
+task :package => [TAR_FILE, ZIP_FILE]
+
+desc "Upload the package files to the web server"
+task :upload => [TAR_FILE, ZIP_FILE] do
+ sh "scp #{TAR_FILE} linode:sites/onestepback.org/download"
+ sh "scp #{ZIP_FILE} linode:sites/onestepback.org/download"
+end
+
+desc "Generate the Koans from the source files from scratch."
+task :regen => [:clobber_koans, :gen]
+
+desc "Generate the Koans from the changed source files."
+task :gen => KOAN_FILES + [PROB_DIR + "/README.rdoc"]
+task :clobber_koans do
+ rm_r PROB_DIR
+end
+
+file PROB_DIR + "/README.rdoc" => "README.rdoc" do |t|
+ cp "README.rdoc", t.name
+end
+
+SRC_FILES.each do |koan_src|
+ file koan_src.pathmap("#{PROB_DIR}/%f") => [PROB_DIR, koan_src] do |t|
+ Koans.make_koan_file koan_src, t.name
+ end
+end
+
+task :run do
+ puts 'koans'
+ Dir.chdir("src") do
+ puts "in #{Dir.pwd}"
+ sh "ruby path_to_enlightenment.rb"
+ end
+end
+
+
+desc "Pre-checkin tests (=> run_all)"
+task :cruise => :run_all
+
+desc "Run the completed koans againts a list of relevant Ruby Implementations"
+task :run_all do
+ results = []
+ RubyImpls.list.each do |impl|
+ puts "=" * 40
+ puts "On Ruby #{impl}"
+ sh "rvm #{impl} rake run"
+ results << [impl, "RAN"]
+ puts
+ end
+ puts "=" * 40
+ puts "Summary:"
+ puts
+ results.each do |impl, res|
+ puts "#{impl} => RAN"
+ end
+ puts
+ RubyImpls.expected.each do |requested_impl|
+ impl_pattern = Regexp.new(Regexp.quote(requested_impl))
+ puts "No Results for #{requested_impl}" unless results.detect { |x| x.first =~ impl_pattern }
+ end
+end
12 koans/Rakefile
@@ -0,0 +1,12 @@
+#!/usr/bin/env ruby
+# -*- ruby -*-
+
+require 'rake/clean'
+require 'rake/testtask'
+
+task :default => :test
+
+task :test do
+ ruby 'path_to_enlightenment.rb'
+end
+
471 koans/edgecase.rb
@@ -0,0 +1,471 @@
+#!/usr/bin/env ruby
+# -*- ruby -*-
+
+require 'test/unit/assertions'
+
+# --------------------------------------------------------------------
+# Support code for the Ruby Koans.
+# --------------------------------------------------------------------
+
+class FillMeInError < StandardError
+end
+
+def ruby_version?(version)
+ RUBY_VERSION =~ /^#{version}/ ||
+ (version == 'jruby' && defined?(JRUBY_VERSION)) ||
+ (version == 'mri' && ! defined?(JRUBY_VERSION))
+end
+
+def in_ruby_version(*versions)
+ yield if versions.any? { |v| ruby_version?(v) }
+end
+
+# Standard, generic replacement value.
+# If value19 is given, it is used in place of value for Ruby 1.9.
+def __(value="FILL ME IN", value19=:mu)
+ if RUBY_VERSION < "1.9"
+ value
+ else
+ (value19 == :mu) ? value : value19
+ end
+end
+
+# Numeric replacement value.
+def _n_(value=999999, value19=:mu)
+ if RUBY_VERSION < "1.9"
+ value
+ else
+ (value19 == :mu) ? value : value19
+ end
+end
+
+# Error object replacement value.
+def ___(value=FillMeInError)
+ value
+end
+
+# Method name replacement.
+class Object
+ def ____(method=nil)
+ if method
+ self.send(method)
+ end
+ end
+
+ in_ruby_version("1.9") do
+ public :method_missing
+ end
+end
+
+class String
+ def side_padding(width)
+ extra = width - self.size
+ if width < 0
+ self
+ else
+ left_padding = extra / 2
+ right_padding = (extra+1)/2
+ (" " * left_padding) + self + (" " *right_padding)
+ end
+ end
+end
+
+module EdgeCase
+ class << self
+ def simple_output
+ ENV['SIMPLE_KOAN_OUTPUT'] == 'true'
+ end
+ end
+
+ module Color
+ #shamelessly stolen (and modified) from redgreen
+ COLORS = {
+ :clear => 0, :black => 30, :red => 31,
+ :green => 32, :yellow => 33, :blue => 34,
+ :magenta => 35, :cyan => 36,
+ }
+
+ module_function
+
+ COLORS.each do |color, value|
+ module_eval "def #{color}(string); colorize(string, #{value}); end"
+ module_function color
+ end
+
+ def colorize(string, color_value)
+ if use_colors?
+ color(color_value) + string + color(COLORS[:clear])
+ else
+ string
+ end
+ end
+
+ def color(color_value)
+ "\e[#{color_value}m"
+ end
+
+ def use_colors?
+ return false if ENV['NO_COLOR']
+ if ENV['ANSI_COLOR'].nil?
+ ! using_windows?
+ else
+ ENV['ANSI_COLOR'] =~ /^(t|y)/i
+ end
+ end
+
+ def using_windows?
+ File::ALT_SEPARATOR
+ end
+ end
+
+ class Sensei
+ attr_reader :failure, :failed_test, :pass_count
+
+ in_ruby_version("1.8") do
+ AssertionError = Test::Unit::AssertionFailedError
+ end
+
+ in_ruby_version("1.9") do
+ if defined?(MiniTest)
+ AssertionError = MiniTest::Assertion
+ else
+ AssertionError = Test::Unit::AssertionFailedError
+ end
+ end
+
+ def initialize
+ @pass_count = 0
+ @failure = nil
+ @failed_test = nil
+ @observations = []
+ end
+
+ PROGRESS_FILE_NAME = '.path_progress'
+
+ def add_progress(prog)
+ @_contents = nil
+ exists = File.exists?(PROGRESS_FILE_NAME)
+ File.open(PROGRESS_FILE_NAME,'a+') do |f|
+ f.print "#{',' if exists}#{prog}"
+ end
+ end
+
+ def progress
+ if @_contents.nil?
+ if File.exists?(PROGRESS_FILE_NAME)
+ File.open(PROGRESS_FILE_NAME,'r') do |f|
+ @_contents = f.read.to_s.gsub(/\s/,'').split(',')
+ end
+ else
+ @_contents = []
+ end
+ end
+ @_contents
+ end
+
+ def observe(step)
+ if step.passed?
+ @pass_count += 1
+ if @pass_count > progress.last.to_i
+ @observations << Color.green("#{step.koan_file}##{step.name} has expanded your awareness.")
+ end
+ else
+ @failed_test = step
+ @failure = step.failure
+ add_progress(@pass_count)
+ @observations << Color.red("#{step.koan_file}##{step.name} has damaged your karma.")
+ throw :edgecase_exit
+ end
+ end
+
+ def failed?
+ ! @failure.nil?
+ end
+
+ def assert_failed?
+ failure.is_a?(AssertionError)
+ end
+
+ def instruct
+ if failed?
+ @observations.each{|c| puts c }
+ encourage
+ guide_through_error
+ a_zenlike_statement
+ show_progress
+ else
+ end_screen
+ end
+ end
+
+ def show_progress
+ bar_width = 50
+ total_tests = EdgeCase::Koan.total_tests
+ scale = bar_width.to_f/total_tests
+ print Color.green("your path thus far [")
+ happy_steps = (pass_count*scale).to_i
+ happy_steps = 1 if happy_steps == 0 && pass_count > 0
+ print Color.green('.'*happy_steps)
+ if failed?
+ print Color.red('X')
+ print Color.cyan('_'*(bar_width-1-happy_steps))
+ end
+ print Color.green(']')
+ print " #{pass_count}/#{total_tests}"
+ puts
+ end
+
+ def end_screen
+ if EdgeCase.simple_output
+ boring_end_screen
+ else
+ artistic_end_screen
+ end
+ end
+
+ def boring_end_screen
+ puts "Mountains are again merely mountains"
+ end
+
+ def artistic_end_screen
+ "JRuby 1.9.x Koans"
+ ruby_version = "(in #{'J' if defined?(JRUBY_VERSION)}Ruby #{defined?(JRUBY_VERSION) ? JRUBY_VERSION : RUBY_VERSION})"
+ ruby_version = ruby_version.side_padding(54)
+ completed = <<-ENDTEXT
+ ,, , ,,
+ : ::::, :::,
+ , ,,: :::::::::::::,, :::: : ,
+ , ,,, ,:::::::::::::::::::, ,: ,: ,,
+ :, ::, , , :, ,::::::::::::::::::, ::: ,::::
+ : : ::, ,:::::::: ::, ,::::
+ , ,::::: :,:::::::,::::,
+ ,: , ,:,,: :::::::::::::
+ ::,: ,,:::, ,::::::::::::,
+ ,:::, :,,::: ::::::::::::,
+ ,::: :::::::, Mountains are again merely mountains ,::::::::::::
+ :::,,,:::::: ::::::::::::
+ ,:::::::::::, ::::::::::::,
+ :::::::::::, ,::::::::::::
+::::::::::::: ,::::::::::::
+:::::::::::: Ruby Koans ::::::::::::,
+::::::::::::#{ ruby_version },::::::::::::,
+:::::::::::, , ::::::::::::
+,:::::::::::::, brought to you by ,,::::::::::::,
+:::::::::::::: ,::::::::::::
+ ::::::::::::::, ,:::::::::::::
+ ::::::::::::, EdgeCase Software Artisans , ::::::::::::
+ :,::::::::: :::: :::::::::::::
+ ,::::::::::: ,: ,,:::::::::::::,
+ :::::::::::: ,::::::::::::::,
+ :::::::::::::::::, ::::::::::::::::
+ :::::::::::::::::::, ::::::::::::::::
+ ::::::::::::::::::::::, ,::::,:, , ::::,:::
+ :::::::::::::::::::::::, ::,: ::,::, ,,: ::::
+ ,:::::::::::::::::::: ::,, , ,, ,::::
+ ,:::::::::::::::: ::,, , ,:::,
+ ,:::: , ,,
+ ,,,
+ENDTEXT
+ puts completed
+ end
+
+ def encourage
+ puts
+ puts "The Master says:"
+ puts Color.cyan(" You have not yet reached enlightenment.")
+ if ((recents = progress.last(5)) && recents.size == 5 && recents.uniq.size == 1)
+ puts Color.cyan(" I sense frustration. Do not be afraid to ask for help.")
+ elsif progress.last(2).size == 2 && progress.last(2).uniq.size == 1
+ puts Color.cyan(" Do not lose hope.")
+ elsif progress.last.to_i > 0
+ puts Color.cyan(" You are progressing. Excellent. #{progress.last} completed.")
+ end
+ end
+
+ def guide_through_error
+ puts
+ puts "The answers you seek..."
+ puts Color.red(indent(failure.message).join)
+ puts
+ puts "Please meditate on the following code:"
+ if assert_failed?
+ puts embolden_first_line_only(indent(find_interesting_lines(failure.backtrace)))
+ else
+ puts embolden_first_line_only(indent(failure.backtrace))
+ end
+ puts
+ end
+
+ def embolden_first_line_only(text)
+ first_line = true
+ text.collect { |t|
+ if first_line
+ first_line = false
+ Color.red(t)
+ else
+ Color.cyan(t)
+ end
+ }
+ end
+
+ def indent(text)
+ text = text.split(/\n/) if text.is_a?(String)
+ text.collect{|t| " #{t}"}
+ end
+
+ def find_interesting_lines(backtrace)
+ backtrace.reject { |line|
+ line =~ /test\/unit\/|edgecase\.rb|minitest/
+ }
+ end
+
+ # Hat's tip to Ara T. Howard for the zen statements from his
+ # metakoans Ruby Quiz (http://rubyquiz.com/quiz67.html)
+ def a_zenlike_statement
+ if !failed?
+ zen_statement = "Mountains are again merely mountains"
+ else
+ zen_statement = case (@pass_count % 10)
+ when 0
+ "mountains are merely mountains"
+ when 1, 2
+ "learn the rules so you know how to break them properly"
+ when 3, 4
+ "remember that silence is sometimes the best answer"
+ when 5, 6
+ "sleep is the best meditation"
+ when 7, 8
+ "when you lose, don't lose the lesson"
+ else
+ "things are not what they appear to be: nor are they otherwise"
+ end
+ end
+ puts Color.green(zen_statement)
+ end
+ end
+
+ class Koan
+ include Test::Unit::Assertions
+
+ attr_reader :name, :failure, :koan_count, :step_count, :koan_file
+
+ def initialize(name, koan_file=nil, koan_count=0, step_count=0)
+ @name = name
+ @failure = nil
+ @koan_count = koan_count
+ @step_count = step_count
+ @koan_file = koan_file
+ end
+
+ def passed?
+ @failure.nil?
+ end
+
+ def failed(failure)
+ @failure = failure
+ end
+
+ def setup
+ end
+
+ def teardown
+ end
+
+ def meditate
+ setup
+ begin
+ send(name)
+ rescue StandardError, EdgeCase::Sensei::AssertionError => ex
+ failed(ex)
+ ensure
+ begin
+ teardown
+ rescue StandardError, EdgeCase::Sensei::AssertionError => ex
+ failed(ex) if passed?
+ end
+ end
+ self
+ end
+
+ # Class methods for the EdgeCase test suite.
+ class << self
+ def inherited(subclass)
+ subclasses << subclass
+ end
+
+ def method_added(name)
+ testmethods << name if !tests_disabled? && Koan.test_pattern =~ name.to_s
+ end
+
+ def end_of_enlightenment
+ @tests_disabled = true
+ end
+
+ def command_line(args)
+ args.each do |arg|
+ case arg
+ when /^-n\/(.*)\/$/
+ @test_pattern = Regexp.new($1)
+ when /^-n(.*)$/
+ @test_pattern = Regexp.new(Regexp.quote($1))
+ else
+ if File.exist?(arg)
+ load(arg)
+ else
+ fail "Unknown command line argument '#{arg}'"
+ end
+ end
+ end
+ end
+
+ # Lazy initialize list of subclasses
+ def subclasses
+ @subclasses ||= []
+ end
+
+ # Lazy initialize list of test methods.
+ def testmethods
+ @test_methods ||= []
+ end
+
+ def tests_disabled?
+ @tests_disabled ||= false
+ end
+
+ def test_pattern
+ @test_pattern ||= /^test_/
+ end
+
+ def total_tests
+ self.subclasses.inject(0){|total, k| total + k.testmethods.size }
+ end
+ end
+ end
+
+ class ThePath
+ def walk
+ sensei = EdgeCase::Sensei.new
+ each_step do |step|
+ sensei.observe(step.meditate)
+ end
+ sensei.instruct
+ end
+
+ def each_step
+ catch(:edgecase_exit) {
+ step_count = 0
+ EdgeCase::Koan.subclasses.each_with_index do |koan,koan_index|
+ koan.testmethods.each do |method_name|
+ step = koan.new(method_name, koan.to_s, koan_index+1, step_count+=1)
+ yield step
+ end
+ end
+ }
+ end
+ end
+end
+
+END {
+ EdgeCase::Koan.command_line(ARGV)
+ EdgeCase::ThePath.new.walk
+}
3 koans/path_to_enlightenment.rb
@@ -0,0 +1,3 @@
+# The path to Ruby Enlightenment starts with the following:
+
+$LOAD_PATH << File.dirname(__FILE__)
7 koans/test_helper.rb
@@ -0,0 +1,7 @@
+require 'test/unit'
+
+def __
+ "FILL ME IN"
+end
+
+EdgeCase = Test::Unit
33 rakelib/checks.rake
@@ -0,0 +1,33 @@
+namespace "check" do
+
+ desc "Check that the require files match the about_* files"
+ task :abouts do
+ about_files = Dir['src/about_*.rb'].size
+ about_requires = `grep require src/path_to_enlightenment.rb | wc -l`.to_i
+ puts "Checking path_to_enlightenment completeness"
+ puts "# of about files: #{about_files}"
+ puts "# of about requires: #{about_requires}"
+ if about_files > about_requires
+ puts "*** There seems to be requires missing in the path to enlightenment"
+ else
+ puts "OK"
+ end
+ puts
+ end
+
+ desc "Check that asserts have __ replacements"
+ task :asserts do
+ puts "Checking for asserts missing the replacement text:"
+ begin
+ sh "egrep -n 'assert( |_)' src/about_* | egrep -v '__|_n_|project|about_assert' | egrep -v ' *#'"
+ puts
+ puts "Examine the above lines for missing __ replacements"
+ rescue RuntimeError => ex
+ puts "OK"
+ end
+ puts
+ end
+end
+
+desc "Run some simple consistency checks"
+task :check => ["check:abouts", "check:asserts"]
8 rakelib/run.rake
@@ -0,0 +1,8 @@
+RUBIES = ENV['KOAN_RUBIES'] || %w(ruby-1.8.7-p299,ruby-1.9.2-p0,jruby-1.5.2,jruby-head)
+
+task :runall do
+ chdir('src') do
+ ENV['SIMPLE_KOAN_OUTPUT'] = 'true'
+ sh "rvm #{RUBIES} path_to_enlightenment.rb"
+ end
+end

0 comments on commit d1494a6

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