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)
|
||||
|
||||
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
|
||||
|
||||
@@ -84,14 +89,6 @@ task :upload => [TAR_FILE, ZIP_FILE] do
|
||||
sh "scp #{ZIP_FILE} linode:sites/onestepback.org/download"
|
||||
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."
|
||||
task :regen => [:clobber_koans, :gen]
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
||||
class AboutArrays < EdgeCase::Koan
|
||||
def test_creating_arrays
|
||||
empty_array = Array.new
|
||||
assert_equal Array, empty_array.class
|
||||
assert_equal __, empty_array.class
|
||||
assert_equal __, empty_array.size
|
||||
end
|
||||
|
||||
|
||||
@@ -3,16 +3,16 @@ require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
||||
class AboutArrays < EdgeCase::Koan
|
||||
def test_creating_arrays
|
||||
empty_array = Array.new
|
||||
assert_equal Array, empty_array.class
|
||||
assert_equal __(Array), empty_array.class
|
||||
assert_equal __(0), empty_array.size
|
||||
end
|
||||
|
||||
def test_array_literals
|
||||
array = Array.new
|
||||
assert_equal [], array
|
||||
assert_equal [], array # __
|
||||
|
||||
array[0] = 1
|
||||
assert_equal [1], array
|
||||
assert_equal [1], array # __
|
||||
|
||||
array[1] = 2
|
||||
assert_equal [1, __(2)], array
|
||||
@@ -45,9 +45,9 @@ class AboutArrays < EdgeCase::Koan
|
||||
end
|
||||
|
||||
def test_arrays_and_ranges
|
||||
assert_equal Range, (1..5).class
|
||||
assert_not_equal [1,2,3,4,5], (1..5)
|
||||
assert_equal [1,2,3,4,5], (1..5).to_a
|
||||
assert_equal __(Range), (1..5).class
|
||||
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]), (1...5).to_a
|
||||
end
|
||||
|
||||
|
||||
@@ -130,7 +130,7 @@ class AboutClasses < EdgeCase::Koan
|
||||
fido = Dog6.new("Fido")
|
||||
rover = Dog6.new("Rover")
|
||||
|
||||
assert_not_equal rover.name, fido.name
|
||||
assert_equal __(true), rover.name != fido.name
|
||||
end
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
@@ -164,12 +164,12 @@ class AboutClasses < EdgeCase::Koan
|
||||
|
||||
def test_to_s_provides_a_string_version_of_the_object
|
||||
fido = Dog7.new("Fido")
|
||||
assert_equal "Fido", fido.to_s
|
||||
assert_equal __("Fido"), fido.to_s
|
||||
end
|
||||
|
||||
def test_to_s_is_used_in_string_interpolation
|
||||
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
|
||||
|
||||
def test_inspect_provides_a_more_complete_string_version
|
||||
|
||||
@@ -22,12 +22,12 @@ class AboutExceptions < EdgeCase::Koan
|
||||
|
||||
assert_equal __(:exception_handled), result
|
||||
|
||||
assert ex.is_a?(StandardError), "Failure message."
|
||||
assert ex.is_a?(RuntimeError), "Failure message."
|
||||
assert ex.is_a?(___(StandardError)), "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"
|
||||
|
||||
|
||||
assert_equal __("Oops"), ex.message
|
||||
end
|
||||
|
||||
@@ -58,7 +58,7 @@ class AboutExceptions < EdgeCase::Koan
|
||||
end
|
||||
|
||||
# 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
|
||||
assert_raise(___(MySpecialError)) do
|
||||
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
|
||||
def test_creating_hashes
|
||||
empty_hash = Hash.new
|
||||
assert_equal Hash, empty_hash.class
|
||||
assert_equal({}, empty_hash)
|
||||
assert_equal __(Hash), empty_hash.class
|
||||
assert_equal({}, empty_hash) # __
|
||||
assert_equal __(0), empty_hash.size
|
||||
end
|
||||
|
||||
@@ -25,7 +25,7 @@ class AboutHashes < EdgeCase::Koan
|
||||
hash[:one] = "eins"
|
||||
|
||||
expected = { :one => __("eins"), :two => "dos" }
|
||||
assert_equal expected, hash
|
||||
assert_equal __(true), expected == hash
|
||||
|
||||
# Bonus Question: Why was "expected" broken out into a variable
|
||||
# rather than used as a literal?
|
||||
@@ -35,7 +35,7 @@ class AboutHashes < EdgeCase::Koan
|
||||
hash1 = { :one => "uno", :two => "dos" }
|
||||
hash2 = { :two => "dos", :one => "uno" }
|
||||
|
||||
assert_equal hash1, hash2
|
||||
assert_equal __(true), hash1 == hash2
|
||||
end
|
||||
|
||||
def test_hash_keys
|
||||
@@ -43,7 +43,7 @@ class AboutHashes < EdgeCase::Koan
|
||||
assert_equal __(2), hash.keys.size
|
||||
assert_equal __(true), hash.keys.include?(:one)
|
||||
assert_equal __(true), hash.keys.include?(:two)
|
||||
assert_equal Array, hash.keys.class
|
||||
assert_equal __(Array), hash.keys.class
|
||||
end
|
||||
|
||||
def test_hash_values
|
||||
@@ -51,16 +51,16 @@ class AboutHashes < EdgeCase::Koan
|
||||
assert_equal __(2), hash.values.size
|
||||
assert_equal __(true), hash.values.include?("uno")
|
||||
assert_equal __(true), hash.values.include?("dos")
|
||||
assert_equal Array, hash.values.class
|
||||
assert_equal __(Array), hash.values.class
|
||||
end
|
||||
|
||||
def test_combining_hashes
|
||||
hash = { "jim" => 53, "amy" => 20, "dan" => 23 }
|
||||
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) }
|
||||
assert_equal expected, new_hash
|
||||
assert_equal __(true), expected == new_hash
|
||||
end
|
||||
end
|
||||
|
||||
@@ -12,7 +12,7 @@ class AboutIteration < EdgeCase::Koan
|
||||
array.each do |item|
|
||||
sum += item
|
||||
end
|
||||
assert_equal 6, sum
|
||||
assert_equal __(6), sum
|
||||
end
|
||||
|
||||
def test_each_can_use_curly_brace_blocks_too
|
||||
|
||||
@@ -11,19 +11,19 @@ class AboutMessagePassing < EdgeCase::Koan
|
||||
def test_methods_can_be_called_directly
|
||||
mc = MessageCatcher.new
|
||||
|
||||
assert mc.caught?
|
||||
assert mc.caught? # __
|
||||
end
|
||||
|
||||
def test_methods_can_be_invoked_by_sending_the_message
|
||||
mc = MessageCatcher.new
|
||||
|
||||
assert mc.send(:caught?)
|
||||
assert mc.send(:caught?) # __
|
||||
end
|
||||
|
||||
def test_methods_can_be_invoked_more_dynamically
|
||||
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?".____(:downcase) ) # What would you need to do to the string?
|
||||
end
|
||||
@@ -74,7 +74,7 @@ class AboutMessagePassing < EdgeCase::Koan
|
||||
exception = assert_raise(___(NoMethodError)) do
|
||||
typical.foobar
|
||||
end
|
||||
assert_match(/foobar/, exception.message)
|
||||
assert_match(/foobar/, exception.message) # __
|
||||
end
|
||||
|
||||
def test_calling_method_missing_causes_the_no_method_error
|
||||
@@ -83,7 +83,7 @@ class AboutMessagePassing < EdgeCase::Koan
|
||||
exception = assert_raise(___(NoMethodError)) do
|
||||
typical.method_missing(:foobar)
|
||||
end
|
||||
assert_match(/foobar/, exception.message)
|
||||
assert_match(/foobar/, exception.message) # __
|
||||
|
||||
# THINK ABOUT IT:
|
||||
#
|
||||
@@ -122,7 +122,7 @@ class AboutMessagePassing < EdgeCase::Koan
|
||||
def test_catching_messages_makes_respond_to_lie
|
||||
catcher = AllMessageCatcher.new
|
||||
|
||||
assert_nothing_raised(NoMethodError) do
|
||||
assert_nothing_raised(NoMethodError) do # __
|
||||
catcher.any_method
|
||||
end
|
||||
assert_equal __(false), catcher.respond_to?(:any_method)
|
||||
|
||||
@@ -19,10 +19,10 @@ class AboutMethods < EdgeCase::Koan
|
||||
# considered to be syntactically invalid).
|
||||
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
|
||||
#++
|
||||
eval "assert_equal 5, my_global_method 2, 3" # ENABLE CHECK
|
||||
eval "assert_equal 5, my_global_method 2, 3" # ENABLE CHECK # __
|
||||
#--
|
||||
end
|
||||
#++
|
||||
|
||||
@@ -44,8 +44,8 @@ class AboutModules < EdgeCase::Koan
|
||||
|
||||
def test_module_methods_are_also_availble_in_the_object
|
||||
fido = Dog.new
|
||||
assert_nothing_raised(Exception) do
|
||||
fido.set_name("Rover")
|
||||
assert_nothing_raised(Exception) do # __
|
||||
fido.set_name("Rover")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -3,11 +3,11 @@ require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
||||
|
||||
class AboutRegularExpressions < EdgeCase::Koan
|
||||
def test_a_pattern_is_a_regular_expression
|
||||
assert_equal Regexp, /pattern/.class
|
||||
assert_equal __(Regexp), /pattern/.class
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
def test_a_failed_match_returns_nil
|
||||
|
||||
@@ -29,8 +29,8 @@ class AboutScope < EdgeCase::Koan
|
||||
assert_equal __(:jims_dog), fido.identify
|
||||
assert_equal __(:joes_dog), rover.identify
|
||||
|
||||
assert_not_equal fido.class, rover.class
|
||||
assert_not_equal Jims::Dog, Joes::Dog
|
||||
assert_equal __(true), fido.class != rover.class
|
||||
assert_equal __(true), Jims::Dog != Joes::Dog
|
||||
end
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
|
||||
@@ -3,6 +3,10 @@
|
||||
|
||||
require 'test/unit/assertions'
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# Support code for the Ruby Koans.
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
class FillMeInError < StandardError
|
||||
end
|
||||
|
||||
@@ -16,6 +20,8 @@ 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 inplace of value for Ruby 1.9.
|
||||
def __(value="FILL ME IN", value19=:mu)
|
||||
if RUBY_VERSION < "1.9"
|
||||
value
|
||||
@@ -24,6 +30,7 @@ def __(value="FILL ME IN", value19=:mu)
|
||||
end
|
||||
end
|
||||
|
||||
# Numeric replacement value.
|
||||
def _n_(value=999999, value19=:mu)
|
||||
if RUBY_VERSION < "1.9"
|
||||
value
|
||||
@@ -32,10 +39,12 @@ def _n_(value=999999, value19=:mu)
|
||||
end
|
||||
end
|
||||
|
||||
# Error object replacement value.
|
||||
def ___(value=FillMeInError)
|
||||
value
|
||||
end
|
||||
|
||||
# Method name replacement.
|
||||
class Object
|
||||
def ____(method=nil)
|
||||
if method
|
||||
|
||||
Reference in New Issue
Block a user