Skip to content

Commit

Permalink
Evaluated each assert line without a replacement test specified.
Browse files Browse the repository at this point in the history
  • Loading branch information
jimweirich committed Sep 27, 2010
1 parent 012cb20 commit 17fb071
Show file tree
Hide file tree
Showing 13 changed files with 53 additions and 47 deletions.
13 changes: 5 additions & 8 deletions Rakefile
Expand Up @@ -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

Expand Down Expand Up @@ -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]

Expand Down
2 changes: 1 addition & 1 deletion koans/about_arrays.rb
Expand Up @@ -3,7 +3,7 @@
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

Expand Down
12 changes: 6 additions & 6 deletions src/about_arrays.rb
Expand Up @@ -3,16 +3,16 @@
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
Expand Down Expand Up @@ -45,9 +45,9 @@ def test_slicing_arrays
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

Expand Down
6 changes: 3 additions & 3 deletions src/about_classes.rb
Expand Up @@ -130,7 +130,7 @@ def test_different_objects_have_difference_instance_variables
fido = Dog6.new("Fido")
rover = Dog6.new("Rover")

assert_not_equal rover.name, fido.name
assert_equal __(true), rover.name != fido.name
end

# ------------------------------------------------------------------
Expand Down Expand Up @@ -164,12 +164,12 @@ def test_inside_a_method_self_refers_to_the_containing_object

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
Expand Down
10 changes: 5 additions & 5 deletions src/about_exceptions.rb
Expand Up @@ -22,12 +22,12 @@ def test_rescue_clause

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

Expand Down Expand Up @@ -58,7 +58,7 @@ def test_ensure_clause
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.")
Expand Down
18 changes: 9 additions & 9 deletions src/about_hashes.rb
Expand Up @@ -3,8 +3,8 @@
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

Expand All @@ -25,7 +25,7 @@ def test_changing_hashes
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?
Expand All @@ -35,32 +35,32 @@ def test_hash_is_unordered
hash1 = { :one => "uno", :two => "dos" }
hash2 = { :two => "dos", :one => "uno" }

assert_equal hash1, hash2
assert_equal __(true), hash1 == hash2
end

def test_hash_keys
hash = { :one => "uno", :two => "dos" }
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
hash = { :one => "uno", :two => "dos" }
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
2 changes: 1 addition & 1 deletion src/about_iteration.rb
Expand Up @@ -12,7 +12,7 @@ def test_iterating_with_each
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
Expand Down
12 changes: 6 additions & 6 deletions src/about_message_passing.rb
Expand Up @@ -11,19 +11,19 @@ def caught?
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
Expand Down Expand Up @@ -74,7 +74,7 @@ def test_sending_undefined_messages_to_a_typical_object_results_in_errors
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
Expand All @@ -83,7 +83,7 @@ def test_calling_method_missing_causes_the_no_method_error
exception = assert_raise(___(NoMethodError)) do
typical.method_missing(:foobar)
end
assert_match(/foobar/, exception.message)
assert_match(/foobar/, exception.message) # __

# THINK ABOUT IT:
#
Expand Down Expand Up @@ -122,7 +122,7 @@ def test_all_messages_are_caught
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)
Expand Down
4 changes: 2 additions & 2 deletions src/about_methods.rb
Expand Up @@ -19,10 +19,10 @@ def test_calling_global_methods_without_parentheses
# 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
#++
Expand Down
4 changes: 2 additions & 2 deletions src/about_modules.rb
Expand Up @@ -44,8 +44,8 @@ def test_normal_methods_are_available_in_the_object

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

Expand Down
4 changes: 2 additions & 2 deletions src/about_regular_expressions.rb
Expand Up @@ -3,11 +3,11 @@

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
Expand Down
4 changes: 2 additions & 2 deletions src/about_scope.rb
Expand Up @@ -29,8 +29,8 @@ def test_you_can_reference_nested_classes_using_the_scope_operator
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

# ------------------------------------------------------------------
Expand Down
9 changes: 9 additions & 0 deletions src/edgecase.rb
Expand Up @@ -3,6 +3,10 @@

require 'test/unit/assertions'

# --------------------------------------------------------------------
# Support code for the Ruby Koans.
# --------------------------------------------------------------------

class FillMeInError < StandardError
end

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 17fb071

Please sign in to comment.