Add specs for calling into Kernel#lambda with super
This commit is contained in:
parent
ea405ee8ed
commit
e0b336c8ce
Notes:
git
2019-12-21 23:09:18 +09:00
@ -337,6 +337,28 @@ module KernelSpecs
|
||||
end
|
||||
end
|
||||
|
||||
module LambdaSpecs
|
||||
module ZSuper
|
||||
def lambda
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
class ForwardBlockWithZSuper
|
||||
prepend(ZSuper)
|
||||
end
|
||||
|
||||
module Ampersand
|
||||
def lambda(&block)
|
||||
super(&block)
|
||||
end
|
||||
end
|
||||
|
||||
class SuperAmpersand
|
||||
prepend(Ampersand)
|
||||
end
|
||||
end
|
||||
|
||||
class RespondViaMissing
|
||||
def respond_to_missing?(method, priv=false)
|
||||
case method
|
||||
|
@ -31,13 +31,28 @@ describe "Kernel.lambda" do
|
||||
l.lambda?.should be_true
|
||||
end
|
||||
|
||||
it "returned the passed Proc if given an existing Proc" do
|
||||
it "returns the passed Proc if given an existing Proc" do
|
||||
some_proc = proc {}
|
||||
l = lambda(&some_proc)
|
||||
l.should equal(some_proc)
|
||||
l.lambda?.should be_false
|
||||
end
|
||||
|
||||
it "creates a lambda-style Proc when called with zsuper" do
|
||||
l = KernelSpecs::LambdaSpecs::ForwardBlockWithZSuper.new.lambda { 42 }
|
||||
l.lambda?.should be_true
|
||||
l.call.should == 42
|
||||
|
||||
lambda { l.call(:extra) }.should raise_error(ArgumentError)
|
||||
end
|
||||
|
||||
it "returns the passed Proc if given an existing Proc through super" do
|
||||
some_proc = proc { }
|
||||
l = KernelSpecs::LambdaSpecs::SuperAmpersand.new.lambda(&some_proc)
|
||||
l.should equal(some_proc)
|
||||
l.lambda?.should be_false
|
||||
end
|
||||
|
||||
it "checks the arity of the call when no args are specified" do
|
||||
l = lambda { :called }
|
||||
l.call.should == :called
|
||||
|
Loading…
x
Reference in New Issue
Block a user