Skip to content

Commit

Permalink
Put #object_id/#__id__/#id specs in the right place
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jfirebaugh authored and brixen committed Jan 15, 2012
1 parent 8e12483 commit 9af5570
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 38 deletions.
9 changes: 9 additions & 0 deletions 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
11 changes: 0 additions & 11 deletions core/kernel/__id___spec.rb

This file was deleted.

6 changes: 0 additions & 6 deletions core/kernel/id_spec.rb

This file was deleted.

11 changes: 0 additions & 11 deletions core/kernel/object_id_spec.rb

This file was deleted.

9 changes: 9 additions & 0 deletions 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
9 changes: 9 additions & 0 deletions 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
7 changes: 7 additions & 0 deletions 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
22 changes: 12 additions & 10 deletions core/kernel/shared/object_id.rb → 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
Expand Down

0 comments on commit 9af5570

Please sign in to comment.