From 9af557043e732a03d6f1a7907343fb63d0b63545 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Fri, 13 Jan 2012 21:36:03 -0800 Subject: [PATCH] Put #object_id/#__id__/#id specs in the right place 1.8 defines Object#object_id, Object#__id__, and Object#id. 1.9 defines BasicObject#__id__ and Object#object_id. These methods aren't defined on Kernel, they shouldn't be in the kernel subdirectory. --- core/basicobject/__id__spec.rb | 9 ++++++++ core/kernel/__id___spec.rb | 11 ---------- core/kernel/id_spec.rb | 6 ----- core/kernel/object_id_spec.rb | 11 ---------- core/object/__id__spec.rb | 9 ++++++++ core/object/id_spec.rb | 9 ++++++++ core/object/object_id_spec.rb | 7 ++++++ .../shared => shared/object}/object_id.rb | 22 ++++++++++--------- 8 files changed, 46 insertions(+), 38 deletions(-) create mode 100644 core/basicobject/__id__spec.rb delete mode 100644 core/kernel/__id___spec.rb delete mode 100644 core/kernel/id_spec.rb delete mode 100644 core/kernel/object_id_spec.rb create mode 100644 core/object/__id__spec.rb create mode 100644 core/object/id_spec.rb create mode 100644 core/object/object_id_spec.rb rename {core/kernel/shared => shared/object}/object_id.rb (79%) diff --git a/core/basicobject/__id__spec.rb b/core/basicobject/__id__spec.rb new file mode 100644 index 0000000000..586e35bcc1 --- /dev/null +++ b/core/basicobject/__id__spec.rb @@ -0,0 +1,9 @@ +require File.expand_path('../../../spec_helper', __FILE__) +require File.expand_path('../../../shared/object/object_id', __FILE__) + +ruby_version_is "1.9" do + describe "BasicObject#__id__" do + it_behaves_like :basic_object_id, :__id__, BasicObject + it_behaves_like :object_id, :__id__, Object + end +end diff --git a/core/kernel/__id___spec.rb b/core/kernel/__id___spec.rb deleted file mode 100644 index b23159fb71..0000000000 --- a/core/kernel/__id___spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -require File.expand_path('../../../spec_helper', __FILE__) -require File.expand_path('../fixtures/classes', __FILE__) -require File.expand_path('../shared/object_id', __FILE__) - -describe "Kernel#__id__" do - it_behaves_like(:kernel_object_id, :__id__) -end - -describe "Kernel#__id__" do - it "needs to be reviewed for spec completeness" -end diff --git a/core/kernel/id_spec.rb b/core/kernel/id_spec.rb deleted file mode 100644 index 877e1bcbcf..0000000000 --- a/core/kernel/id_spec.rb +++ /dev/null @@ -1,6 +0,0 @@ -require File.expand_path('../../../spec_helper', __FILE__) -require File.expand_path('../fixtures/classes', __FILE__) - -describe "Kernel#id" do - it "needs to be reviewed for spec completeness" -end diff --git a/core/kernel/object_id_spec.rb b/core/kernel/object_id_spec.rb deleted file mode 100644 index ba30def3e4..0000000000 --- a/core/kernel/object_id_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -require File.expand_path('../../../spec_helper', __FILE__) -require File.expand_path('../fixtures/classes', __FILE__) -require File.expand_path('../shared/object_id', __FILE__) - -describe "Object.object_id" do - it_behaves_like(:kernel_object_id, :object_id) -end - -describe "Kernel#object_id" do - it "needs to be reviewed for spec completeness" -end diff --git a/core/object/__id__spec.rb b/core/object/__id__spec.rb new file mode 100644 index 0000000000..7ad17a51d9 --- /dev/null +++ b/core/object/__id__spec.rb @@ -0,0 +1,9 @@ +require File.expand_path('../../../spec_helper', __FILE__) +require File.expand_path('../../../shared/object/object_id', __FILE__) + +ruby_version_is "".."1.9" do + describe "Object#__id__" do + it_behaves_like :basic_object_id, :__id__, Object + it_behaves_like :object_id, :__id__, Object + end +end diff --git a/core/object/id_spec.rb b/core/object/id_spec.rb new file mode 100644 index 0000000000..943da29b8b --- /dev/null +++ b/core/object/id_spec.rb @@ -0,0 +1,9 @@ +require File.expand_path('../../../spec_helper', __FILE__) +require File.expand_path('../../../shared/object/object_id', __FILE__) + +ruby_version_is "".."1.9" do + describe "Object#id" do + it_behaves_like :basic_object_id, :id, Object + it_behaves_like :object_id, :id, Object + end +end diff --git a/core/object/object_id_spec.rb b/core/object/object_id_spec.rb new file mode 100644 index 0000000000..6a68fcdf20 --- /dev/null +++ b/core/object/object_id_spec.rb @@ -0,0 +1,7 @@ +require File.expand_path('../../../spec_helper', __FILE__) +require File.expand_path('../../../shared/object/object_id', __FILE__) + +describe "Object#object_id" do + it_behaves_like :basic_object_id, :object_id, Object + it_behaves_like :object_id, :object_id, Object +end diff --git a/core/kernel/shared/object_id.rb b/shared/object/object_id.rb similarity index 79% rename from core/kernel/shared/object_id.rb rename to shared/object/object_id.rb index 4f86e1377c..61f7e0517d 100644 --- a/core/kernel/shared/object_id.rb +++ b/shared/object/object_id.rb @@ -1,22 +1,24 @@ -describe :kernel_object_id, :shared => true do - # #object_id and #__id__ are aliases, so we only need one function - # that tests both methods +# These examples hold for both BasicObject#__id__ and Object#object_id. +describe :basic_object_id, :shared => true do it "returns an integer" do - mock('fixnum').send(@method).should be_kind_of(Integer) - nil.send(@method).should be_kind_of(Integer) + o1 = @object.new + o1.__send__(@method).should be_kind_of(Integer) end it "returns the same value on all calls to id for a given object" do - o1 = mock('x') - o1.send(@method).should == o1.send(@method) + o1 = @object.new + o1.__send__(@method).should == o1.send(@method) end it "returns different values for different objects" do - o1 = mock('o1') - o2 = mock('o2') - o1.send(@method).should_not == o2.send(@method) + o1 = @object.new + o2 = @object.new + o1.__send__(@method).should_not == o2.__send__(@method) end +end +# These examples hold for Object#object_id, or for specific subclasses. +describe :object_id, :shared => true do it "returns the same value for two Fixnums with the same value" do o1 = 1 o2 = 1