Answers now Ruby 1.9 compliant
authorJim Weirich <jim.weirich@gmail.com>
Mon, 16 Aug 2010 19:05:20 +0000 (15:05 -0400)
committerJim Weirich <jim.weirich@gmail.com>
Mon, 16 Aug 2010 19:05:20 +0000 (15:05 -0400)
src/about_classes.rb
src/about_scope.rb
src/about_strings.rb
src/edgecase.rb

index 350c112..30a2ca9 100644 (file)
@@ -22,7 +22,7 @@ class AboutClasses < EdgeCase::Koan
     assert_equal __([]), fido.instance_variables
 
     fido.set_name("Fido")
-    assert_equal __(["@name"]), fido.instance_variables
+    assert_equal __(["@name"], [:@name]), fido.instance_variables
   end
 
   def test_instance_variables_cannot_be_accessed_outside_the_class
@@ -43,7 +43,7 @@ class AboutClasses < EdgeCase::Koan
     fido = Dog2.new
     fido.set_name("Fido")
 
-    assert_equal __("Fido"), fido.instance_variable_get("@name")    
+    assert_equal __("Fido"), fido.instance_variable_get("@name")
   end
 
   def test_you_can_rip_the_value_out_using_instance_eval
@@ -89,7 +89,7 @@ class AboutClasses < EdgeCase::Koan
 
     assert_equal __("Fido"), fido.name
   end
-  
+
   # ------------------------------------------------------------------
 
   class Dog5
@@ -125,7 +125,7 @@ class AboutClasses < EdgeCase::Koan
     # THINK ABOUT IT:
     # Why is this so?
   end
-  
+
   def test_different_objects_have_difference_instance_variables
     fido = Dog6.new("Fido")
     rover = Dog6.new("Rover")
@@ -180,11 +180,11 @@ class AboutClasses < EdgeCase::Koan
   def test_all_objects_support_to_s_and_inspect
     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 __("STRING"), "STRING".to_s
     assert_equal __('"STRING"'), "STRING".inspect
   end
+
 end
index 097ffd3..796ff02 100644 (file)
@@ -28,7 +28,7 @@ class AboutScope < EdgeCase::Koan
     rover = Joes::Dog.new
     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
   end
@@ -41,7 +41,7 @@ class AboutScope < EdgeCase::Koan
   def test_bare_bones_class_names_assume_the_current_scope
     assert_equal __(true), AboutScope::String == String
   end
-  
+
   def test_nested_string_is_not_the_same_as_the_system_string
     assert_equal __(false), String == "HI".class
   end
@@ -73,7 +73,7 @@ class AboutScope < EdgeCase::Koan
   end
 
   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)
   end
 end
index 97a3877..3dd0725 100644 (file)
@@ -141,16 +141,25 @@ EOS
 
   def test_you_can_get_a_single_character_from_a_string
     string = "Bacon, lettuce and tomato"
-    assert_equal __(97), string[1]
+    assert_equal __(97, 'a'), string[1]
 
     # Surprised?
   end
 
-  def test_single_characters_are_represented_by_integers
-    assert_equal __(97), ?a
-    assert_equal __(true), ?a == 97
+  in_ruby_version("1.8") do
+    def test_in_ruby_1_8_single_characters_are_represented_by_integers
+      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
 
   def test_strings_can_be_split
index acb032b..0f92a6b 100644 (file)
@@ -6,12 +6,24 @@ require 'test/unit/assertions'
 class FillMeInError < StandardError
 end
 
-def __(value="FILL ME IN")
-  value
+def in_ruby_version(version)
+  yield if RUBY_VERSION =~ /^#{version}/
 end
 
-def _n_(value=999999)
-  value
+def __(value="FILL ME IN", value19=:mu)
+  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
 
 def ___(value=FillMeInError)
@@ -104,7 +116,7 @@ module EdgeCase
         end
       end
     end
-  end      
+  end
 
   class Koan
     include Test::Unit::Assertions
@@ -181,7 +193,7 @@ module EdgeCase
               load(arg)
             else
               fail "Unknown command line argument '#{arg}'"
-            end              
+            end
           end
         end
       end