Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rubinius/rubinius
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 25405ee88e81
Choose a base ref
...
head repository: rubinius/rubinius
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: c96c52ce4789
Choose a head ref
  • 3 commits
  • 2 files changed
  • 2 contributors

Commits on Dec 4, 2014

  1. Describe define_method interaction w UnboundMethod

    Thanks to @jc00ke for pairing with me on this!
    jbr committed Dec 4, 2014

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    572cf4c View commit details
  2. tag failing unbound method specs

    jbr committed Dec 4, 2014
    Copy the full SHA
    309f6aa View commit details
  3. Merge pull request #3229 from jbr/define_method

    Add some UnboundMethod specs
    
    Thanks @jbr!
    jc00ke committed Dec 4, 2014
    Copy the full SHA
    c96c52c View commit details
Showing with 39 additions and 11 deletions.
  1. +37 −11 spec/ruby/core/module/define_method_spec.rb
  2. +2 −0 spec/tags/ruby/core/module/define_method_tags.txt
48 changes: 37 additions & 11 deletions spec/ruby/core/module/define_method_spec.rb
Original file line number Diff line number Diff line change
@@ -213,18 +213,44 @@ class DefineMethodSpecClass
end
end

describe "method body is an UnboundMethod" do
before do
@lazy_class_def = lambda {
LazyClass = Class.new do
define_method :bar, ModuleSpecs::UnboundMethodTest.instance_method(:foo)
end
}
end
it "allows an UnboundMethod from a module to be defined on a class" do
DestinationClass = Class.new {
define_method :bar, ModuleSpecs::UnboundMethodTest.instance_method(:foo)
}
DestinationClass.new.should respond_to(:bar)
end

it "allows methods defined on a different object" do
@lazy_class_def.call.new.bar.should == 'bar'
end
it "allows an UnboundMethod from a parent class to be defined on a child class" do
Parent = Class.new { define_method(:foo) { :bar } }
ChildClass = Class.new(Parent) {
define_method :baz, Parent.instance_method(:foo)
}
ChildClass.new.should respond_to(:baz)
end

it "allows an UnboundMethod from a module to be defined on another unrelated module" do
DestinationModule = Module.new {
define_method :bar, ModuleSpecs::UnboundMethodTest.instance_method(:foo)
}
DestinationClass = Class.new { include DestinationModule }

DestinationClass.new.should respond_to(:bar)
end

it "raises a TypeError when an UnboundMethod from a child class is defined on a parent class" do
lambda {
ParentClass = Class.new { define_method(:foo) { :bar } }
ChildClass = Class.new(ParentClass) { define_method(:foo) { :baz } }
ParentClass.send :define_method, :foo, ChildClass.instance_method(:foo)
}.should raise_error(TypeError)
end

it "raises a TypeError when an UnboundMethod from one class is defined on an unrelated class" do
lambda {
DestinationClass = Class.new {
define_method :bar, ModuleSpecs::InstanceMeth.instance_method(:foo)
}
}.should raise_error(TypeError)
end
end

2 changes: 2 additions & 0 deletions spec/tags/ruby/core/module/define_method_tags.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fails:Module#define_method raises a TypeError when an UnboundMethod from a child class is defined on a parent class
fails:Module#define_method raises a TypeError when an UnboundMethod from one class is defined on an unrelated class