mirror of
https://github.com/edgecase/ruby_koans.git
synced 2026-04-15 07:23:19 -04:00
Evaluated each assert line without a replacement test specified.
This commit is contained in:
13
Rakefile
13
Rakefile
@@ -18,12 +18,17 @@ ZIP_FILE = "#{DIST_DIR}/rubykoans-#{today}.zip"
|
|||||||
CLOBBER.include(DIST_DIR)
|
CLOBBER.include(DIST_DIR)
|
||||||
|
|
||||||
module Koans
|
module Koans
|
||||||
|
# Remove solution info from source
|
||||||
|
# __(a,b) => __
|
||||||
|
# _n_(number) => __
|
||||||
|
# # __ =>
|
||||||
def Koans.remove_solution(line)
|
def Koans.remove_solution(line)
|
||||||
line = line.gsub(/\b____\([^\)]+\)/, "____")
|
line = line.gsub(/\b____\([^\)]+\)/, "____")
|
||||||
line = line.gsub(/\b___\([^\)]+\)/, "___")
|
line = line.gsub(/\b___\([^\)]+\)/, "___")
|
||||||
line = line.gsub(/\b__\([^\)]+\)/, "__")
|
line = line.gsub(/\b__\([^\)]+\)/, "__")
|
||||||
line = line.gsub(/\b_n_\([^\)]+\)/, "_n_")
|
line = line.gsub(/\b_n_\([^\)]+\)/, "_n_")
|
||||||
line = line.gsub(%r(/\#\{__\}/), "/__/")
|
line = line.gsub(%r(/\#\{__\}/), "/__/")
|
||||||
|
line = line.gsub(/\s*#\s*__\s*$/, '')
|
||||||
line
|
line
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -84,14 +89,6 @@ task :upload => [TAR_FILE, ZIP_FILE] do
|
|||||||
sh "scp #{ZIP_FILE} linode:sites/onestepback.org/download"
|
sh "scp #{ZIP_FILE} linode:sites/onestepback.org/download"
|
||||||
end
|
end
|
||||||
|
|
||||||
desc "Check that the require files match the about_* files"
|
|
||||||
task :check do
|
|
||||||
about_files = Dir['src/about_*.rb'].size
|
|
||||||
about_requires = `grep require src/path_to_enlightenment.rb | wc -l`.to_i
|
|
||||||
puts "# of about files: #{about_files}"
|
|
||||||
puts "# of about requires: #{about_requires}"
|
|
||||||
end
|
|
||||||
|
|
||||||
desc "Generate the Koans from the source files from scratch."
|
desc "Generate the Koans from the source files from scratch."
|
||||||
task :regen => [:clobber_koans, :gen]
|
task :regen => [:clobber_koans, :gen]
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
|||||||
class AboutArrays < EdgeCase::Koan
|
class AboutArrays < EdgeCase::Koan
|
||||||
def test_creating_arrays
|
def test_creating_arrays
|
||||||
empty_array = Array.new
|
empty_array = Array.new
|
||||||
assert_equal Array, empty_array.class
|
assert_equal __, empty_array.class
|
||||||
assert_equal __, empty_array.size
|
assert_equal __, empty_array.size
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -3,16 +3,16 @@ require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
|||||||
class AboutArrays < EdgeCase::Koan
|
class AboutArrays < EdgeCase::Koan
|
||||||
def test_creating_arrays
|
def test_creating_arrays
|
||||||
empty_array = Array.new
|
empty_array = Array.new
|
||||||
assert_equal Array, empty_array.class
|
assert_equal __(Array), empty_array.class
|
||||||
assert_equal __(0), empty_array.size
|
assert_equal __(0), empty_array.size
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_array_literals
|
def test_array_literals
|
||||||
array = Array.new
|
array = Array.new
|
||||||
assert_equal [], array
|
assert_equal [], array # __
|
||||||
|
|
||||||
array[0] = 1
|
array[0] = 1
|
||||||
assert_equal [1], array
|
assert_equal [1], array # __
|
||||||
|
|
||||||
array[1] = 2
|
array[1] = 2
|
||||||
assert_equal [1, __(2)], array
|
assert_equal [1, __(2)], array
|
||||||
@@ -45,9 +45,9 @@ class AboutArrays < EdgeCase::Koan
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_arrays_and_ranges
|
def test_arrays_and_ranges
|
||||||
assert_equal Range, (1..5).class
|
assert_equal __(Range), (1..5).class
|
||||||
assert_not_equal [1,2,3,4,5], (1..5)
|
assert_not_equal [1,2,3,4,5], (1..5) # __
|
||||||
assert_equal [1,2,3,4,5], (1..5).to_a
|
assert_equal __([1,2,3,4,5]), (1..5).to_a
|
||||||
assert_equal __([1,2,3,4]), (1...5).to_a
|
assert_equal __([1,2,3,4]), (1...5).to_a
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ class AboutClasses < EdgeCase::Koan
|
|||||||
fido = Dog6.new("Fido")
|
fido = Dog6.new("Fido")
|
||||||
rover = Dog6.new("Rover")
|
rover = Dog6.new("Rover")
|
||||||
|
|
||||||
assert_not_equal rover.name, fido.name
|
assert_equal __(true), rover.name != fido.name
|
||||||
end
|
end
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
@@ -164,12 +164,12 @@ class AboutClasses < EdgeCase::Koan
|
|||||||
|
|
||||||
def test_to_s_provides_a_string_version_of_the_object
|
def test_to_s_provides_a_string_version_of_the_object
|
||||||
fido = Dog7.new("Fido")
|
fido = Dog7.new("Fido")
|
||||||
assert_equal "Fido", fido.to_s
|
assert_equal __("Fido"), fido.to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_to_s_is_used_in_string_interpolation
|
def test_to_s_is_used_in_string_interpolation
|
||||||
fido = Dog7.new("Fido")
|
fido = Dog7.new("Fido")
|
||||||
assert_equal "My dog is Fido", "My dog is #{fido}"
|
assert_equal __("My dog is Fido"), "My dog is #{fido}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_inspect_provides_a_more_complete_string_version
|
def test_inspect_provides_a_more_complete_string_version
|
||||||
|
|||||||
@@ -22,10 +22,10 @@ class AboutExceptions < EdgeCase::Koan
|
|||||||
|
|
||||||
assert_equal __(:exception_handled), result
|
assert_equal __(:exception_handled), result
|
||||||
|
|
||||||
assert ex.is_a?(StandardError), "Failure message."
|
assert ex.is_a?(___(StandardError)), "Failure message."
|
||||||
assert ex.is_a?(RuntimeError), "Failure message."
|
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"
|
||||||
|
|
||||||
assert_equal __("Oops"), ex.message
|
assert_equal __("Oops"), ex.message
|
||||||
@@ -58,7 +58,7 @@ class AboutExceptions < EdgeCase::Koan
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Sometimes, we must know about the unknown
|
# Sometimes, we must know about the unknown
|
||||||
def test_asserting_an_error_is_raised
|
def test_asserting_an_error_is_raised # __
|
||||||
# A do-end is a block, a topic to explore more later
|
# A do-end is a block, a topic to explore more later
|
||||||
assert_raise(___(MySpecialError)) do
|
assert_raise(___(MySpecialError)) do
|
||||||
raise MySpecialError.new("New instances can be raised directly.")
|
raise MySpecialError.new("New instances can be raised directly.")
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
|||||||
class AboutHashes < EdgeCase::Koan
|
class AboutHashes < EdgeCase::Koan
|
||||||
def test_creating_hashes
|
def test_creating_hashes
|
||||||
empty_hash = Hash.new
|
empty_hash = Hash.new
|
||||||
assert_equal Hash, empty_hash.class
|
assert_equal __(Hash), empty_hash.class
|
||||||
assert_equal({}, empty_hash)
|
assert_equal({}, empty_hash) # __
|
||||||
assert_equal __(0), empty_hash.size
|
assert_equal __(0), empty_hash.size
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -25,7 +25,7 @@ class AboutHashes < EdgeCase::Koan
|
|||||||
hash[:one] = "eins"
|
hash[:one] = "eins"
|
||||||
|
|
||||||
expected = { :one => __("eins"), :two => "dos" }
|
expected = { :one => __("eins"), :two => "dos" }
|
||||||
assert_equal expected, hash
|
assert_equal __(true), expected == hash
|
||||||
|
|
||||||
# Bonus Question: Why was "expected" broken out into a variable
|
# Bonus Question: Why was "expected" broken out into a variable
|
||||||
# rather than used as a literal?
|
# rather than used as a literal?
|
||||||
@@ -35,7 +35,7 @@ class AboutHashes < EdgeCase::Koan
|
|||||||
hash1 = { :one => "uno", :two => "dos" }
|
hash1 = { :one => "uno", :two => "dos" }
|
||||||
hash2 = { :two => "dos", :one => "uno" }
|
hash2 = { :two => "dos", :one => "uno" }
|
||||||
|
|
||||||
assert_equal hash1, hash2
|
assert_equal __(true), hash1 == hash2
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_hash_keys
|
def test_hash_keys
|
||||||
@@ -43,7 +43,7 @@ class AboutHashes < EdgeCase::Koan
|
|||||||
assert_equal __(2), hash.keys.size
|
assert_equal __(2), hash.keys.size
|
||||||
assert_equal __(true), hash.keys.include?(:one)
|
assert_equal __(true), hash.keys.include?(:one)
|
||||||
assert_equal __(true), hash.keys.include?(:two)
|
assert_equal __(true), hash.keys.include?(:two)
|
||||||
assert_equal Array, hash.keys.class
|
assert_equal __(Array), hash.keys.class
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_hash_values
|
def test_hash_values
|
||||||
@@ -51,16 +51,16 @@ class AboutHashes < EdgeCase::Koan
|
|||||||
assert_equal __(2), hash.values.size
|
assert_equal __(2), hash.values.size
|
||||||
assert_equal __(true), hash.values.include?("uno")
|
assert_equal __(true), hash.values.include?("uno")
|
||||||
assert_equal __(true), hash.values.include?("dos")
|
assert_equal __(true), hash.values.include?("dos")
|
||||||
assert_equal Array, hash.values.class
|
assert_equal __(Array), hash.values.class
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_combining_hashes
|
def test_combining_hashes
|
||||||
hash = { "jim" => 53, "amy" => 20, "dan" => 23 }
|
hash = { "jim" => 53, "amy" => 20, "dan" => 23 }
|
||||||
new_hash = hash.merge({ "jim" => 54, "jenny" => 26 })
|
new_hash = hash.merge({ "jim" => 54, "jenny" => 26 })
|
||||||
|
|
||||||
assert_not_equal hash, new_hash
|
assert_equal __(true), hash != new_hash
|
||||||
|
|
||||||
expected = { "jim" => __(54), "amy" => 20, "dan" => 23, "jenny" => __(26) }
|
expected = { "jim" => __(54), "amy" => 20, "dan" => 23, "jenny" => __(26) }
|
||||||
assert_equal expected, new_hash
|
assert_equal __(true), expected == new_hash
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ class AboutIteration < EdgeCase::Koan
|
|||||||
array.each do |item|
|
array.each do |item|
|
||||||
sum += item
|
sum += item
|
||||||
end
|
end
|
||||||
assert_equal 6, sum
|
assert_equal __(6), sum
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_each_can_use_curly_brace_blocks_too
|
def test_each_can_use_curly_brace_blocks_too
|
||||||
|
|||||||
@@ -11,19 +11,19 @@ class AboutMessagePassing < EdgeCase::Koan
|
|||||||
def test_methods_can_be_called_directly
|
def test_methods_can_be_called_directly
|
||||||
mc = MessageCatcher.new
|
mc = MessageCatcher.new
|
||||||
|
|
||||||
assert mc.caught?
|
assert mc.caught? # __
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_methods_can_be_invoked_by_sending_the_message
|
def test_methods_can_be_invoked_by_sending_the_message
|
||||||
mc = MessageCatcher.new
|
mc = MessageCatcher.new
|
||||||
|
|
||||||
assert mc.send(:caught?)
|
assert mc.send(:caught?) # __
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_methods_can_be_invoked_more_dynamically
|
def test_methods_can_be_invoked_more_dynamically
|
||||||
mc = MessageCatcher.new
|
mc = MessageCatcher.new
|
||||||
|
|
||||||
assert mc.send("caught?")
|
assert mc.send("caught?") # __
|
||||||
assert mc.send("caught" + __("?") ) # What do you need to add to the first string?
|
assert mc.send("caught" + __("?") ) # What do you need to add to the first string?
|
||||||
assert mc.send("CAUGHT?".____(:downcase) ) # What would you need to do to the string?
|
assert mc.send("CAUGHT?".____(:downcase) ) # What would you need to do to the string?
|
||||||
end
|
end
|
||||||
@@ -74,7 +74,7 @@ class AboutMessagePassing < EdgeCase::Koan
|
|||||||
exception = assert_raise(___(NoMethodError)) do
|
exception = assert_raise(___(NoMethodError)) do
|
||||||
typical.foobar
|
typical.foobar
|
||||||
end
|
end
|
||||||
assert_match(/foobar/, exception.message)
|
assert_match(/foobar/, exception.message) # __
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_calling_method_missing_causes_the_no_method_error
|
def test_calling_method_missing_causes_the_no_method_error
|
||||||
@@ -83,7 +83,7 @@ class AboutMessagePassing < EdgeCase::Koan
|
|||||||
exception = assert_raise(___(NoMethodError)) do
|
exception = assert_raise(___(NoMethodError)) do
|
||||||
typical.method_missing(:foobar)
|
typical.method_missing(:foobar)
|
||||||
end
|
end
|
||||||
assert_match(/foobar/, exception.message)
|
assert_match(/foobar/, exception.message) # __
|
||||||
|
|
||||||
# THINK ABOUT IT:
|
# THINK ABOUT IT:
|
||||||
#
|
#
|
||||||
@@ -122,7 +122,7 @@ class AboutMessagePassing < EdgeCase::Koan
|
|||||||
def test_catching_messages_makes_respond_to_lie
|
def test_catching_messages_makes_respond_to_lie
|
||||||
catcher = AllMessageCatcher.new
|
catcher = AllMessageCatcher.new
|
||||||
|
|
||||||
assert_nothing_raised(NoMethodError) do
|
assert_nothing_raised(NoMethodError) do # __
|
||||||
catcher.any_method
|
catcher.any_method
|
||||||
end
|
end
|
||||||
assert_equal __(false), catcher.respond_to?(:any_method)
|
assert_equal __(false), catcher.respond_to?(:any_method)
|
||||||
|
|||||||
@@ -19,10 +19,10 @@ class AboutMethods < EdgeCase::Koan
|
|||||||
# considered to be syntactically invalid).
|
# considered to be syntactically invalid).
|
||||||
def test_sometimes_missing_parentheses_are_ambiguous
|
def test_sometimes_missing_parentheses_are_ambiguous
|
||||||
#--
|
#--
|
||||||
eval "assert_equal 5, my_global_method(2, 3)" # REMOVE CHECK
|
eval "assert_equal 5, my_global_method(2, 3)" # REMOVE CHECK # __
|
||||||
if false
|
if false
|
||||||
#++
|
#++
|
||||||
eval "assert_equal 5, my_global_method 2, 3" # ENABLE CHECK
|
eval "assert_equal 5, my_global_method 2, 3" # ENABLE CHECK # __
|
||||||
#--
|
#--
|
||||||
end
|
end
|
||||||
#++
|
#++
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ class AboutModules < EdgeCase::Koan
|
|||||||
|
|
||||||
def test_module_methods_are_also_availble_in_the_object
|
def test_module_methods_are_also_availble_in_the_object
|
||||||
fido = Dog.new
|
fido = Dog.new
|
||||||
assert_nothing_raised(Exception) do
|
assert_nothing_raised(Exception) do # __
|
||||||
fido.set_name("Rover")
|
fido.set_name("Rover")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -3,11 +3,11 @@ require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
|||||||
|
|
||||||
class AboutRegularExpressions < EdgeCase::Koan
|
class AboutRegularExpressions < EdgeCase::Koan
|
||||||
def test_a_pattern_is_a_regular_expression
|
def test_a_pattern_is_a_regular_expression
|
||||||
assert_equal Regexp, /pattern/.class
|
assert_equal __(Regexp), /pattern/.class
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_a_regexp_can_search_a_string_for_matching_content
|
def test_a_regexp_can_search_a_string_for_matching_content
|
||||||
assert_equal "match", "some matching content"[/match/]
|
assert_equal __("match"), "some matching content"[/match/]
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_a_failed_match_returns_nil
|
def test_a_failed_match_returns_nil
|
||||||
|
|||||||
@@ -29,8 +29,8 @@ class AboutScope < EdgeCase::Koan
|
|||||||
assert_equal __(:jims_dog), fido.identify
|
assert_equal __(:jims_dog), fido.identify
|
||||||
assert_equal __(:joes_dog), rover.identify
|
assert_equal __(:joes_dog), rover.identify
|
||||||
|
|
||||||
assert_not_equal fido.class, rover.class
|
assert_equal __(true), fido.class != rover.class
|
||||||
assert_not_equal Jims::Dog, Joes::Dog
|
assert_equal __(true), Jims::Dog != Joes::Dog
|
||||||
end
|
end
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
|
|||||||
@@ -3,6 +3,10 @@
|
|||||||
|
|
||||||
require 'test/unit/assertions'
|
require 'test/unit/assertions'
|
||||||
|
|
||||||
|
# --------------------------------------------------------------------
|
||||||
|
# Support code for the Ruby Koans.
|
||||||
|
# --------------------------------------------------------------------
|
||||||
|
|
||||||
class FillMeInError < StandardError
|
class FillMeInError < StandardError
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -16,6 +20,8 @@ def in_ruby_version(*versions)
|
|||||||
yield if versions.any? { |v| ruby_version?(v) }
|
yield if versions.any? { |v| ruby_version?(v) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Standard, generic replacement value.
|
||||||
|
# If value19 is given, it is used inplace of value for Ruby 1.9.
|
||||||
def __(value="FILL ME IN", value19=:mu)
|
def __(value="FILL ME IN", value19=:mu)
|
||||||
if RUBY_VERSION < "1.9"
|
if RUBY_VERSION < "1.9"
|
||||||
value
|
value
|
||||||
@@ -24,6 +30,7 @@ def __(value="FILL ME IN", value19=:mu)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Numeric replacement value.
|
||||||
def _n_(value=999999, value19=:mu)
|
def _n_(value=999999, value19=:mu)
|
||||||
if RUBY_VERSION < "1.9"
|
if RUBY_VERSION < "1.9"
|
||||||
value
|
value
|
||||||
@@ -32,10 +39,12 @@ def _n_(value=999999, value19=:mu)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Error object replacement value.
|
||||||
def ___(value=FillMeInError)
|
def ___(value=FillMeInError)
|
||||||
value
|
value
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Method name replacement.
|
||||||
class Object
|
class Object
|
||||||
def ____(method=nil)
|
def ____(method=nil)
|
||||||
if method
|
if method
|
||||||
|
|||||||
Reference in New Issue
Block a user