diff options
author | Benoit Daloze <eregontp@gmail.com> | 2019-07-27 12:40:09 +0200 |
---|---|---|
committer | Benoit Daloze <eregontp@gmail.com> | 2019-07-27 12:40:09 +0200 |
commit | 5c276e1cc91c5ab2a41fbf7827af2fed914a2bc0 (patch) | |
tree | 05b5c68c8b2a00224d4646ea3b26ce3877efaadd /spec/ruby/core/proc | |
parent | a06301b103371b0b7da8eaca26ba744961769f99 (diff) |
Update to ruby/spec@875a09e
Diffstat (limited to 'spec/ruby/core/proc')
-rw-r--r-- | spec/ruby/core/proc/allocate_spec.rb | 2 | ||||
-rw-r--r-- | spec/ruby/core/proc/binding_spec.rb | 4 | ||||
-rw-r--r-- | spec/ruby/core/proc/compose_spec.rb | 16 | ||||
-rw-r--r-- | spec/ruby/core/proc/curry_spec.rb | 60 | ||||
-rw-r--r-- | spec/ruby/core/proc/fixtures/source_location.rb | 6 | ||||
-rw-r--r-- | spec/ruby/core/proc/hash_spec.rb | 2 | ||||
-rw-r--r-- | spec/ruby/core/proc/lambda_spec.rb | 14 | ||||
-rw-r--r-- | spec/ruby/core/proc/new_spec.rb | 12 | ||||
-rw-r--r-- | spec/ruby/core/proc/parameters_spec.rb | 36 | ||||
-rw-r--r-- | spec/ruby/core/proc/shared/call.rb | 28 | ||||
-rw-r--r-- | spec/ruby/core/proc/shared/call_arguments.rb | 2 | ||||
-rw-r--r-- | spec/ruby/core/proc/shared/dup.rb | 2 | ||||
-rw-r--r-- | spec/ruby/core/proc/shared/equal.rb | 20 | ||||
-rw-r--r-- | spec/ruby/core/proc/shared/to_s.rb | 4 | ||||
-rw-r--r-- | spec/ruby/core/proc/source_location_spec.rb | 2 | ||||
-rw-r--r-- | spec/ruby/core/proc/to_proc_spec.rb | 2 |
16 files changed, 114 insertions, 98 deletions
diff --git a/spec/ruby/core/proc/allocate_spec.rb b/spec/ruby/core/proc/allocate_spec.rb index a512c73b1a..54e1b69df9 100644 --- a/spec/ruby/core/proc/allocate_spec.rb +++ b/spec/ruby/core/proc/allocate_spec.rb @@ -2,7 +2,7 @@ require_relative '../../spec_helper' describe "Proc.allocate" do it "raises a TypeError" do - lambda { + -> { Proc.allocate }.should raise_error(TypeError) end diff --git a/spec/ruby/core/proc/binding_spec.rb b/spec/ruby/core/proc/binding_spec.rb index 5e8a461a55..86ab6bd400 100644 --- a/spec/ruby/core/proc/binding_spec.rb +++ b/spec/ruby/core/proc/binding_spec.rb @@ -2,7 +2,7 @@ require_relative '../../spec_helper' describe "Proc#binding" do it "returns a Binding instance" do - [Proc.new{}, lambda {}, proc {}].each { |p| + [Proc.new{}, -> {}, proc {}].each { |p| p.binding.should be_kind_of(Binding) } end @@ -10,7 +10,7 @@ describe "Proc#binding" do it "returns the binding associated with self" do obj = mock('binding') def obj.test_binding(some, params) - lambda {} + -> {} end lambdas_binding = obj.test_binding(1, 2).binding diff --git a/spec/ruby/core/proc/compose_spec.rb b/spec/ruby/core/proc/compose_spec.rb index f1befe658b..35e949a779 100644 --- a/spec/ruby/core/proc/compose_spec.rb +++ b/spec/ruby/core/proc/compose_spec.rb @@ -44,6 +44,14 @@ ruby_version_is "2.6" do (inc << mul).call(2, 3).should == 7 end + + it "passes blocks to the second proc" do + ScratchPad.record [] + one = proc { |&arg| arg.call :one if arg } + two = proc { |&arg| arg.call :two if arg } + (one << two).call { |x| ScratchPad << x } + ScratchPad.recorded.should == [:two] + end end end @@ -89,6 +97,14 @@ ruby_version_is "2.6" do (mul >> inc).call(2, 3).should == 7 end + + it "passes blocks to the first proc" do + ScratchPad.record [] + one = proc { |&arg| arg.call :one if arg } + two = proc { |&arg| arg.call :two if arg } + (one >> two).call { |x| ScratchPad << x } + ScratchPad.recorded.should == [:one] + end end end end diff --git a/spec/ruby/core/proc/curry_spec.rb b/spec/ruby/core/proc/curry_spec.rb index 7d1da441f1..24df2a8a72 100644 --- a/spec/ruby/core/proc/curry_spec.rb +++ b/spec/ruby/core/proc/curry_spec.rb @@ -3,7 +3,7 @@ require_relative '../../spec_helper' describe "Proc#curry" do before :each do @proc_add = Proc.new {|x,y,z| (x||0) + (y||0) + (z||0) } - @lambda_add = lambda {|x,y,z| (x||0) + (y||0) + (z||0) } + @lambda_add = -> x, y, z { (x||0) + (y||0) + (z||0) } end it "returns a Proc when called on a proc" do @@ -12,7 +12,7 @@ describe "Proc#curry" do end it "returns a Proc when called on a lambda" do - p = lambda { true } + p = -> { true } p.curry.should be_an_instance_of(Proc) end @@ -36,10 +36,10 @@ describe "Proc#curry" do it "can be called multiple times on the same Proc" do @proc_add.curry - lambda { @proc_add.curry }.should_not raise_error + -> { @proc_add.curry }.should_not raise_error @lambda_add.curry - lambda { @lambda_add.curry }.should_not raise_error + -> { @lambda_add.curry }.should_not raise_error end it "can be passed superfluous arguments if created from a proc" do @@ -49,19 +49,19 @@ describe "Proc#curry" do end it "raises an ArgumentError if passed superfluous arguments when created from a lambda" do - lambda { @lambda_add.curry[1,2,3,4] }.should raise_error(ArgumentError) - lambda { @lambda_add.curry[1,2].curry[3,4,5,6] }.should raise_error(ArgumentError) + -> { @lambda_add.curry[1,2,3,4] }.should raise_error(ArgumentError) + -> { @lambda_add.curry[1,2].curry[3,4,5,6] }.should raise_error(ArgumentError) end it "returns Procs with arities of -1" do @proc_add.curry.arity.should == -1 @lambda_add.curry.arity.should == -1 - l = lambda { |*a| } + l = -> *a { } l.curry.arity.should == -1 end it "produces Procs that raise ArgumentError for #binding" do - lambda do + -> do @proc_add.curry.binding end.should raise_error(ArgumentError) end @@ -81,7 +81,7 @@ describe "Proc#curry" do end it "combines arguments and calculates incoming arity accurately for successively currying" do - l = lambda{|a,b,c| a+b+c } + l = -> a, b, c { a+b+c } l1 = l.curry.call(1) # the l1 currying seems unnecessary, but it triggered the original issue l2 = l1.curry.call(2) @@ -93,13 +93,13 @@ end describe "Proc#curry with arity argument" do before :each do - @proc_add = proc {|x,y,z| (x||0) + (y||0) + (z||0) } - @lambda_add = lambda {|x,y,z| (x||0) + (y||0) + (z||0) } + @proc_add = proc { |x,y,z| (x||0) + (y||0) + (z||0) } + @lambda_add = -> x, y, z { (x||0) + (y||0) + (z||0) } end it "accepts an optional Integer argument for the arity" do - lambda { @proc_add.curry(3) }.should_not raise_error - lambda { @lambda_add.curry(3) }.should_not raise_error + -> { @proc_add.curry(3) }.should_not raise_error + -> { @lambda_add.curry(3) }.should_not raise_error end it "returns a Proc when called on a proc" do @@ -117,22 +117,22 @@ describe "Proc#curry with arity argument" do end it "raises an ArgumentError if called on a lambda that requires more than _arity_ arguments" do - lambda { @lambda_add.curry(2) }.should raise_error(ArgumentError) - lambda { lambda{|x, y, z, *more|}.curry(2) }.should raise_error(ArgumentError) + -> { @lambda_add.curry(2) }.should raise_error(ArgumentError) + -> { -> x, y, z, *more{}.curry(2) }.should raise_error(ArgumentError) end it 'returns a Proc if called on a lambda that requires fewer than _arity_ arguments but may take more' do - lambda{|a, b, c, d=nil, e=nil|}.curry(4).should be_an_instance_of(Proc) - lambda{|a, b, c, d=nil, *e|}.curry(4).should be_an_instance_of(Proc) - lambda{|a, b, c, *d|}.curry(4).should be_an_instance_of(Proc) + -> a, b, c, d=nil, e=nil {}.curry(4).should be_an_instance_of(Proc) + -> a, b, c, d=nil, *e {}.curry(4).should be_an_instance_of(Proc) + -> a, b, c, *d {}.curry(4).should be_an_instance_of(Proc) end it "raises an ArgumentError if called on a lambda that requires fewer than _arity_ arguments" do - lambda { @lambda_add.curry(4) }.should raise_error(ArgumentError) - lambda { lambda { true }.curry(1) }.should raise_error(ArgumentError) - lambda { lambda {|a, b=nil|}.curry(5) }.should raise_error(ArgumentError) - lambda { lambda {|a, &b|}.curry(2) }.should raise_error(ArgumentError) - lambda { lambda {|a, b=nil, &c|}.curry(3) }.should raise_error(ArgumentError) + -> { @lambda_add.curry(4) }.should raise_error(ArgumentError) + -> { -> { true }.curry(1) }.should raise_error(ArgumentError) + -> { -> a, b=nil {}.curry(5) }.should raise_error(ArgumentError) + -> { -> a, &b {}.curry(2) }.should raise_error(ArgumentError) + -> { -> a, b=nil, &c {}.curry(3) }.should raise_error(ArgumentError) end it "calls the curried proc with the arguments if _arity_ arguments have been given" do @@ -152,29 +152,29 @@ describe "Proc#curry with arity argument" do it "can be specified multiple times on the same Proc" do @proc_add.curry(2) - lambda { @proc_add.curry(1) }.should_not raise_error + -> { @proc_add.curry(1) }.should_not raise_error @lambda_add.curry(3) - lambda { @lambda_add.curry(3) }.should_not raise_error + -> { @lambda_add.curry(3) }.should_not raise_error end it "can be passed more than _arity_ arguments if created from a proc" do - lambda { @proc_add.curry(3)[1,2,3,4].should == 6 }.should_not + -> { @proc_add.curry(3)[1,2,3,4].should == 6 }.should_not raise_error(ArgumentError) - lambda { @proc_add.curry(1)[1,2].curry(3)[3,4,5,6].should == 6 }.should_not + -> { @proc_add.curry(1)[1,2].curry(3)[3,4,5,6].should == 6 }.should_not raise_error(ArgumentError) end it "raises an ArgumentError if passed more than _arity_ arguments when created from a lambda" do - lambda { @lambda_add.curry(3)[1,2,3,4] }.should raise_error(ArgumentError) - lambda { @lambda_add.curry(1)[1,2].curry(3)[3,4,5,6] }.should raise_error(ArgumentError) + -> { @lambda_add.curry(3)[1,2,3,4] }.should raise_error(ArgumentError) + -> { @lambda_add.curry(1)[1,2].curry(3)[3,4,5,6] }.should raise_error(ArgumentError) end it "returns Procs with arities of -1 regardless of the value of _arity_" do @proc_add.curry(1).arity.should == -1 @proc_add.curry(2).arity.should == -1 @lambda_add.curry(3).arity.should == -1 - l = lambda { |*a| } + l = -> *a { } l.curry(3).arity.should == -1 end end diff --git a/spec/ruby/core/proc/fixtures/source_location.rb b/spec/ruby/core/proc/fixtures/source_location.rb index 468262e02a..688dac1e22 100644 --- a/spec/ruby/core/proc/fixtures/source_location.rb +++ b/spec/ruby/core/proc/fixtures/source_location.rb @@ -5,7 +5,7 @@ module ProcSpecs end def self.my_lambda - lambda { true } + -> { true } end def self.my_proc_new @@ -24,7 +24,7 @@ module ProcSpecs end def self.my_multiline_lambda - lambda do + -> do 'a'.upcase 1 + 22 end @@ -43,7 +43,7 @@ module ProcSpecs end def self.my_detached_lambda - body = lambda { true } + body = -> { true } lambda(&body) end diff --git a/spec/ruby/core/proc/hash_spec.rb b/spec/ruby/core/proc/hash_spec.rb index 5993ad5098..d780c1ceb0 100644 --- a/spec/ruby/core/proc/hash_spec.rb +++ b/spec/ruby/core/proc/hash_spec.rb @@ -3,7 +3,7 @@ require_relative '../../spec_helper' describe "Proc#hash" do it "is provided" do proc {}.respond_to?(:hash).should be_true - lambda {}.respond_to?(:hash).should be_true + -> {}.respond_to?(:hash).should be_true end it "returns an Integer" do diff --git a/spec/ruby/core/proc/lambda_spec.rb b/spec/ruby/core/proc/lambda_spec.rb index edf2151f27..fe2ceb4279 100644 --- a/spec/ruby/core/proc/lambda_spec.rb +++ b/spec/ruby/core/proc/lambda_spec.rb @@ -3,7 +3,7 @@ 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 {}.lambda?.should be_true + -> {}.lambda?.should be_true end it "returns false if the Proc was created from a block with the proc keyword" do @@ -15,17 +15,17 @@ describe "Proc#lambda?" do end it "is preserved when passing a Proc with & to the lambda keyword" do - lambda(&lambda{}).lambda?.should be_true + lambda(&->{}).lambda?.should be_true lambda(&proc{}).lambda?.should be_false end it "is preserved when passing a Proc with & to the proc keyword" do - proc(&lambda{}).lambda?.should be_true + proc(&->{}).lambda?.should be_true proc(&proc{}).lambda?.should be_false end it "is preserved when passing a Proc with & to Proc.new" do - Proc.new(&lambda{}).lambda?.should be_true + Proc.new(&->{}).lambda?.should be_true Proc.new(&proc{}).lambda?.should be_false end @@ -34,7 +34,7 @@ describe "Proc#lambda?" do end it "is preserved when the Proc was passed using &" do - ProcSpecs.new_proc_from_amp(&lambda{}).lambda?.should be_true + ProcSpecs.new_proc_from_amp(&->{}).lambda?.should be_true ProcSpecs.new_proc_from_amp(&proc{}).lambda?.should be_false ProcSpecs.new_proc_from_amp(&Proc.new{}).lambda?.should be_false end @@ -47,13 +47,13 @@ describe "Proc#lambda?" do # [ruby-core:24127] it "is preserved when a Proc is curried" do - lambda{}.curry.lambda?.should be_true + ->{}.curry.lambda?.should be_true proc{}.curry.lambda?.should be_false Proc.new{}.curry.lambda?.should be_false end it "is preserved when a curried Proc is called without enough arguments" do - lambda{|x,y|}.curry.call(42).lambda?.should be_true + -> x, y{}.curry.call(42).lambda?.should be_true proc{|x,y|}.curry.call(42).lambda?.should be_false Proc.new{|x,y|}.curry.call(42).lambda?.should be_false end diff --git a/spec/ruby/core/proc/new_spec.rb b/spec/ruby/core/proc/new_spec.rb index 60a7320e4b..cc033467e5 100644 --- a/spec/ruby/core/proc/new_spec.rb +++ b/spec/ruby/core/proc/new_spec.rb @@ -71,7 +71,7 @@ describe "Proc.new with an associated block" do end res = some_method() - lambda { res.call }.should raise_error(LocalJumpError) + -> { res.call }.should raise_error(LocalJumpError) end it "returns from within enclosing method when 'return' is used in the block" do @@ -169,15 +169,15 @@ end describe "Proc.new without a block" do it "raises an ArgumentError" do - lambda { Proc.new }.should raise_error(ArgumentError) + -> { Proc.new }.should raise_error(ArgumentError) end it "raises an ArgumentError if invoked from within a method with no block" do - lambda { ProcSpecs.new_proc_in_method }.should raise_error(ArgumentError) + -> { ProcSpecs.new_proc_in_method }.should raise_error(ArgumentError) end it "raises an ArgumentError if invoked on a subclass from within a method with no block" do - lambda { ProcSpecs.new_proc_subclass_in_method }.should raise_error(ArgumentError) + -> { ProcSpecs.new_proc_subclass_in_method }.should raise_error(ArgumentError) end ruby_version_is ""..."2.7" do @@ -205,11 +205,11 @@ describe "Proc.new without a block" do ruby_version_is "2.7" do it "can be created if invoked from within a method with a block" do - lambda { ProcSpecs.new_proc_in_method { "hello" } }.should complain(/Capturing the given block using Proc.new is deprecated/) + -> { ProcSpecs.new_proc_in_method { "hello" } }.should complain(/Capturing the given block using Proc.new is deprecated/) end it "can be created if invoked on a subclass from within a method with a block" do - lambda { ProcSpecs.new_proc_subclass_in_method { "hello" } }.should complain(/Capturing the given block using Proc.new is deprecated/) + -> { ProcSpecs.new_proc_subclass_in_method { "hello" } }.should complain(/Capturing the given block using Proc.new is deprecated/) end diff --git a/spec/ruby/core/proc/parameters_spec.rb b/spec/ruby/core/proc/parameters_spec.rb index 4a8958497d..2bc5f1325c 100644 --- a/spec/ruby/core/proc/parameters_spec.rb +++ b/spec/ruby/core/proc/parameters_spec.rb @@ -25,17 +25,17 @@ describe "Proc#parameters" do end it "regards parameters with default values as optional" do - lambda {|x=1| }.parameters.first.first.should == :opt + -> x=1 { }.parameters.first.first.should == :opt proc {|x=1| }.parameters.first.first.should == :opt end it "sets the first element of each sub-Array to :req for required arguments" do - lambda {|x,y=[]| }.parameters.first.first.should == :req - lambda {|y,*x| }.parameters.first.first.should == :req + -> x, y=[] { }.parameters.first.first.should == :req + -> y, *x { }.parameters.first.first.should == :req end it "regards named parameters in lambdas as required" do - lambda {|x| }.parameters.first.first.should == :req + -> x { }.parameters.first.first.should == :req end it "regards keyword parameters in lambdas as required" do @@ -43,32 +43,32 @@ describe "Proc#parameters" do end it "sets the first element of each sub-Array to :rest for parameters prefixed with asterisks" do - lambda {|*x| }.parameters.first.first.should == :rest - lambda {|x,*y| }.parameters.last.first.should == :rest + -> *x { }.parameters.first.first.should == :rest + -> x, *y { }.parameters.last.first.should == :rest proc {|*x| }.parameters.first.first.should == :rest proc {|x,*y| }.parameters.last.first.should == :rest end it "sets the first element of each sub-Array to :keyrest for parameters prefixed with double asterisks" do - lambda {|**x| }.parameters.first.first.should == :keyrest - lambda {|x,**y| }.parameters.last.first.should == :keyrest + -> **x { }.parameters.first.first.should == :keyrest + -> x, **y { }.parameters.last.first.should == :keyrest proc {|**x| }.parameters.first.first.should == :keyrest proc {|x,**y| }.parameters.last.first.should == :keyrest end it "sets the first element of each sub-Array to :block for parameters prefixed with ampersands" do - lambda {|&x| }.parameters.first.first.should == :block - lambda {|x,&y| }.parameters.last.first.should == :block + ->&x { }.parameters.first.first.should == :block + -> x, &y { }.parameters.last.first.should == :block proc {|&x| }.parameters.first.first.should == :block proc {|x,&y| }.parameters.last.first.should == :block end it "sets the second element of each sub-Array to the name of the argument" do - lambda {|x| }.parameters.first.last.should == :x - lambda {|x=Math::PI| }.parameters.first.last.should == :x - lambda {|an_argument, glark, &foo| }.parameters[1].last.should == :glark - lambda {|*rest| }.parameters.first.last.should == :rest - lambda {|&block| }.parameters.first.last.should == :block + -> x { }.parameters.first.last.should == :x + -> x=Math::PI { }.parameters.first.last.should == :x + -> an_argument, glark, &foo { }.parameters[1].last.should == :glark + -> *rest { }.parameters.first.last.should == :rest + ->&block { }.parameters.first.last.should == :block proc {|x| }.parameters.first.last.should == :x proc {|x=Math::PI| }.parameters.first.last.should == :x proc {|an_argument, glark, &foo| }.parameters[1].last.should == :glark @@ -77,15 +77,15 @@ describe "Proc#parameters" do end it "ignores unnamed rest args" do - lambda {|x,|}.parameters.should == [[:req, :x]] + -> x {}.parameters.should == [[:req, :x]] end it "adds nameless rest arg for \"star\" argument" do - lambda {|x,*|}.parameters.should == [[:req, :x], [:rest]] + -> x, * {}.parameters.should == [[:req, :x], [:rest]] end it "does not add locals as block options with a block and splat" do - lambda do |*args, &blk| + -> *args, &blk do local_is_not_parameter = {} end.parameters.should == [[:rest, :args], [:block, :blk]] proc do |*args, &blk| diff --git a/spec/ruby/core/proc/shared/call.rb b/spec/ruby/core/proc/shared/call.rb index 996d0e055d..c30ea84b23 100644 --- a/spec/ruby/core/proc/shared/call.rb +++ b/spec/ruby/core/proc/shared/call.rb @@ -3,7 +3,7 @@ require_relative '../fixtures/common' describe :proc_call, shared: true do it "invokes self" do Proc.new { "test!" }.send(@method).should == "test!" - lambda { "test!" }.send(@method).should == "test!" + -> { "test!" }.send(@method).should == "test!" proc { "test!" }.send(@method).should == "test!" end @@ -12,9 +12,9 @@ describe :proc_call, shared: true do Proc.new { |*args| args }.send(@method, 1, 2, 3, 4).should == [1, 2, 3, 4] Proc.new { |_, *args| args }.send(@method, 1, 2, 3).should == [2, 3] - lambda { |a, b| a + b }.send(@method, 1, 2).should == 3 - lambda { |*args| args }.send(@method, 1, 2, 3, 4).should == [1, 2, 3, 4] - lambda { |_, *args| args }.send(@method, 1, 2, 3).should == [2, 3] + -> a, b { a + b }.send(@method, 1, 2).should == 3 + -> *args { args }.send(@method, 1, 2, 3, 4).should == [1, 2, 3, 4] + -> _, *args { args }.send(@method, 1, 2, 3).should == [2, 3] proc { |a, b| a + b }.send(@method, 1, 2).should == 3 proc { |*args| args }.send(@method, 1, 2, 3, 4).should == [1, 2, 3, 4] @@ -65,28 +65,28 @@ describe :proc_call_on_proc_or_lambda, shared: true do end it "raises an ArgumentError on excess arguments when self is a lambda" do - lambda { - lambda {|x| x}.send(@method, 1, 2) + -> { + -> x { x }.send(@method, 1, 2) }.should raise_error(ArgumentError) - lambda { - lambda {|x| x}.send(@method, 1, 2, 3) + -> { + -> x { x }.send(@method, 1, 2, 3) }.should raise_error(ArgumentError) end it "raises an ArgumentError on missing arguments when self is a lambda" do - lambda { - lambda {|x| x}.send(@method) + -> { + -> x { x }.send(@method) }.should raise_error(ArgumentError) - lambda { - lambda {|x,y| [x,y]}.send(@method, 1) + -> { + -> x, y { [x,y] }.send(@method, 1) }.should raise_error(ArgumentError) end it "treats a single Array argument as a single argument when self is a lambda" do - lambda { |a| a }.send(@method, [1, 2]).should == [1, 2] - lambda { |a, b| [a, b] }.send(@method, [1, 2], 3).should == [[1,2], 3] + -> a { a }.send(@method, [1, 2]).should == [1, 2] + -> a, b { [a, b] }.send(@method, [1, 2], 3).should == [[1,2], 3] end it "treats a single Array argument as a single argument when self is a proc" do diff --git a/spec/ruby/core/proc/shared/call_arguments.rb b/spec/ruby/core/proc/shared/call_arguments.rb index a937bd99d0..ef6ec04620 100644 --- a/spec/ruby/core/proc/shared/call_arguments.rb +++ b/spec/ruby/core/proc/shared/call_arguments.rb @@ -1,7 +1,7 @@ describe :proc_call_block_args, shared: true do it "can receive block arguments" do Proc.new {|&b| b.send(@method)}.send(@method) {1 + 1}.should == 2 - lambda {|&b| b.send(@method)}.send(@method) {1 + 1}.should == 2 + ->&b { b.send(@method)}.send(@method) {1 + 1}.should == 2 proc {|&b| b.send(@method)}.send(@method) {1 + 1}.should == 2 end diff --git a/spec/ruby/core/proc/shared/dup.rb b/spec/ruby/core/proc/shared/dup.rb index fb6fff299d..eda1d6929d 100644 --- a/spec/ruby/core/proc/shared/dup.rb +++ b/spec/ruby/core/proc/shared/dup.rb @@ -1,6 +1,6 @@ describe :proc_dup, shared: true do it "returns a copy of self" do - a = lambda { "hello" } + a = -> { "hello" } b = a.send(@method) a.should_not equal(b) diff --git a/spec/ruby/core/proc/shared/equal.rb b/spec/ruby/core/proc/shared/equal.rb index a5d067cea3..46a1894424 100644 --- a/spec/ruby/core/proc/shared/equal.rb +++ b/spec/ruby/core/proc/shared/equal.rb @@ -13,7 +13,7 @@ describe :proc_equal, shared: true do p = Proc.new { :foo } p.send(@method, p).should be_true - p = lambda { :foo } + p = -> { :foo } p.send(@method, p).should be_true end @@ -24,7 +24,7 @@ describe :proc_equal, shared: true do p = Proc.new { :foo } p.send(@method, p.dup).should be_true - p = lambda { :foo } + p = -> { :foo } p.send(@method, p.dup).should be_true end @@ -43,18 +43,18 @@ describe :proc_equal, shared: true do end it "returns true if both lambdas with the same body and environment" do - x = lambda { :foo } - x2 = lambda { :foo } + x = -> { :foo } + x2 = -> { :foo } x.send(@method, x2).should be_true end it "returns true if both different kinds of procs with the same body and env" do - p = lambda { :foo } + p = -> { :foo } p2 = proc { :foo } p.send(@method, p2).should be_true x = proc { :bar } - x2 = lambda { :bar } + x2 = -> { :bar } x.send(@method, x2).should be_true end @@ -65,7 +65,7 @@ describe :proc_equal, shared: true do p = Proc.new { :foo } p.send(@method, Object.new).should be_false - p = lambda { :foo } + p = -> { :foo } p.send(@method, :foo).should be_false end @@ -76,8 +76,8 @@ describe :proc_equal, shared: true do end it "returns false if self and other are both lambdas but have different bodies" do - p = lambda { :foo } - p2 = lambda { :bar } + p = -> { :foo } + p2 = -> { :bar } p.send(@method, p2).should be_false end end @@ -94,7 +94,7 @@ describe :proc_equal_undefined, shared: true do p = Proc.new { :foo } p.send(@method, p.dup).should be_false - p = lambda { :foo } + p = -> { :foo } p.send(@method, p.dup).should be_false end end diff --git a/spec/ruby/core/proc/shared/to_s.rb b/spec/ruby/core/proc/shared/to_s.rb index 59fcf5bef0..a4d1d5d630 100644 --- a/spec/ruby/core/proc/shared/to_s.rb +++ b/spec/ruby/core/proc/shared/to_s.rb @@ -11,11 +11,11 @@ describe :proc_to_s, shared: true do describe "for a proc created with lambda" do it "returns a description including '(lambda)' and optionally including file and line number" do - lambda { "hello" }.send(@method).should =~ /^#<Proc:([^ ]*?)(@([^ ]*)\/to_s\.rb:10)? \(lambda\)>$/ + -> { "hello" }.send(@method).should =~ /^#<Proc:([^ ]*?)(@([^ ]*)\/to_s\.rb:10)? \(lambda\)>$/ end it "has a binary encoding" do - lambda { "hello" }.send(@method).encoding.should == Encoding::BINARY + -> { "hello" }.send(@method).encoding.should == Encoding::BINARY end end diff --git a/spec/ruby/core/proc/source_location_spec.rb b/spec/ruby/core/proc/source_location_spec.rb index 89409c357b..b5b8178df2 100644 --- a/spec/ruby/core/proc/source_location_spec.rb +++ b/spec/ruby/core/proc/source_location_spec.rb @@ -55,7 +55,7 @@ describe "Proc#source_location" do it "works even if the proc was created on the same line" do proc { true }.source_location.should == [__FILE__, __LINE__] Proc.new { true }.source_location.should == [__FILE__, __LINE__] - lambda { true }.source_location.should == [__FILE__, __LINE__] + -> { true }.source_location.should == [__FILE__, __LINE__] end it "returns the first line of a multi-line proc (i.e. the line containing 'proc do')" do diff --git a/spec/ruby/core/proc/to_proc_spec.rb b/spec/ruby/core/proc/to_proc_spec.rb index 24e66760e4..ffaa34929b 100644 --- a/spec/ruby/core/proc/to_proc_spec.rb +++ b/spec/ruby/core/proc/to_proc_spec.rb @@ -2,7 +2,7 @@ require_relative '../../spec_helper' describe "Proc#to_proc" do it "returns self" do - [Proc.new {}, lambda {}, proc {}].each { |p| + [Proc.new {}, -> {}, proc {}].each { |p| p.to_proc.should equal(p) } end |