Skip to content

Commit

Permalink
Port specs for UnboundMethod and Method
Browse files Browse the repository at this point in the history
Ported specs for UnboundMethod#super_method and Method#super_method.
Like Float#next_float Float#prev_float they were introduced in rubyspec
by @jemc but didn't made it into rubinius itself.
  • Loading branch information
tak1n committed May 26, 2015
1 parent 952991e commit e078e4e
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 0 deletions.
12 changes: 12 additions & 0 deletions spec/ruby/core/method/fixtures/classes.rb
Expand Up @@ -99,12 +99,24 @@ class A
def baz(a, b)
self.class
end
def overridden; end
end

class B < A
def overridden; end
end

module BetweenBAndC
def overridden; end
end

class C < B
include BetweenBAndC
def overridden; end
end

module OverrideAgain
def overridden; end
end

class D
Expand Down
25 changes: 25 additions & 0 deletions spec/ruby/core/method/super_method_spec.rb
@@ -0,0 +1,25 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/classes', __FILE__)

describe "Method#super_method" do
it "returns the method that would be called by super in the method" do
obj = MethodSpecs::C.new
obj.extend MethodSpecs::OverrideAgain
meth = obj.method(:overridden)

s_meth = meth.super_method
s_meth.owner.should == MethodSpecs::C
s_meth.receiver.should == obj
s_meth.name.should == :overridden

ss_meth = meth.super_method.super_method
ss_meth.owner.should == MethodSpecs::BetweenBAndC
ss_meth.receiver.should == obj
ss_meth.name.should == :overridden

sss_meth = meth.super_method.super_method.super_method
sss_meth.owner.should == MethodSpecs::B
sss_meth.receiver.should == obj
sss_meth.name.should == :overridden
end
end
3 changes: 3 additions & 0 deletions spec/ruby/core/unboundmethod/fixtures/classes.rb
Expand Up @@ -73,11 +73,14 @@ class A
def baz(a, b)
return [__FILE__, self.class]
end
def overriden; end
end

class B < A
def overridden; end
end

class C < B
def overridden; end
end
end
12 changes: 12 additions & 0 deletions spec/ruby/core/unboundmethod/super_method_spec.rb
@@ -0,0 +1,12 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/classes', __FILE__)

describe "UnboundMethod#super_method" do
it "returns the method that would be called by super in the method" do
meth = UnboundMethodSpecs::C.instance_method(:overridden)
meth = meth.super_method
meth.should == UnboundMethodSpecs::B.instance_method(:overridden)
meth = meth.super_method
meth.should == UnboundMethodSpecs::A.instance_method(:overridden)
end
end
1 change: 1 addition & 0 deletions spec/tags/ruby/core/method/super_method_tags.txt
@@ -0,0 +1 @@
fails: returns the method that would be called by super in the method
1 change: 1 addition & 0 deletions spec/tags/ruby/core/unboundmethod/super_method_tags.txt
@@ -0,0 +1 @@
fails: returns the method that would be called by super in the method

0 comments on commit e078e4e

Please sign in to comment.