Answers now Ruby 1.9 compliant

This commit is contained in:
Jim Weirich
2010-08-16 15:05:20 -04:00
parent e8456fa321
commit 7046294343
4 changed files with 41 additions and 20 deletions

View File

@@ -22,7 +22,7 @@ class AboutClasses < EdgeCase::Koan
assert_equal __([]), fido.instance_variables assert_equal __([]), fido.instance_variables
fido.set_name("Fido") fido.set_name("Fido")
assert_equal __(["@name"]), fido.instance_variables assert_equal __(["@name"], [:@name]), fido.instance_variables
end end
def test_instance_variables_cannot_be_accessed_outside_the_class def test_instance_variables_cannot_be_accessed_outside_the_class
@@ -43,7 +43,7 @@ class AboutClasses < EdgeCase::Koan
fido = Dog2.new fido = Dog2.new
fido.set_name("Fido") fido.set_name("Fido")
assert_equal __("Fido"), fido.instance_variable_get("@name") assert_equal __("Fido"), fido.instance_variable_get("@name")
end end
def test_you_can_rip_the_value_out_using_instance_eval def test_you_can_rip_the_value_out_using_instance_eval
@@ -89,7 +89,7 @@ class AboutClasses < EdgeCase::Koan
assert_equal __("Fido"), fido.name assert_equal __("Fido"), fido.name
end end
# ------------------------------------------------------------------ # ------------------------------------------------------------------
class Dog5 class Dog5
@@ -125,7 +125,7 @@ class AboutClasses < EdgeCase::Koan
# THINK ABOUT IT: # THINK ABOUT IT:
# Why is this so? # Why is this so?
end end
def test_different_objects_have_difference_instance_variables def test_different_objects_have_difference_instance_variables
fido = Dog6.new("Fido") fido = Dog6.new("Fido")
rover = Dog6.new("Rover") rover = Dog6.new("Rover")
@@ -180,11 +180,11 @@ class AboutClasses < EdgeCase::Koan
def test_all_objects_support_to_s_and_inspect def test_all_objects_support_to_s_and_inspect
array = [1,2,3] array = [1,2,3]
assert_equal __("123"), array.to_s assert_equal __("123", "[1, 2, 3]"), array.to_s
assert_equal __("[1, 2, 3]"), array.inspect assert_equal __("[1, 2, 3]"), array.inspect
assert_equal __("STRING"), "STRING".to_s assert_equal __("STRING"), "STRING".to_s
assert_equal __('"STRING"'), "STRING".inspect assert_equal __('"STRING"'), "STRING".inspect
end end
end end

View File

@@ -28,7 +28,7 @@ class AboutScope < EdgeCase::Koan
rover = Joes::Dog.new rover = Joes::Dog.new
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_not_equal fido.class, rover.class
assert_not_equal Jims::Dog, Joes::Dog assert_not_equal Jims::Dog, Joes::Dog
end end
@@ -41,7 +41,7 @@ class AboutScope < EdgeCase::Koan
def test_bare_bones_class_names_assume_the_current_scope def test_bare_bones_class_names_assume_the_current_scope
assert_equal __(true), AboutScope::String == String assert_equal __(true), AboutScope::String == String
end end
def test_nested_string_is_not_the_same_as_the_system_string def test_nested_string_is_not_the_same_as_the_system_string
assert_equal __(false), String == "HI".class assert_equal __(false), String == "HI".class
end end
@@ -73,7 +73,7 @@ class AboutScope < EdgeCase::Koan
end end
def test_you_can_get_a_list_of_constants_for_any_class_or_module def test_you_can_get_a_list_of_constants_for_any_class_or_module
assert_equal __(["Dog"]), Jims.constants assert_equal __(["Dog"], [:Dog]), Jims.constants
assert Object.constants.size > _n_(10) assert Object.constants.size > _n_(10)
end end
end end

View File

@@ -141,16 +141,25 @@ EOS
def test_you_can_get_a_single_character_from_a_string def test_you_can_get_a_single_character_from_a_string
string = "Bacon, lettuce and tomato" string = "Bacon, lettuce and tomato"
assert_equal __(97), string[1] assert_equal __(97, 'a'), string[1]
# Surprised? # Surprised?
end end
def test_single_characters_are_represented_by_integers in_ruby_version("1.8") do
assert_equal __(97), ?a def test_in_ruby_1_8_single_characters_are_represented_by_integers
assert_equal __(true), ?a == 97 assert_equal __(97, 'a'), ?a
assert_equal __(true, false), ?a == 97
assert_equal __(true), ?b == (?a + 1) assert_equal __(true), ?b == (?a + 1)
end
end
in_ruby_version("1.9") do
def test_in_ruby_1_8_single_characters_are_represented_by_strings
assert_equal __('a'), ?a
assert_equal __(false), ?a == 97
end
end end
def test_strings_can_be_split def test_strings_can_be_split

View File

@@ -6,12 +6,24 @@ require 'test/unit/assertions'
class FillMeInError < StandardError class FillMeInError < StandardError
end end
def __(value="FILL ME IN") def in_ruby_version(version)
value yield if RUBY_VERSION =~ /^#{version}/
end end
def _n_(value=999999) def __(value="FILL ME IN", value19=:mu)
value if RUBY_VERSION < "1.9"
value
else
(value19 == :mu) ? value : value19
end
end
def _n_(value=999999, value19=:mu)
if RUBY_VERSION < "1.9"
value
else
(value19 == :mu) ? value : value19
end
end end
def ___(value=FillMeInError) def ___(value=FillMeInError)
@@ -104,7 +116,7 @@ module EdgeCase
end end
end end
end end
end end
class Koan class Koan
include Test::Unit::Assertions include Test::Unit::Assertions
@@ -181,7 +193,7 @@ module EdgeCase
load(arg) load(arg)
else else
fail "Unknown command line argument '#{arg}'" fail "Unknown command line argument '#{arg}'"
end end
end end
end end
end end