mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Move spec/rubyspec to spec/ruby for consistency
* Other ruby implementations use the spec/ruby directory. [Misc #13792] [ruby-core:82287] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59979 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
75bfc6440d
commit
1d15d5f080
4370 changed files with 0 additions and 0 deletions
51
spec/ruby/core/unboundmethod/bind_spec.rb
Normal file
51
spec/ruby/core/unboundmethod/bind_spec.rb
Normal file
|
@ -0,0 +1,51 @@
|
|||
require File.expand_path('../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../fixtures/classes', __FILE__)
|
||||
|
||||
describe "UnboundMethod#bind" do
|
||||
before :each do
|
||||
@normal_um = UnboundMethodSpecs::Methods.new.method(:foo).unbind
|
||||
@parent_um = UnboundMethodSpecs::Parent.new.method(:foo).unbind
|
||||
@child1_um = UnboundMethodSpecs::Child1.new.method(:foo).unbind
|
||||
@child2_um = UnboundMethodSpecs::Child2.new.method(:foo).unbind
|
||||
end
|
||||
|
||||
it "raises TypeError if object is not kind_of? the Module the method defined in" do
|
||||
lambda { @normal_um.bind(UnboundMethodSpecs::B.new) }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
it "returns Method for any object that is kind_of? the Module method was extracted from" do
|
||||
@normal_um.bind(UnboundMethodSpecs::Methods.new).should be_kind_of(Method)
|
||||
end
|
||||
|
||||
it "returns Method on any object when UnboundMethod is unbound from a module" do
|
||||
UnboundMethodSpecs::Mod.instance_method(:from_mod).bind(Object.new).should be_kind_of(Method)
|
||||
end
|
||||
|
||||
it "returns Method returned for obj is equal to one directly returned by obj.method" do
|
||||
obj = UnboundMethodSpecs::Methods.new
|
||||
@normal_um.bind(obj).should == obj.method(:foo)
|
||||
end
|
||||
|
||||
it "returns a callable method" do
|
||||
obj = UnboundMethodSpecs::Methods.new
|
||||
@normal_um.bind(obj).call.should == obj.foo
|
||||
end
|
||||
|
||||
it "binds a Parent's class method to any Child's class methods" do
|
||||
m = UnboundMethodSpecs::Parent.method(:class_method).unbind.bind(UnboundMethodSpecs::Child1)
|
||||
m.should be_an_instance_of(Method)
|
||||
m.call.should == "I am UnboundMethodSpecs::Child1"
|
||||
end
|
||||
|
||||
it "will raise when binding a an object singleton's method to another object" do
|
||||
other = UnboundMethodSpecs::Parent.new
|
||||
p = UnboundMethodSpecs::Parent.new
|
||||
class << p
|
||||
def singleton_method
|
||||
:single
|
||||
end
|
||||
end
|
||||
um = p.method(:singleton_method).unbind
|
||||
lambda{ um.bind(other) }.should raise_error(TypeError)
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue