Updated the koans directory.
authorJim Weirich <jim.weirich@gmail.com>
Mon, 16 Aug 2010 20:57:13 +0000 (16:57 -0400)
committerJim Weirich <jim.weirich@gmail.com>
Mon, 16 Aug 2010 20:57:13 +0000 (16:57 -0400)
koans/Rakefile
koans/about_message_passing.rb
koans/edgecase.rb
koans/path_to_enlightenment.rb

index 171fffe..1a2c7f2 100644 (file)
@@ -7,6 +7,6 @@ require 'rake/testtask'
 task :default => :test
 
 task :test do
-  ruby '-I.', 'path_to_enlightenment.rb'
+  ruby 'path_to_enlightenment.rb'
 end
 
index d6c0bc4..45541a0 100644 (file)
@@ -1,28 +1,28 @@
 require File.expand_path(File.dirname(__FILE__) + '/edgecase')
 
 class AboutMessagePassing < EdgeCase::Koan
-  
+
   class MessageCatcher
     def caught?
       true
     end
   end
-    
+
   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?)
   end
-  
+
   def test_methods_can_be_invoked_more_dynamically
     mc = MessageCatcher.new
-    
+
     assert mc.send("caught?")
     assert mc.send("caught" + __ )    # What do you need to add to the first string?
     assert mc.send("CAUGHT?".____ )      # What would you need to do to the string?
@@ -40,11 +40,11 @@ class AboutMessagePassing < EdgeCase::Koan
 
   def test_classes_can_be_asked_if_they_know_how_to_respond
     mc = MessageCatcher.new
-    
+
     assert_equal __, mc.respond_to?(:caught?)
     assert_equal __, mc.respond_to?(:does_not_exist)
   end
-  
+
   # ------------------------------------------------------------------
 
   class MessageCatcher
@@ -52,10 +52,10 @@ class AboutMessagePassing < EdgeCase::Koan
       args
     end
   end
-  
+
   def test_sending_a_message_with_arguments
     mc = MessageCatcher.new
-    
+
     assert_equal __, mc.add_a_payload
     assert_equal __, mc.send(:add_a_payload)
 
@@ -89,6 +89,18 @@ class AboutMessagePassing < EdgeCase::Koan
     #
     # If the method :method_missing causes the NoMethodError, then
     # what would happen if we redefine method_missing?
+    #
+    # NOTE:
+    #
+    # In Ruby 1.8 the method_missing method is public and can be
+    # called as shown above.  However, in Ruby 1.9 the method_missing
+    # method is private.  We explicitly made it public in the testing
+    # framework so this example works in both versions of Ruby.  Just
+    # keep in mind you can't call method_missing like that in Ruby
+    # 1.9. normally.
+    #
+    # Thanks.  We now return you to your regularly schedule Ruby
+    # Koans.
   end
 
   # ------------------------------------------------------------------
index 0f92a6b..71a70b9 100644 (file)
@@ -36,13 +36,27 @@ class Object
       self.send(method)
     end
   end
+
+  in_ruby_version("1.9") do
+    public :method_missing
+  end
 end
 
 module EdgeCase
   class Sensei
     attr_reader :failure, :failed_test
 
-    AssertionError = Test::Unit::AssertionFailedError
+    in_ruby_version("1.8") do
+      AssertionError = Test::Unit::AssertionFailedError
+    end
+
+    in_ruby_version("1.9") do
+      if defined?(MiniTest)
+        AssertionError = MiniTest::Assertion
+      else
+        AssertionError = Test::Unit::AssertionFailedError
+      end
+    end
 
     def initialize
       @pass_count = 0
@@ -165,12 +179,12 @@ module EdgeCase
         test.setup
         begin
           test.send(method)
-        rescue StandardError => ex
+        rescue StandardError, EdgeCase::Sensei::AssertionError => ex
           test.failed(ex)
         ensure
           begin
             test.teardown
-          rescue StandardError => ex
+          rescue StandardError, EdgeCase::Sensei::AssertionError => ex
             test.failed(ex) if test.passed?
           end
         end
index 6a87bcb..ee57759 100644 (file)
@@ -1,5 +1,7 @@
 # The path to Ruby Enlightenment starts with the following:
 
+$LOAD_PATH << File.dirname(__FILE__)
+
 require 'about_asserts'
 require 'about_nil'
 require 'about_arrays'