1 shared :kernel_lambda do |cmd|
2 describe "Kernel.#{cmd}" do
3 it "returns a Proc object" do
4 send(cmd) { true }.kind_of?(Proc).should == true
7 it "raises an ArgumentError when no block is given" do
8 lambda { send(cmd) }.should raise_error(ArgumentError)
11 it "raises an ArgumentError when given too many arguments" do
13 send(cmd) { |a, b| a + b }.call(1, 2, 5)
14 }.should raise_error(ArgumentError)
17 it "raises an ArgumentError when given too few arguments" do
19 send(cmd) { |a, b| a + b }.call(1)
20 }.should raise_error(ArgumentError)
23 it "returns from block into caller block" do
24 # More info in the pickaxe book pg. 359
26 p = send(cmd) { return 99 }
31 # Have to pass in the cmd errors otherwise
32 some_method(cmd).should == "returned 99"
34 def some_method2(&b) b end
35 a_proc = send(cmd) { return true }
36 res = some_method2(&a_proc)
38 res.call.should == true