summaryrefslogtreecommitdiff
path: root/spec/ruby/core/method/equal_value_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/core/method/equal_value_spec.rb')
-rw-r--r--spec/ruby/core/method/equal_value_spec.rb92
1 files changed, 90 insertions, 2 deletions
diff --git a/spec/ruby/core/method/equal_value_spec.rb b/spec/ruby/core/method/equal_value_spec.rb
index 0431d0c5f6..ca9ef9f108 100644
--- a/spec/ruby/core/method/equal_value_spec.rb
+++ b/spec/ruby/core/method/equal_value_spec.rb
@@ -1,6 +1,94 @@
require_relative '../../spec_helper'
-require_relative 'shared/eql'
+require_relative 'fixtures/classes'
describe "Method#==" do
- it_behaves_like :method_equal, :==
+ before :each do
+ @m = MethodSpecs::Methods.new
+ @m_foo = @m.method(:foo)
+ @m2 = MethodSpecs::Methods.new
+ @a = MethodSpecs::A.new
+ end
+
+ it "returns true if methods are the same" do
+ m2 = @m.method(:foo)
+
+ (@m_foo == @m_foo).should == true
+ (@m_foo == m2).should == true
+ end
+
+ it "returns true on aliased methods" do
+ m_bar = @m.method(:bar)
+
+ (m_bar == @m_foo).should == true
+ end
+
+ it "returns true if the two core methods are aliases" do
+ s = "hello"
+ a = s.method(:size)
+ b = s.method(:length)
+ (a == b).should == true
+ end
+
+ it "returns false on a method which is neither aliased nor the same method" do
+ m2 = @m.method(:zero)
+
+ (@m_foo == m2).should == false
+ end
+
+ it "returns false for a method which is not bound to the same object" do
+ m2_foo = @m2.method(:foo)
+ a_baz = @a.method(:baz)
+
+ (@m_foo == m2_foo).should == false
+ (@m_foo == a_baz).should == false
+ end
+
+ it "returns false if the two methods are bound to the same object but were defined independently" do
+ m2 = @m.method(:same_as_foo)
+ (@m_foo == m2).should == false
+ end
+
+ it "returns true if a method was defined using the other one" do
+ MethodSpecs::Methods.send :define_method, :defined_foo, MethodSpecs::Methods.instance_method(:foo)
+ m2 = @m.method(:defined_foo)
+ (@m_foo == m2).should == true
+ end
+
+ it "returns false if comparing a method defined via define_method and def" do
+ defn = @m.method(:zero)
+ defined = @m.method(:zero_defined_method)
+
+ (defn == defined).should == false
+ (defined == defn).should == false
+ end
+
+ describe 'missing methods' do
+ it "returns true for the same method missing" do
+ miss1 = @m.method(:handled_via_method_missing)
+ miss1bis = @m.method(:handled_via_method_missing)
+ miss2 = @m.method(:also_handled)
+
+ (miss1 == miss1bis).should == true
+ (miss1 == miss2).should == false
+ end
+
+ it 'calls respond_to_missing? with true to include private methods' do
+ @m.should_receive(:respond_to_missing?).with(:some_missing_method, true).and_return(true)
+ @m.method(:some_missing_method)
+ end
+ end
+
+ it "returns false if the two methods are bound to different objects, have the same names, and identical bodies" do
+ a = MethodSpecs::Eql.instance_method(:same_body)
+ b = MethodSpecs::Eql2.instance_method(:same_body)
+ (a == b).should == false
+ end
+
+ it "returns false if the argument is not a Method object" do
+ (String.instance_method(:size) == 7).should == false
+ end
+
+ it "returns false if the argument is an unbound version of self" do
+ (method(:load) == method(:load).unbind).should == false
+ end
end