[macruby-changes] [1447] MacRuby/branches/experimental/spec/frozen/core/kernel

source_changes at macosforge.org source_changes at macosforge.org
Wed Apr 22 15:08:41 PDT 2009


Revision: 1447
          http://trac.macosforge.org/projects/ruby/changeset/1447
Author:   eloy.de.enige at gmail.com
Date:     2009-04-22 15:08:37 -0700 (Wed, 22 Apr 2009)
Log Message:
-----------
Added specs for Kernel#clone and Kernel#dup.

Modified Paths:
--------------
    MacRuby/branches/experimental/spec/frozen/core/kernel/clone_spec.rb
    MacRuby/branches/experimental/spec/frozen/core/kernel/dup_spec.rb
    MacRuby/branches/experimental/spec/frozen/core/kernel/fixtures/classes.rb

Modified: MacRuby/branches/experimental/spec/frozen/core/kernel/clone_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/kernel/clone_spec.rb	2009-04-22 22:08:22 UTC (rev 1446)
+++ MacRuby/branches/experimental/spec/frozen/core/kernel/clone_spec.rb	2009-04-22 22:08:37 UTC (rev 1447)
@@ -2,5 +2,46 @@
 require File.dirname(__FILE__) + '/fixtures/classes'
 
 describe "Kernel#clone" do
-  it "needs to be reviewed for spec completeness"
+  before :each do
+    ScratchPad.clear
+    @obj = KernelSpecs::Duplicate.new 1, :a
+  end
+
+  it "calls #initialize_copy on the new instance" do
+    clone = @obj.clone
+    ScratchPad.recorded.should_not == @obj.object_id
+    ScratchPad.recorded.should == clone.object_id
+  end
+
+  it "copies instance variables" do
+    clone = @obj.clone
+    clone.one.should == 1
+    clone.two.should == :a
+  end
+
+  it "copies singleton methods" do
+    def @obj.special() :the_one end
+    clone = @obj.clone
+    clone.special.should == :the_one
+  end
+
+  it "copies modules included in the singleton class" do
+    class << @obj
+      include KernelSpecs::DuplicateM
+    end
+
+    clone = @obj.clone
+    clone.repr.should == "KernelSpecs::Duplicate"
+  end
+
+  it "copies constants defined in the singleton class" do
+    class << @obj
+      CLONE = :clone
+    end
+
+    clone = @obj.clone
+    class << clone
+      CLONE.should == :clone
+    end
+  end
 end

Modified: MacRuby/branches/experimental/spec/frozen/core/kernel/dup_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/kernel/dup_spec.rb	2009-04-22 22:08:22 UTC (rev 1446)
+++ MacRuby/branches/experimental/spec/frozen/core/kernel/dup_spec.rb	2009-04-22 22:08:37 UTC (rev 1447)
@@ -2,5 +2,46 @@
 require File.dirname(__FILE__) + '/fixtures/classes'
 
 describe "Kernel#dup" do
-  it "needs to be reviewed for spec completeness"
+  before :each do
+    ScratchPad.clear
+    @obj = KernelSpecs::Duplicate.new 1, :a
+  end
+
+  it "calls #initialize_copy on the new instance" do
+    dup = @obj.dup
+    ScratchPad.recorded.should_not == @obj.object_id
+    ScratchPad.recorded.should == dup.object_id
+  end
+
+  it "copies instance variables" do
+    dup = @obj.dup
+    dup.one.should == 1
+    dup.two.should == :a
+  end
+
+  it "does not copy singleton methods" do
+    def @obj.special() :the_one end
+    dup = @obj.dup
+    lambda { dup.special }.should raise_error(NameError)
+  end
+
+  it "does not copy modules included in the singleton class" do
+    class << @obj
+      include KernelSpecs::DuplicateM
+    end
+
+    dup = @obj.dup
+    lambda { dup.repr }.should raise_error(NameError)
+  end
+
+  it "does not copy constants defined in the singleton class" do
+    class << @obj
+      CLONE = :clone
+    end
+
+    dup = @obj.dup
+    class << dup
+      lambda { CLONE }.should raise_error(NameError)
+    end
+  end
 end

Modified: MacRuby/branches/experimental/spec/frozen/core/kernel/fixtures/classes.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/kernel/fixtures/classes.rb	2009-04-22 22:08:22 UTC (rev 1446)
+++ MacRuby/branches/experimental/spec/frozen/core/kernel/fixtures/classes.rb	2009-04-22 22:08:37 UTC (rev 1447)
@@ -7,35 +7,35 @@
     class << self
       def san; end
     end
-  
+
     private
-  
+
     def self.shi; end
     def juu_shi; end
-  
+
     class << self
       def roku; end
 
       private
-    
+
       def shichi; end
     end
-  
+
     protected
-  
+
     def self.hachi; end
     def ku; end
-  
+
     class << self
       def juu; end
-    
+
       protected
-    
+
       def juu_ichi; end
     end
-  
+
     public
-  
+
     def self.juu_ni; end
     def juu_san; end
   end
@@ -59,23 +59,23 @@
     def initialize(n)
       @secret = n
     end
-  
+
     def square(n)
       n * n
     end
-    
+
     def get_binding
       a = true
       @bind = binding
 
       # Add/Change stuff
-      b = true 
+      b = true
       @secret += 1
 
       @bind
     end
   end
-  
+
   module MethodMissing
     def self.method_missing(*args) :method_missing end
     def self.existing() :existing end
@@ -83,7 +83,7 @@
     def self.private_method() :private_method end
     private_class_method :private_method
   end
-  
+
   class MethodMissingC
     def self.method_missing(*args) :method_missing end
     def method_missing(*args) :instance_method_missing end
@@ -104,14 +104,14 @@
     def protected_method() :protected_instance_method end
     protected :protected_method
   end
-  
+
   module NoMethodMissing
     def self.existing() :existing end
 
     def self.private_method() :private_method end
     private_class_method :private_method
   end
-    
+
   class NoMethodMissingC
     def self.existing() :existing end
     def existing() :instance_existing end
@@ -129,17 +129,17 @@
     def protected_method() :protected_instance_method end
     protected :protected_method
   end
-  
+
   module BlockGiven
     def self.accept_block
       block_given?
     end
-    
+
     def self.accept_block_as_argument(&block)
       block_given?
     end
   end
-  
+
   def self.before_and_after
     i = "before"
     cont = callcc { |c| c }
@@ -149,19 +149,19 @@
     end
     i
   end
-  
+
   class IVars
     def initialize
       @secret = 99
     end
   end
-  
+
   module InstEval
     def self.included(base)
       base.instance_eval { @@count = 2 }
     end
   end
-  
+
   class IncludesInstEval
     include InstEval
   end
@@ -178,6 +178,25 @@
   def self.helper_script
     File.dirname(__FILE__) + '/check_expansion.rb'
   end
+
+  module DuplicateM
+    def repr
+      self.class.name.to_s
+    end
+  end
+
+  class Duplicate
+    attr_accessor :one, :two
+
+    def initialize(one, two)
+      @one = one
+      @two = two
+    end
+
+    def initialize_copy(other)
+      ScratchPad.record object_id
+    end
+  end
 end
 
 # for Kernel#sleep to have Channel in it's specs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090422/1079c3de/attachment-0001.html>


More information about the macruby-changes mailing list