summaryrefslogtreecommitdiff
path: root/spec/ruby/core/proc/lambda_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/core/proc/lambda_spec.rb')
-rw-r--r--spec/ruby/core/proc/lambda_spec.rb55
1 files changed, 55 insertions, 0 deletions
diff --git a/spec/ruby/core/proc/lambda_spec.rb b/spec/ruby/core/proc/lambda_spec.rb
new file mode 100644
index 0000000000..1ff6147319
--- /dev/null
+++ b/spec/ruby/core/proc/lambda_spec.rb
@@ -0,0 +1,55 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
+
+describe "Proc#lambda?" do
+ it "returns true if the Proc was created from a block with the lambda keyword" do
+ -> {}.lambda?.should == true
+ end
+
+ it "returns false if the Proc was created from a block with the proc keyword" do
+ proc {}.lambda?.should == false
+ end
+
+ it "returns false if the Proc was created from a block with Proc.new" do
+ Proc.new {}.lambda?.should == false
+ end
+
+ it "is preserved when passing a Proc with & to the proc keyword" do
+ proc(&->{}).lambda?.should == true
+ proc(&proc{}).lambda?.should == false
+ end
+
+ it "is preserved when passing a Proc with & to Proc.new" do
+ Proc.new(&->{}).lambda?.should == true
+ Proc.new(&proc{}).lambda?.should == false
+ end
+
+ it "returns false if the Proc was created from a block with &" do
+ ProcSpecs.new_proc_from_amp{}.lambda?.should == false
+ end
+
+ it "is preserved when the Proc was passed using &" do
+ ProcSpecs.new_proc_from_amp(&->{}).lambda?.should == true
+ ProcSpecs.new_proc_from_amp(&proc{}).lambda?.should == false
+ ProcSpecs.new_proc_from_amp(&Proc.new{}).lambda?.should == false
+ end
+
+ it "returns true for a Method converted to a Proc" do
+ m = :foo.method(:to_s)
+ m.to_proc.lambda?.should == true
+ ProcSpecs.new_proc_from_amp(&m).lambda?.should == true
+ end
+
+ # [ruby-core:24127]
+ it "is preserved when a Proc is curried" do
+ ->{}.curry.lambda?.should == true
+ proc{}.curry.lambda?.should == false
+ Proc.new{}.curry.lambda?.should == false
+ end
+
+ it "is preserved when a curried Proc is called without enough arguments" do
+ -> x, y{}.curry.call(42).lambda?.should == true
+ proc{|x,y|}.curry.call(42).lambda?.should == false
+ Proc.new{|x,y|}.curry.call(42).lambda?.should == false
+ end
+end