mirror of
https://github.com/edgecase/ruby_koans.git
synced 2026-04-19 08:43:20 -04:00
Compare commits
1 Commits
rubykoans-
...
become_the
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d27004c70d |
@@ -22,8 +22,8 @@ class AboutExceptions < EdgeCase::Koan
|
|||||||
|
|
||||||
assert_equal __, result
|
assert_equal __, result
|
||||||
|
|
||||||
assert_equal __, ex.is_a?(StandardError), "Should be a Standard Error"
|
assert ex.is_a?(___), "Failure message."
|
||||||
assert_equal __, ex.is_a?(RuntimeError), "Should be a Runtime Error"
|
assert ex.is_a?(___), "Failure message."
|
||||||
|
|
||||||
assert RuntimeError.ancestors.include?(StandardError),
|
assert RuntimeError.ancestors.include?(StandardError),
|
||||||
"RuntimeError is a subclass of StandardError"
|
"RuntimeError is a subclass of StandardError"
|
||||||
|
|||||||
118
koans/about_sensei.rb
Normal file
118
koans/about_sensei.rb
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
||||||
|
|
||||||
|
class Sensei
|
||||||
|
def observe(step)
|
||||||
|
# Step Protocol: step.passed? | step.failure | step.koan_file | step.name
|
||||||
|
# WRITE THIS CODE
|
||||||
|
end
|
||||||
|
|
||||||
|
def pass_count
|
||||||
|
# WRITE THIS CODE
|
||||||
|
end
|
||||||
|
|
||||||
|
def failed?
|
||||||
|
# WRITE THIS CODE
|
||||||
|
end
|
||||||
|
|
||||||
|
def instruct
|
||||||
|
# WRITE THIS CODE
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def student_passes_test
|
||||||
|
assert true # DO NOT CHANGE YOUR STUDENT'S ANSWER
|
||||||
|
end
|
||||||
|
|
||||||
|
def student_fails_test
|
||||||
|
assert false # DO NOT CHANGE YOUR STUDENT'S ANSWER
|
||||||
|
end
|
||||||
|
|
||||||
|
class AboutSensei < EdgeCase::Koan
|
||||||
|
def test_sensei_comments_about_expanded_awareness
|
||||||
|
you = Sensei.new
|
||||||
|
student_step = EdgeCase::Koan.new(:student_passes_test, self)
|
||||||
|
student_meditation = student_step.meditate
|
||||||
|
observation = you.observe(student_meditation)
|
||||||
|
assert_equal "AboutSensei#student_passes_test has expanded your awareness.", observation
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_sensei_comments_about_damaged_karma
|
||||||
|
you = Sensei.new
|
||||||
|
student_step = EdgeCase::Koan.new(:student_fails_test, self)
|
||||||
|
student_meditation = student_step.meditate
|
||||||
|
observation = you.observe(student_meditation)
|
||||||
|
assert_equal "AboutSensei#student_fails_test has damaged your karma.", observation
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_sensei_counts_passed_steps
|
||||||
|
you = Sensei.new
|
||||||
|
student_steps = [EdgeCase::Koan.new(:student_passes_test, self),
|
||||||
|
EdgeCase::Koan.new(:student_passes_test, self),
|
||||||
|
EdgeCase::Koan.new(:student_passes_test, self),
|
||||||
|
EdgeCase::Koan.new(:student_passes_test, self),
|
||||||
|
EdgeCase::Koan.new(:student_fails_test, self)]
|
||||||
|
student_steps.each do |step|
|
||||||
|
you.observe step.meditate
|
||||||
|
end
|
||||||
|
assert_equal 4, you.pass_count
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_sensei_reports_failed_true
|
||||||
|
you = Sensei.new
|
||||||
|
student_steps = [EdgeCase::Koan.new(:student_passes_test, self),
|
||||||
|
EdgeCase::Koan.new(:student_fails_test, self)]
|
||||||
|
student_steps.each do |step|
|
||||||
|
you.observe step
|
||||||
|
end
|
||||||
|
assert you.failed?
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_sensei_reports_failed_true
|
||||||
|
you = Sensei.new
|
||||||
|
student_steps = [EdgeCase::Koan.new(:student_passes_test, self),
|
||||||
|
EdgeCase::Koan.new(:student_passes_test, self)]
|
||||||
|
student_steps.each do |step|
|
||||||
|
you.observe step
|
||||||
|
end
|
||||||
|
assert ! you.failed?
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_sensei_shows_beginning_progress
|
||||||
|
you = Sensei.new
|
||||||
|
student_steps = [EdgeCase::Koan.new(:student_fails_test, self),
|
||||||
|
EdgeCase::Koan.new(:student_fails_test, self),
|
||||||
|
EdgeCase::Koan.new(:student_fails_test, self),
|
||||||
|
EdgeCase::Koan.new(:student_fails_test, self),
|
||||||
|
EdgeCase::Koan.new(:student_fails_test, self)]
|
||||||
|
student_steps.each do |step|
|
||||||
|
you.observe step.meditate
|
||||||
|
end
|
||||||
|
instructions = you.instruct
|
||||||
|
assert_match "You have not yet reached enlightenment", instructions
|
||||||
|
assert_match "You have passed 0 steps", instructions
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_sensei_shows_partial_progress
|
||||||
|
you = Sensei.new
|
||||||
|
student_steps = [EdgeCase::Koan.new(:student_passes_test, self),
|
||||||
|
EdgeCase::Koan.new(:student_passes_test, self),
|
||||||
|
EdgeCase::Koan.new(:student_passes_test, self),
|
||||||
|
EdgeCase::Koan.new(:student_fails_test, self),
|
||||||
|
EdgeCase::Koan.new(:student_fails_test, self)]
|
||||||
|
student_steps.each do |step|
|
||||||
|
you.observe step.meditate
|
||||||
|
end
|
||||||
|
instructions = you.instruct
|
||||||
|
assert_match "You have not yet reached enlightenment", instructions
|
||||||
|
assert_match "You have passed 3 steps", instructions
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_sensei_congratulates_student
|
||||||
|
you = Sensei.new
|
||||||
|
# run all of Ruby Koans with you as the sensei
|
||||||
|
EdgeCase::ThePath.new(you).walk
|
||||||
|
|
||||||
|
instructions = you.instruct
|
||||||
|
assert_match "The student has become the master", instructions
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -53,7 +53,7 @@ class AboutSymbols < EdgeCase::Koan
|
|||||||
assert_equal symbol, __.to_sym
|
assert_equal symbol, __.to_sym
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_symbols_with_interpolation_can_be_built
|
def test_symbols_with_spaces_can_be_built
|
||||||
value = "and"
|
value = "and"
|
||||||
symbol = :"cats #{value} dogs"
|
symbol = :"cats #{value} dogs"
|
||||||
|
|
||||||
|
|||||||
@@ -93,29 +93,16 @@ module EdgeCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def colorize(string, color_value)
|
def colorize(string, color_value)
|
||||||
if use_colors?
|
if ENV['NO_COLOR']
|
||||||
color(color_value) + string + color(COLORS[:clear])
|
|
||||||
else
|
|
||||||
string
|
string
|
||||||
|
else
|
||||||
|
color(color_value) + string + color(COLORS[:clear])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def color(color_value)
|
def color(color_value)
|
||||||
"\e[#{color_value}m"
|
"\e[#{color_value}m"
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
class Sensei
|
class Sensei
|
||||||
@@ -137,7 +124,10 @@ module EdgeCase
|
|||||||
@pass_count = 0
|
@pass_count = 0
|
||||||
@failure = nil
|
@failure = nil
|
||||||
@failed_test = nil
|
@failed_test = nil
|
||||||
@observations = []
|
end
|
||||||
|
|
||||||
|
def observations
|
||||||
|
@observations ||= []
|
||||||
end
|
end
|
||||||
|
|
||||||
PROGRESS_FILE_NAME = '.path_progress'
|
PROGRESS_FILE_NAME = '.path_progress'
|
||||||
@@ -167,13 +157,13 @@ module EdgeCase
|
|||||||
if step.passed?
|
if step.passed?
|
||||||
@pass_count += 1
|
@pass_count += 1
|
||||||
if @pass_count > progress.last.to_i
|
if @pass_count > progress.last.to_i
|
||||||
@observations << Color.green("#{step.koan_file}##{step.name} has expanded your awareness.")
|
observations << Color.green("#{step.koan_file}##{step.name} has expanded your awareness.")
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@failed_test = step
|
@failed_test = step
|
||||||
@failure = step.failure
|
@failure = step.failure
|
||||||
add_progress(@pass_count)
|
add_progress(@pass_count)
|
||||||
@observations << Color.red("#{step.koan_file}##{step.name} has damaged your karma.")
|
observations << Color.red("#{step.koan_file}##{step.name} has damaged your karma.")
|
||||||
throw :edgecase_exit
|
throw :edgecase_exit
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -188,7 +178,7 @@ module EdgeCase
|
|||||||
|
|
||||||
def instruct
|
def instruct
|
||||||
if failed?
|
if failed?
|
||||||
@observations.each{|c| puts c }
|
observations.each{|c| puts c }
|
||||||
encourage
|
encourage
|
||||||
guide_through_error
|
guide_through_error
|
||||||
a_zenlike_statement
|
a_zenlike_statement
|
||||||
@@ -216,22 +206,23 @@ module EdgeCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def end_screen
|
def end_screen
|
||||||
if EdgeCase.simple_output
|
screen = if EdgeCase.simple_output
|
||||||
boring_end_screen
|
end_message
|
||||||
else
|
else
|
||||||
artistic_end_screen
|
artistic_end_screen
|
||||||
end
|
end
|
||||||
|
puts screen
|
||||||
end
|
end
|
||||||
|
|
||||||
def boring_end_screen
|
def end_message
|
||||||
puts "Mountains are again merely mountains"
|
"The student has become the master"
|
||||||
end
|
end
|
||||||
|
|
||||||
def artistic_end_screen
|
def artistic_end_screen
|
||||||
"JRuby 1.9.x Koans"
|
"JRuby 1.9.x Koans"
|
||||||
ruby_version = "(in #{'J' if defined?(JRUBY_VERSION)}Ruby #{defined?(JRUBY_VERSION) ? JRUBY_VERSION : RUBY_VERSION})"
|
ruby_version = "(in #{'J' if defined?(JRUBY_VERSION)}Ruby #{defined?(JRUBY_VERSION) ? JRUBY_VERSION : RUBY_VERSION})"
|
||||||
ruby_version = ruby_version.side_padding(54)
|
ruby_version = ruby_version.side_padding(54)
|
||||||
completed = <<-ENDTEXT
|
return <<-ENDTEXT
|
||||||
,, , ,,
|
,, , ,,
|
||||||
: ::::, :::,
|
: ::::, :::,
|
||||||
, ,,: :::::::::::::,, :::: : ,
|
, ,,: :::::::::::::,, :::: : ,
|
||||||
@@ -242,7 +233,7 @@ module EdgeCase
|
|||||||
,: , ,:,,: :::::::::::::
|
,: , ,:,,: :::::::::::::
|
||||||
::,: ,,:::, ,::::::::::::,
|
::,: ,,:::, ,::::::::::::,
|
||||||
,:::, :,,::: ::::::::::::,
|
,:::, :,,::: ::::::::::::,
|
||||||
,::: :::::::, Mountains are again merely mountains ,::::::::::::
|
,::: :::::::,#{ end_message.side_padding 48 },::::::::::::
|
||||||
:::,,,:::::: ::::::::::::
|
:::,,,:::::: ::::::::::::
|
||||||
,:::::::::::, ::::::::::::,
|
,:::::::::::, ::::::::::::,
|
||||||
:::::::::::, ,::::::::::::
|
:::::::::::, ,::::::::::::
|
||||||
@@ -266,7 +257,6 @@ module EdgeCase
|
|||||||
,:::: , ,,
|
,:::: , ,,
|
||||||
,,,
|
,,,
|
||||||
ENDTEXT
|
ENDTEXT
|
||||||
puts completed
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def encourage
|
def encourage
|
||||||
@@ -443,23 +433,28 @@ ENDTEXT
|
|||||||
end
|
end
|
||||||
|
|
||||||
class ThePath
|
class ThePath
|
||||||
def walk
|
def initialize(sensei=nil)
|
||||||
sensei = EdgeCase::Sensei.new
|
@sensei = sensei || Sensei.new
|
||||||
each_step do |step|
|
|
||||||
sensei.observe(step.meditate)
|
|
||||||
end
|
end
|
||||||
sensei.instruct
|
|
||||||
|
def walk
|
||||||
|
each_step do |step|
|
||||||
|
@sensei.observe(step.meditate)
|
||||||
|
end
|
||||||
|
@sensei.instruct
|
||||||
end
|
end
|
||||||
|
|
||||||
def each_step
|
def each_step
|
||||||
catch(:edgecase_exit) {
|
catch(:edgecase_exit) {
|
||||||
step_count = 0
|
step_count = 0
|
||||||
EdgeCase::Koan.subclasses.each_with_index do |koan,koan_index|
|
EdgeCase::Koan.subclasses.each_with_index do |koan,koan_index|
|
||||||
|
if @sensei.instance_of?(EdgeCase::Sensei) || (koan.to_s != "AboutSensei")
|
||||||
koan.testmethods.each do |method_name|
|
koan.testmethods.each do |method_name|
|
||||||
step = koan.new(method_name, koan.to_s, koan_index+1, step_count+=1)
|
step = koan.new(method_name, koan.to_s, koan_index+1, step_count+=1)
|
||||||
yield step
|
yield step
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -35,3 +35,4 @@ in_ruby_version("jruby") do
|
|||||||
require 'about_java_interop'
|
require 'about_java_interop'
|
||||||
end
|
end
|
||||||
require 'about_extra_credit'
|
require 'about_extra_credit'
|
||||||
|
require 'about_sensei'
|
||||||
|
|||||||
@@ -22,8 +22,8 @@ class AboutExceptions < EdgeCase::Koan
|
|||||||
|
|
||||||
assert_equal __(:exception_handled), result
|
assert_equal __(:exception_handled), result
|
||||||
|
|
||||||
assert_equal __(true), ex.is_a?(StandardError), "Should be a Standard Error"
|
assert ex.is_a?(___(StandardError)), "Failure message."
|
||||||
assert_equal __(true), ex.is_a?(RuntimeError), "Should be a Runtime Error"
|
assert ex.is_a?(___(RuntimeError)), "Failure message."
|
||||||
|
|
||||||
assert RuntimeError.ancestors.include?(StandardError), # __
|
assert RuntimeError.ancestors.include?(StandardError), # __
|
||||||
"RuntimeError is a subclass of StandardError"
|
"RuntimeError is a subclass of StandardError"
|
||||||
|
|||||||
141
src/about_sensei.rb
Normal file
141
src/about_sensei.rb
Normal file
@@ -0,0 +1,141 @@
|
|||||||
|
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
||||||
|
|
||||||
|
class Sensei
|
||||||
|
def observe(step)
|
||||||
|
# Step Protocol: step.passed? | step.failure | step.koan_file | step.name
|
||||||
|
# WRITE THIS CODE
|
||||||
|
#--
|
||||||
|
@pass_count ||= 0
|
||||||
|
if step.passed?
|
||||||
|
@pass_count += 1
|
||||||
|
"#{step.koan_file.class.to_s}##{step.name} has expanded your awareness."
|
||||||
|
else
|
||||||
|
@failure = step.failure
|
||||||
|
"#{step.koan_file.class.to_s}##{step.name} has damaged your karma."
|
||||||
|
end
|
||||||
|
#++
|
||||||
|
end
|
||||||
|
|
||||||
|
def pass_count
|
||||||
|
# WRITE THIS CODE
|
||||||
|
#--
|
||||||
|
@pass_count
|
||||||
|
#++
|
||||||
|
end
|
||||||
|
|
||||||
|
def failed?
|
||||||
|
# WRITE THIS CODE
|
||||||
|
#--
|
||||||
|
! @failure.nil?
|
||||||
|
#++
|
||||||
|
end
|
||||||
|
|
||||||
|
def instruct
|
||||||
|
# WRITE THIS CODE
|
||||||
|
#--
|
||||||
|
if failed?
|
||||||
|
"You have not yet reached enlightenment. You have passed #{pass_count} steps."
|
||||||
|
else
|
||||||
|
"The student has become the master"
|
||||||
|
end
|
||||||
|
#++
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def student_passes_test
|
||||||
|
assert true # DO NOT CHANGE YOUR STUDENT'S ANSWER
|
||||||
|
end
|
||||||
|
|
||||||
|
def student_fails_test
|
||||||
|
assert false # DO NOT CHANGE YOUR STUDENT'S ANSWER
|
||||||
|
end
|
||||||
|
|
||||||
|
class AboutSensei < EdgeCase::Koan
|
||||||
|
def test_sensei_comments_about_expanded_awareness
|
||||||
|
you = Sensei.new
|
||||||
|
student_step = EdgeCase::Koan.new(:student_passes_test, self)
|
||||||
|
student_meditation = student_step.meditate
|
||||||
|
observation = you.observe(student_meditation)
|
||||||
|
assert_equal "AboutSensei#student_passes_test has expanded your awareness.", observation
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_sensei_comments_about_damaged_karma
|
||||||
|
you = Sensei.new
|
||||||
|
student_step = EdgeCase::Koan.new(:student_fails_test, self)
|
||||||
|
student_meditation = student_step.meditate
|
||||||
|
observation = you.observe(student_meditation)
|
||||||
|
assert_equal "AboutSensei#student_fails_test has damaged your karma.", observation
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_sensei_counts_passed_steps
|
||||||
|
you = Sensei.new
|
||||||
|
student_steps = [EdgeCase::Koan.new(:student_passes_test, self),
|
||||||
|
EdgeCase::Koan.new(:student_passes_test, self),
|
||||||
|
EdgeCase::Koan.new(:student_passes_test, self),
|
||||||
|
EdgeCase::Koan.new(:student_passes_test, self),
|
||||||
|
EdgeCase::Koan.new(:student_fails_test, self)]
|
||||||
|
student_steps.each do |step|
|
||||||
|
you.observe step.meditate
|
||||||
|
end
|
||||||
|
assert_equal 4, you.pass_count
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_sensei_reports_failed_true
|
||||||
|
you = Sensei.new
|
||||||
|
student_steps = [EdgeCase::Koan.new(:student_passes_test, self),
|
||||||
|
EdgeCase::Koan.new(:student_fails_test, self)]
|
||||||
|
student_steps.each do |step|
|
||||||
|
you.observe step
|
||||||
|
end
|
||||||
|
assert you.failed?
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_sensei_reports_failed_true
|
||||||
|
you = Sensei.new
|
||||||
|
student_steps = [EdgeCase::Koan.new(:student_passes_test, self),
|
||||||
|
EdgeCase::Koan.new(:student_passes_test, self)]
|
||||||
|
student_steps.each do |step|
|
||||||
|
you.observe step
|
||||||
|
end
|
||||||
|
assert ! you.failed?
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_sensei_shows_beginning_progress
|
||||||
|
you = Sensei.new
|
||||||
|
student_steps = [EdgeCase::Koan.new(:student_fails_test, self),
|
||||||
|
EdgeCase::Koan.new(:student_fails_test, self),
|
||||||
|
EdgeCase::Koan.new(:student_fails_test, self),
|
||||||
|
EdgeCase::Koan.new(:student_fails_test, self),
|
||||||
|
EdgeCase::Koan.new(:student_fails_test, self)]
|
||||||
|
student_steps.each do |step|
|
||||||
|
you.observe step.meditate
|
||||||
|
end
|
||||||
|
instructions = you.instruct
|
||||||
|
assert_match "You have not yet reached enlightenment", instructions
|
||||||
|
assert_match "You have passed 0 steps", instructions
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_sensei_shows_partial_progress
|
||||||
|
you = Sensei.new
|
||||||
|
student_steps = [EdgeCase::Koan.new(:student_passes_test, self),
|
||||||
|
EdgeCase::Koan.new(:student_passes_test, self),
|
||||||
|
EdgeCase::Koan.new(:student_passes_test, self),
|
||||||
|
EdgeCase::Koan.new(:student_fails_test, self),
|
||||||
|
EdgeCase::Koan.new(:student_fails_test, self)]
|
||||||
|
student_steps.each do |step|
|
||||||
|
you.observe step.meditate
|
||||||
|
end
|
||||||
|
instructions = you.instruct
|
||||||
|
assert_match "You have not yet reached enlightenment", instructions
|
||||||
|
assert_match "You have passed 3 steps", instructions
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_sensei_congratulates_student
|
||||||
|
you = Sensei.new
|
||||||
|
# run all of Ruby Koans with you as the sensei
|
||||||
|
EdgeCase::ThePath.new(you).walk
|
||||||
|
|
||||||
|
instructions = you.instruct
|
||||||
|
assert_match "The student has become the master", instructions
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -53,7 +53,7 @@ class AboutSymbols < EdgeCase::Koan
|
|||||||
assert_equal symbol, __("cats and dogs").to_sym
|
assert_equal symbol, __("cats and dogs").to_sym
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_symbols_with_interpolation_can_be_built
|
def test_symbols_with_spaces_can_be_built
|
||||||
value = "and"
|
value = "and"
|
||||||
symbol = :"cats #{value} dogs"
|
symbol = :"cats #{value} dogs"
|
||||||
|
|
||||||
|
|||||||
@@ -93,29 +93,16 @@ module EdgeCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def colorize(string, color_value)
|
def colorize(string, color_value)
|
||||||
if use_colors?
|
if ENV['NO_COLOR']
|
||||||
color(color_value) + string + color(COLORS[:clear])
|
|
||||||
else
|
|
||||||
string
|
string
|
||||||
|
else
|
||||||
|
color(color_value) + string + color(COLORS[:clear])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def color(color_value)
|
def color(color_value)
|
||||||
"\e[#{color_value}m"
|
"\e[#{color_value}m"
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
class Sensei
|
class Sensei
|
||||||
@@ -137,7 +124,10 @@ module EdgeCase
|
|||||||
@pass_count = 0
|
@pass_count = 0
|
||||||
@failure = nil
|
@failure = nil
|
||||||
@failed_test = nil
|
@failed_test = nil
|
||||||
@observations = []
|
end
|
||||||
|
|
||||||
|
def observations
|
||||||
|
@observations ||= []
|
||||||
end
|
end
|
||||||
|
|
||||||
PROGRESS_FILE_NAME = '.path_progress'
|
PROGRESS_FILE_NAME = '.path_progress'
|
||||||
@@ -167,13 +157,13 @@ module EdgeCase
|
|||||||
if step.passed?
|
if step.passed?
|
||||||
@pass_count += 1
|
@pass_count += 1
|
||||||
if @pass_count > progress.last.to_i
|
if @pass_count > progress.last.to_i
|
||||||
@observations << Color.green("#{step.koan_file}##{step.name} has expanded your awareness.")
|
observations << Color.green("#{step.koan_file}##{step.name} has expanded your awareness.")
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@failed_test = step
|
@failed_test = step
|
||||||
@failure = step.failure
|
@failure = step.failure
|
||||||
add_progress(@pass_count)
|
add_progress(@pass_count)
|
||||||
@observations << Color.red("#{step.koan_file}##{step.name} has damaged your karma.")
|
observations << Color.red("#{step.koan_file}##{step.name} has damaged your karma.")
|
||||||
throw :edgecase_exit
|
throw :edgecase_exit
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -188,7 +178,7 @@ module EdgeCase
|
|||||||
|
|
||||||
def instruct
|
def instruct
|
||||||
if failed?
|
if failed?
|
||||||
@observations.each{|c| puts c }
|
observations.each{|c| puts c }
|
||||||
encourage
|
encourage
|
||||||
guide_through_error
|
guide_through_error
|
||||||
a_zenlike_statement
|
a_zenlike_statement
|
||||||
@@ -216,22 +206,23 @@ module EdgeCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def end_screen
|
def end_screen
|
||||||
if EdgeCase.simple_output
|
screen = if EdgeCase.simple_output
|
||||||
boring_end_screen
|
end_message
|
||||||
else
|
else
|
||||||
artistic_end_screen
|
artistic_end_screen
|
||||||
end
|
end
|
||||||
|
puts screen
|
||||||
end
|
end
|
||||||
|
|
||||||
def boring_end_screen
|
def end_message
|
||||||
puts "Mountains are again merely mountains"
|
"The student has become the master"
|
||||||
end
|
end
|
||||||
|
|
||||||
def artistic_end_screen
|
def artistic_end_screen
|
||||||
"JRuby 1.9.x Koans"
|
"JRuby 1.9.x Koans"
|
||||||
ruby_version = "(in #{'J' if defined?(JRUBY_VERSION)}Ruby #{defined?(JRUBY_VERSION) ? JRUBY_VERSION : RUBY_VERSION})"
|
ruby_version = "(in #{'J' if defined?(JRUBY_VERSION)}Ruby #{defined?(JRUBY_VERSION) ? JRUBY_VERSION : RUBY_VERSION})"
|
||||||
ruby_version = ruby_version.side_padding(54)
|
ruby_version = ruby_version.side_padding(54)
|
||||||
completed = <<-ENDTEXT
|
return <<-ENDTEXT
|
||||||
,, , ,,
|
,, , ,,
|
||||||
: ::::, :::,
|
: ::::, :::,
|
||||||
, ,,: :::::::::::::,, :::: : ,
|
, ,,: :::::::::::::,, :::: : ,
|
||||||
@@ -242,7 +233,7 @@ module EdgeCase
|
|||||||
,: , ,:,,: :::::::::::::
|
,: , ,:,,: :::::::::::::
|
||||||
::,: ,,:::, ,::::::::::::,
|
::,: ,,:::, ,::::::::::::,
|
||||||
,:::, :,,::: ::::::::::::,
|
,:::, :,,::: ::::::::::::,
|
||||||
,::: :::::::, Mountains are again merely mountains ,::::::::::::
|
,::: :::::::,#{ end_message.side_padding 48 },::::::::::::
|
||||||
:::,,,:::::: ::::::::::::
|
:::,,,:::::: ::::::::::::
|
||||||
,:::::::::::, ::::::::::::,
|
,:::::::::::, ::::::::::::,
|
||||||
:::::::::::, ,::::::::::::
|
:::::::::::, ,::::::::::::
|
||||||
@@ -266,7 +257,6 @@ module EdgeCase
|
|||||||
,:::: , ,,
|
,:::: , ,,
|
||||||
,,,
|
,,,
|
||||||
ENDTEXT
|
ENDTEXT
|
||||||
puts completed
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def encourage
|
def encourage
|
||||||
@@ -443,23 +433,28 @@ ENDTEXT
|
|||||||
end
|
end
|
||||||
|
|
||||||
class ThePath
|
class ThePath
|
||||||
def walk
|
def initialize(sensei=nil)
|
||||||
sensei = EdgeCase::Sensei.new
|
@sensei = sensei || Sensei.new
|
||||||
each_step do |step|
|
|
||||||
sensei.observe(step.meditate)
|
|
||||||
end
|
end
|
||||||
sensei.instruct
|
|
||||||
|
def walk
|
||||||
|
each_step do |step|
|
||||||
|
@sensei.observe(step.meditate)
|
||||||
|
end
|
||||||
|
@sensei.instruct
|
||||||
end
|
end
|
||||||
|
|
||||||
def each_step
|
def each_step
|
||||||
catch(:edgecase_exit) {
|
catch(:edgecase_exit) {
|
||||||
step_count = 0
|
step_count = 0
|
||||||
EdgeCase::Koan.subclasses.each_with_index do |koan,koan_index|
|
EdgeCase::Koan.subclasses.each_with_index do |koan,koan_index|
|
||||||
|
if @sensei.instance_of?(EdgeCase::Sensei) || (koan.to_s != "AboutSensei")
|
||||||
koan.testmethods.each do |method_name|
|
koan.testmethods.each do |method_name|
|
||||||
step = koan.new(method_name, koan.to_s, koan_index+1, step_count+=1)
|
step = koan.new(method_name, koan.to_s, koan_index+1, step_count+=1)
|
||||||
yield step
|
yield step
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -35,3 +35,4 @@ in_ruby_version("jruby") do
|
|||||||
require 'about_java_interop'
|
require 'about_java_interop'
|
||||||
end
|
end
|
||||||
require 'about_extra_credit'
|
require 'about_extra_credit'
|
||||||
|
require 'about_sensei'
|
||||||
|
|||||||
Reference in New Issue
Block a user