diff options
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 | 2 | ||||
| -rw-r--r-- | spec/ruby/core/proc/block_pass_spec.rb | 4 | ||||
| -rw-r--r-- | spec/ruby/core/proc/clone_spec.rb | 20 | ||||
| -rw-r--r-- | spec/ruby/core/proc/curry_spec.rb | 62 | ||||
| -rw-r--r-- | spec/ruby/core/proc/dup_spec.rb | 18 | ||||
| -rw-r--r-- | spec/ruby/core/proc/element_reference_spec.rb | 10 | ||||
| -rw-r--r-- | spec/ruby/core/proc/hash_spec.rb | 6 | ||||
| -rw-r--r-- | spec/ruby/core/proc/lambda_spec.rb | 45 | ||||
| -rw-r--r-- | spec/ruby/core/proc/new_spec.rb | 28 | ||||
| -rw-r--r-- | spec/ruby/core/proc/parameters_spec.rb | 90 | ||||
| -rw-r--r-- | spec/ruby/core/proc/ruby2_keywords_spec.rb | 16 | ||||
| -rw-r--r-- | spec/ruby/core/proc/shared/call.rb | 8 | ||||
| -rw-r--r-- | spec/ruby/core/proc/shared/compose.rb | 4 | ||||
| -rw-r--r-- | spec/ruby/core/proc/shared/dup.rb | 10 | ||||
| -rw-r--r-- | spec/ruby/core/proc/shared/equal.rb | 34 | ||||
| -rw-r--r-- | spec/ruby/core/proc/source_location_spec.rb | 75 | ||||
| -rw-r--r-- | spec/ruby/core/proc/to_proc_spec.rb | 2 |
18 files changed, 213 insertions, 223 deletions
diff --git a/spec/ruby/core/proc/allocate_spec.rb b/spec/ruby/core/proc/allocate_spec.rb index 54e1b69df9..96c4eb9fa8 100644 --- a/spec/ruby/core/proc/allocate_spec.rb +++ b/spec/ruby/core/proc/allocate_spec.rb @@ -4,6 +4,6 @@ describe "Proc.allocate" do it "raises a TypeError" do -> { Proc.allocate - }.should raise_error(TypeError) + }.should.raise(TypeError) end end diff --git a/spec/ruby/core/proc/binding_spec.rb b/spec/ruby/core/proc/binding_spec.rb index 86ab6bd400..d643cbf89c 100644 --- a/spec/ruby/core/proc/binding_spec.rb +++ b/spec/ruby/core/proc/binding_spec.rb @@ -3,7 +3,7 @@ require_relative '../../spec_helper' describe "Proc#binding" do it "returns a Binding instance" do [Proc.new{}, -> {}, proc {}].each { |p| - p.binding.should be_kind_of(Binding) + p.binding.should.is_a?(Binding) } end diff --git a/spec/ruby/core/proc/block_pass_spec.rb b/spec/ruby/core/proc/block_pass_spec.rb index 411c0bf3db..82c08db8a7 100644 --- a/spec/ruby/core/proc/block_pass_spec.rb +++ b/spec/ruby/core/proc/block_pass_spec.rb @@ -8,14 +8,14 @@ describe "Proc as a block pass argument" do it "remains the same object if re-vivified by the target method" do p = Proc.new {} p2 = revivify(&p) - p.should equal p2 + p.should.equal? p2 p.should == p2 end it "remains the same object if reconstructed with Proc.new" do p = Proc.new {} p2 = Proc.new(&p) - p.should equal p2 + p.should.equal? p2 p.should == p2 end end diff --git a/spec/ruby/core/proc/clone_spec.rb b/spec/ruby/core/proc/clone_spec.rb index 730dc421a8..aee4873e09 100644 --- a/spec/ruby/core/proc/clone_spec.rb +++ b/spec/ruby/core/proc/clone_spec.rb @@ -5,7 +5,7 @@ require_relative 'shared/dup' describe "Proc#clone" do it_behaves_like :proc_dup, :clone - ruby_bug "cloning a frozen proc is broken on Ruby 3.3", "3.3"..."3.4" do + ruby_bug "cloning a frozen proc is broken on Ruby 3.3", ""..."3.4" do it "preserves frozen status" do proc = Proc.new { } proc.freeze @@ -14,17 +14,15 @@ describe "Proc#clone" do end end - ruby_version_is "3.3" do - it "calls #initialize_clone on subclass" do - obj = ProcSpecs::MyProc2.new(:a, 2) { } - dup = obj.clone + it "calls #initialize_clone on subclass" do + obj = ProcSpecs::MyProc2.new(:a, 2) { } + dup = obj.clone - dup.should_not equal(obj) - dup.class.should == ProcSpecs::MyProc2 + dup.should_not.equal?(obj) + dup.class.should == ProcSpecs::MyProc2 - dup.first.should == :a - dup.second.should == 2 - dup.initializer.should == :clone - end + dup.first.should == :a + dup.second.should == 2 + dup.initializer.should == :clone end end diff --git a/spec/ruby/core/proc/curry_spec.rb b/spec/ruby/core/proc/curry_spec.rb index 6daabe0ee1..de13983ca6 100644 --- a/spec/ruby/core/proc/curry_spec.rb +++ b/spec/ruby/core/proc/curry_spec.rb @@ -8,12 +8,12 @@ describe "Proc#curry" do it "returns a Proc when called on a proc" do p = proc { true } - p.curry.should be_an_instance_of(Proc) + p.curry.should.instance_of?(Proc) end it "returns a Proc when called on a lambda" do p = -> { true } - p.curry.should be_an_instance_of(Proc) + p.curry.should.instance_of?(Proc) end it "calls the curried proc with the arguments if sufficient arguments have been given" do @@ -23,11 +23,11 @@ describe "Proc#curry" do it "returns a Proc that consumes the remainder of the arguments unless sufficient arguments have been given" do proc2 = @proc_add.curry[1][2] - proc2.should be_an_instance_of(Proc) + proc2.should.instance_of?(Proc) proc2.call(3).should == 6 lambda2 = @lambda_add.curry[1][2] - lambda2.should be_an_instance_of(Proc) + lambda2.should.instance_of?(Proc) lambda2.call(3).should == 6 @proc_add.curry.call(1,2,3).should == 6 @@ -36,10 +36,10 @@ describe "Proc#curry" do it "can be called multiple times on the same Proc" do @proc_add.curry - -> { @proc_add.curry }.should_not raise_error + -> { @proc_add.curry }.should_not.raise @lambda_add.curry - -> { @lambda_add.curry }.should_not raise_error + -> { @lambda_add.curry }.should_not.raise end it "can be passed superfluous arguments if created from a proc" do @@ -49,8 +49,8 @@ describe "Proc#curry" do end it "raises an ArgumentError if passed superfluous arguments when created from a lambda" do - -> { @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) + -> { @lambda_add.curry[1,2,3,4] }.should.raise(ArgumentError) + -> { @lambda_add.curry[1,2].curry[3,4,5,6] }.should.raise(ArgumentError) end it "returns Procs with arities of -1" do @@ -63,7 +63,7 @@ describe "Proc#curry" do it "produces Procs that raise ArgumentError for #binding" do -> do @proc_add.curry.binding - end.should raise_error(ArgumentError) + end.should.raise(ArgumentError) end it "produces Procs that return [[:rest]] for #parameters" do @@ -98,41 +98,41 @@ describe "Proc#curry with arity argument" do end it "accepts an optional Integer argument for the arity" do - -> { @proc_add.curry(3) }.should_not raise_error - -> { @lambda_add.curry(3) }.should_not raise_error + -> { @proc_add.curry(3) }.should_not.raise + -> { @lambda_add.curry(3) }.should_not.raise end it "returns a Proc when called on a proc" do - @proc_add.curry(3).should be_an_instance_of(Proc) + @proc_add.curry(3).should.instance_of?(Proc) end it "returns a Proc when called on a lambda" do - @lambda_add.curry(3).should be_an_instance_of(Proc) + @lambda_add.curry(3).should.instance_of?(Proc) end # [ruby-core:24127] it "retains the lambda-ness of the Proc on which its called" do - @lambda_add.curry(3).lambda?.should be_true - @proc_add.curry(3).lambda?.should be_false + @lambda_add.curry(3).lambda?.should == true + @proc_add.curry(3).lambda?.should == false end it "raises an ArgumentError if called on a lambda that requires more than _arity_ arguments" do - -> { @lambda_add.curry(2) }.should raise_error(ArgumentError) - -> { -> x, y, z, *more{}.curry(2) }.should raise_error(ArgumentError) + -> { @lambda_add.curry(2) }.should.raise(ArgumentError) + -> { -> x, y, z, *more{}.curry(2) }.should.raise(ArgumentError) end it 'returns a Proc if called on a lambda that requires fewer than _arity_ arguments but may take more' do - -> 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) + -> a, b, c, d=nil, e=nil {}.curry(4).should.instance_of?(Proc) + -> a, b, c, d=nil, *e {}.curry(4).should.instance_of?(Proc) + -> a, b, c, *d {}.curry(4).should.instance_of?(Proc) end it "raises an ArgumentError if called on a lambda that requires fewer than _arity_ arguments" do - -> { @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) + -> { @lambda_add.curry(4) }.should.raise(ArgumentError) + -> { -> { true }.curry(1) }.should.raise(ArgumentError) + -> { -> a, b=nil {}.curry(5) }.should.raise(ArgumentError) + -> { -> a, &b {}.curry(2) }.should.raise(ArgumentError) + -> { -> a, b=nil, &c {}.curry(3) }.should.raise(ArgumentError) end it "calls the curried proc with the arguments if _arity_ arguments have been given" do @@ -142,20 +142,20 @@ describe "Proc#curry with arity argument" do it "returns a Proc that consumes the remainder of the arguments when fewer than _arity_ arguments are given" do proc2 = @proc_add.curry(3)[1][2] - proc2.should be_an_instance_of(Proc) + proc2.should.instance_of?(Proc) proc2.call(3).should == 6 lambda2 = @lambda_add.curry(3)[1][2] - lambda2.should be_an_instance_of(Proc) + lambda2.should.instance_of?(Proc) lambda2.call(3).should == 6 end it "can be specified multiple times on the same Proc" do @proc_add.curry(2) - -> { @proc_add.curry(1) }.should_not raise_error + -> { @proc_add.curry(1) }.should_not.raise @lambda_add.curry(3) - -> { @lambda_add.curry(3) }.should_not raise_error + -> { @lambda_add.curry(3) }.should_not.raise end it "can be passed more than _arity_ arguments if created from a proc" do @@ -165,8 +165,8 @@ describe "Proc#curry with arity argument" do end it "raises an ArgumentError if passed more than _arity_ arguments when created from a lambda" do - -> { @lambda_add.curry(3)[1,2,3,4] }.should raise_error(ArgumentError) - -> { @lambda_add.curry(3)[1,2].curry(3)[3,4,5,6] }.should raise_error(ArgumentError) + -> { @lambda_add.curry(3)[1,2,3,4] }.should.raise(ArgumentError) + -> { @lambda_add.curry(3)[1,2].curry(3)[3,4,5,6] }.should.raise(ArgumentError) end it "returns Procs with arities of -1 regardless of the value of _arity_" do diff --git a/spec/ruby/core/proc/dup_spec.rb b/spec/ruby/core/proc/dup_spec.rb index 716357d1f0..8604389422 100644 --- a/spec/ruby/core/proc/dup_spec.rb +++ b/spec/ruby/core/proc/dup_spec.rb @@ -12,17 +12,15 @@ describe "Proc#dup" do proc.dup.frozen?.should == false end - ruby_version_is "3.3" do - it "calls #initialize_dup on subclass" do - obj = ProcSpecs::MyProc2.new(:a, 2) { } - dup = obj.dup + it "calls #initialize_dup on subclass" do + obj = ProcSpecs::MyProc2.new(:a, 2) { } + dup = obj.dup - dup.should_not equal(obj) - dup.class.should == ProcSpecs::MyProc2 + dup.should_not.equal?(obj) + dup.class.should == ProcSpecs::MyProc2 - dup.first.should == :a - dup.second.should == 2 - dup.initializer.should == :dup - end + dup.first.should == :a + dup.second.should == 2 + dup.initializer.should == :dup end end diff --git a/spec/ruby/core/proc/element_reference_spec.rb b/spec/ruby/core/proc/element_reference_spec.rb index 9077e44c34..ea3a915a11 100644 --- a/spec/ruby/core/proc/element_reference_spec.rb +++ b/spec/ruby/core/proc/element_reference_spec.rb @@ -17,11 +17,11 @@ describe "Proc#call on a Proc created with Kernel#lambda or Kernel#proc" do it_behaves_like :proc_call_on_proc_or_lambda, :call end -describe "Proc#[] with frozen_string_literals" do +describe "Proc#[] with frozen_string_literal: true/false" do it "doesn't duplicate frozen strings" do - ProcArefSpecs.aref.frozen?.should be_false - ProcArefSpecs.aref_freeze.frozen?.should be_true - ProcArefFrozenSpecs.aref.frozen?.should be_true - ProcArefFrozenSpecs.aref_freeze.frozen?.should be_true + ProcArefSpecs.aref.frozen?.should == false + ProcArefSpecs.aref_freeze.frozen?.should == true + ProcArefFrozenSpecs.aref.frozen?.should == true + ProcArefFrozenSpecs.aref_freeze.frozen?.should == true end end diff --git a/spec/ruby/core/proc/hash_spec.rb b/spec/ruby/core/proc/hash_spec.rb index ebe0fde1a0..adcb1ccb78 100644 --- a/spec/ruby/core/proc/hash_spec.rb +++ b/spec/ruby/core/proc/hash_spec.rb @@ -2,12 +2,12 @@ require_relative '../../spec_helper' describe "Proc#hash" do it "is provided" do - proc {}.respond_to?(:hash).should be_true - -> {}.respond_to?(:hash).should be_true + proc {}.respond_to?(:hash).should == true + -> {}.respond_to?(:hash).should == true end it "returns an Integer" do - proc { 1 + 489 }.hash.should be_kind_of(Integer) + proc { 1 + 489 }.hash.should.is_a?(Integer) end it "is stable" do diff --git a/spec/ruby/core/proc/lambda_spec.rb b/spec/ruby/core/proc/lambda_spec.rb index 5c3c38fc2a..1ff6147319 100644 --- a/spec/ruby/core/proc/lambda_spec.rb +++ b/spec/ruby/core/proc/lambda_spec.rb @@ -3,60 +3,53 @@ 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 be_true + -> {}.lambda?.should == true end it "returns false if the Proc was created from a block with the proc keyword" do - proc {}.lambda?.should be_false + proc {}.lambda?.should == false end it "returns false if the Proc was created from a block with Proc.new" do - Proc.new {}.lambda?.should be_false - end - - ruby_version_is ""..."3.3" do - it "is preserved when passing a Proc with & to the lambda keyword" do - suppress_warning {lambda(&->{})}.lambda?.should be_true - suppress_warning {lambda(&proc{})}.lambda?.should be_false - end + Proc.new {}.lambda?.should == false end it "is preserved when passing a Proc with & to the proc keyword" do - proc(&->{}).lambda?.should be_true - proc(&proc{}).lambda?.should be_false + 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 be_true - Proc.new(&proc{}).lambda?.should be_false + 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 be_false + 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 be_true - ProcSpecs.new_proc_from_amp(&proc{}).lambda?.should be_false - ProcSpecs.new_proc_from_amp(&Proc.new{}).lambda?.should be_false + 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 be_true - ProcSpecs.new_proc_from_amp(&m).lambda?.should be_true + 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 be_true - proc{}.curry.lambda?.should be_false - Proc.new{}.curry.lambda?.should be_false + ->{}.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 be_true - proc{|x,y|}.curry.call(42).lambda?.should be_false - Proc.new{|x,y|}.curry.call(42).lambda?.should be_false + -> 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 diff --git a/spec/ruby/core/proc/new_spec.rb b/spec/ruby/core/proc/new_spec.rb index b2b7387756..f0b817f0cb 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() - -> { res.call }.should raise_error(LocalJumpError) + -> { res.call }.should.raise(LocalJumpError) end it "returns from within enclosing method when 'return' is used in the block" do @@ -86,7 +86,7 @@ describe "Proc.new with an associated block" do it "returns a subclass of Proc" do obj = ProcSpecs::MyProc.new { } - obj.should be_kind_of(ProcSpecs::MyProc) + obj.should.is_a?(ProcSpecs::MyProc) end it "calls initialize on the Proc object" do @@ -101,7 +101,7 @@ describe "Proc.new with a block argument" do passed_prc = Proc.new { "hello".size } prc = Proc.new(&passed_prc) - prc.should equal(passed_prc) + prc.should.equal?(passed_prc) prc.call.should == 5 end @@ -110,7 +110,7 @@ describe "Proc.new with a block argument" do passed_prc = Proc.new(&method) prc = Proc.new(&passed_prc) - prc.should equal(passed_prc) + prc.should.equal?(passed_prc) prc.call.should == 5 end @@ -118,7 +118,7 @@ describe "Proc.new with a block argument" do passed_prc = Proc.new(&:size) prc = Proc.new(&passed_prc) - prc.should equal(passed_prc) + prc.should.equal?(passed_prc) prc.call("hello").should == 5 end end @@ -129,7 +129,7 @@ describe "Proc.new with a block argument called indirectly from a subclass" do passed_prc.class.should == ProcSpecs::MyProc prc = ProcSpecs::MyProc.new(&passed_prc) - prc.should equal(passed_prc) + prc.should.equal?(passed_prc) prc.call.should == 5 end @@ -139,7 +139,7 @@ describe "Proc.new with a block argument called indirectly from a subclass" do passed_prc.class.should == ProcSpecs::MyProc prc = ProcSpecs::MyProc.new(&passed_prc) - prc.should equal(passed_prc) + prc.should.equal?(passed_prc) prc.call.should == 5 end @@ -148,22 +148,22 @@ describe "Proc.new with a block argument called indirectly from a subclass" do passed_prc.class.should == ProcSpecs::MyProc prc = ProcSpecs::MyProc.new(&passed_prc) - prc.should equal(passed_prc) + prc.should.equal?(passed_prc) prc.call("hello").should == 5 end end describe "Proc.new without a block" do it "raises an ArgumentError" do - -> { Proc.new }.should raise_error(ArgumentError) + -> { Proc.new }.should.raise(ArgumentError) end it "raises an ArgumentError if invoked from within a method with no block" do - -> { ProcSpecs.new_proc_in_method }.should raise_error(ArgumentError) + -> { ProcSpecs.new_proc_in_method }.should.raise(ArgumentError) end it "raises an ArgumentError if invoked on a subclass from within a method with no block" do - -> { ProcSpecs.new_proc_subclass_in_method }.should raise_error(ArgumentError) + -> { ProcSpecs.new_proc_subclass_in_method }.should.raise(ArgumentError) end it "raises an ArgumentError when passed no block" do @@ -171,8 +171,8 @@ describe "Proc.new without a block" do Proc.new end - -> { ProcSpecs.new_proc_in_method { "hello" } }.should raise_error(ArgumentError, 'tried to create Proc object without a block') - -> { ProcSpecs.new_proc_subclass_in_method { "hello" } }.should raise_error(ArgumentError, 'tried to create Proc object without a block') - -> { some_method { "hello" } }.should raise_error(ArgumentError, 'tried to create Proc object without a block') + -> { ProcSpecs.new_proc_in_method { "hello" } }.should.raise(ArgumentError, 'tried to create Proc object without a block') + -> { ProcSpecs.new_proc_subclass_in_method { "hello" } }.should.raise(ArgumentError, 'tried to create Proc object without a block') + -> { some_method { "hello" } }.should.raise(ArgumentError, 'tried to create Proc object without a block') end end diff --git a/spec/ruby/core/proc/parameters_spec.rb b/spec/ruby/core/proc/parameters_spec.rb index 972596d2ea..ac8c6e3560 100644 --- a/spec/ruby/core/proc/parameters_spec.rb +++ b/spec/ruby/core/proc/parameters_spec.rb @@ -7,8 +7,8 @@ describe "Proc#parameters" do it "returns an Array of Arrays for a proc expecting parameters" do p = proc {|x| } - p.parameters.should be_an_instance_of(Array) - p.parameters.first.should be_an_instance_of(Array) + p.parameters.should.instance_of?(Array) + p.parameters.first.should.instance_of?(Array) end it "sets the first element of each sub-Array to :opt for optional arguments" do @@ -20,29 +20,27 @@ describe "Proc#parameters" do proc {|x| }.parameters.first.first.should == :opt end - ruby_version_is "3.2" do - it "sets the first element of each sub-Array to :req for required argument if lambda keyword used" do - proc {|x| }.parameters(lambda: true).first.first.should == :req - proc {|y,*x| }.parameters(lambda: true).first.first.should == :req - end + it "sets the first element of each sub-Array to :req for required argument if lambda keyword used" do + proc {|x| }.parameters(lambda: true).first.first.should == :req + proc {|y,*x| }.parameters(lambda: true).first.first.should == :req + end - it "regards named parameters in procs as required if lambda keyword used" do - proc {|x| }.parameters(lambda: true).first.first.should == :req - end + it "regards named parameters in procs as required if lambda keyword used" do + proc {|x| }.parameters(lambda: true).first.first.should == :req + end - it "regards named parameters in lambda as optional if lambda: false keyword used" do - -> x { }.parameters(lambda: false).first.first.should == :opt - end + it "regards named parameters in lambda as optional if lambda: false keyword used" do + -> x { }.parameters(lambda: false).first.first.should == :opt + end - it "regards named parameters in procs and lambdas as required if lambda keyword is truthy" do - proc {|x| }.parameters(lambda: 123).first.first.should == :req - -> x { }.parameters(lambda: 123).first.first.should == :req - end + it "regards named parameters in procs and lambdas as required if lambda keyword is truthy" do + proc {|x| }.parameters(lambda: 123).first.first.should == :req + -> x { }.parameters(lambda: 123).first.first.should == :req + end - it "ignores the lambda keyword if it is nil" do - proc {|x|}.parameters(lambda: nil).first.first.should == :opt - -> x { }.parameters(lambda: nil).first.first.should == :req - end + it "ignores the lambda keyword if it is nil" do + proc {|x|}.parameters(lambda: nil).first.first.should == :opt + -> x { }.parameters(lambda: nil).first.first.should == :req end it "regards optional keyword parameters in procs as optional" do @@ -64,7 +62,7 @@ describe "Proc#parameters" do end it "regards keyword parameters in lambdas as required" do - eval("lambda {|x:| }").parameters.first.first.should == :keyreq + -> x: { }.parameters.first.first.should == :keyreq end it "sets the first element of each sub-Array to :rest for parameters prefixed with asterisks" do @@ -110,30 +108,16 @@ describe "Proc#parameters" do -> x { }.parameters.should == [[:req, :x]] end - ruby_version_is '3.2' do - it "adds rest arg with name * for \"star\" argument" do - -> * {}.parameters.should == [[:rest, :*]] - end - - it "adds keyrest arg with ** as a name for \"double star\" argument" do - -> ** {}.parameters.should == [[:keyrest, :**]] - end + it "adds rest arg with name * for \"star\" argument" do + -> * {}.parameters.should == [[:rest, :*]] end - ruby_version_is ''...'3.2' do - it "adds nameless rest arg for \"star\" argument" do - -> * {}.parameters.should == [[:rest]] - end - - it "adds nameless keyrest arg for \"double star\" argument" do - -> ** {}.parameters.should == [[:keyrest]] - end + it "adds keyrest arg with ** as a name for \"double star\" argument" do + -> ** {}.parameters.should == [[:keyrest, :**]] end - ruby_version_is '3.1' do - it "adds block arg with name & for anonymous block argument" do - eval('-> & {}.parameters').should == [[:block, :&]] - end + it "adds block arg with name & for anonymous block argument" do + -> & {}.parameters.should == [[:block, :&]] end it "does not add locals as block options with a block and splat" do @@ -174,4 +158,26 @@ describe "Proc#parameters" do it "returns :nokey for **nil parameter" do proc { |**nil| }.parameters.should == [[:nokey]] end + + ruby_version_is "3.4"..."4.0" do + it "handles the usage of `it` as a parameter" do + eval("proc { it }").parameters.should == [[:opt, nil]] + eval("lambda { it }").parameters.should == [[:req]] + end + end + + ruby_version_is "4.0" do + it "handles the usage of `it` as a parameter" do + eval("proc { it }").parameters.should == [[:opt]] + eval("lambda { it }").parameters.should == [[:req]] + end + end + + ruby_version_is "4.1" do + it "returns :noblock for &nil parameter" do + eval <<~RUBY + proc { |&nil| }.parameters.should == [[:noblock]] + RUBY + end + end end diff --git a/spec/ruby/core/proc/ruby2_keywords_spec.rb b/spec/ruby/core/proc/ruby2_keywords_spec.rb index ab67302231..e06fad8693 100644 --- a/spec/ruby/core/proc/ruby2_keywords_spec.rb +++ b/spec/ruby/core/proc/ruby2_keywords_spec.rb @@ -27,7 +27,7 @@ describe "Proc#ruby2_keywords" do it "returns self" do f = -> *a { } - f.ruby2_keywords.should equal f + f.ruby2_keywords.should.equal? f end it "prints warning when a proc does not accept argument splat" do @@ -39,7 +39,7 @@ describe "Proc#ruby2_keywords" do end it "prints warning when a proc accepts keywords" do - f = -> a:, b: { } + f = -> *a, b: { } -> { f.ruby2_keywords @@ -47,10 +47,20 @@ describe "Proc#ruby2_keywords" do end it "prints warning when a proc accepts keyword splat" do - f = -> **a { } + f = -> *a, **b { } -> { f.ruby2_keywords }.should complain(/Skipping set of ruby2_keywords flag for/) end + + ruby_version_is "4.0" do + it "prints warning when a proc accepts post arguments" do + f = -> *a, b { } + + -> { + f.ruby2_keywords + }.should complain(/Skipping set of ruby2_keywords flag for/) + end + end end diff --git a/spec/ruby/core/proc/shared/call.rb b/spec/ruby/core/proc/shared/call.rb index dbec34df4b..fae2331b68 100644 --- a/spec/ruby/core/proc/shared/call.rb +++ b/spec/ruby/core/proc/shared/call.rb @@ -70,21 +70,21 @@ describe :proc_call_on_proc_or_lambda, shared: true do it "raises an ArgumentError on excess arguments when self is a lambda" do -> { -> x { x }.send(@method, 1, 2) - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError) -> { -> x { x }.send(@method, 1, 2, 3) - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError) end it "raises an ArgumentError on missing arguments when self is a lambda" do -> { -> x { x }.send(@method) - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError) -> { -> x, y { [x,y] }.send(@method, 1) - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError) end it "treats a single Array argument as a single argument when self is a lambda" do diff --git a/spec/ruby/core/proc/shared/compose.rb b/spec/ruby/core/proc/shared/compose.rb index 3d3f3b310d..c004cec7c9 100644 --- a/spec/ruby/core/proc/shared/compose.rb +++ b/spec/ruby/core/proc/shared/compose.rb @@ -5,7 +5,7 @@ describe :proc_compose, shared: true do -> { lhs.send(@method, not_callable) - }.should raise_error(TypeError, "callable object is expected") + }.should.raise(TypeError, "callable object is expected") end @@ -17,6 +17,6 @@ describe :proc_compose, shared: true do -> { lhs.send(@method, succ) - }.should raise_error(TypeError, "callable object is expected") + }.should.raise(TypeError, "callable object is expected") end end diff --git a/spec/ruby/core/proc/shared/dup.rb b/spec/ruby/core/proc/shared/dup.rb index 818f5b858e..2821d2e00f 100644 --- a/spec/ruby/core/proc/shared/dup.rb +++ b/spec/ruby/core/proc/shared/dup.rb @@ -3,17 +3,15 @@ describe :proc_dup, shared: true do a = -> { "hello" } b = a.send(@method) - a.should_not equal(b) + a.should_not.equal?(b) a.call.should == b.call end - ruby_version_is "3.2" do - it "returns an instance of subclass" do - cl = Class.new(Proc) + it "returns an instance of subclass" do + cl = Class.new(Proc) - cl.new{}.send(@method).class.should == cl - end + cl.new{}.send(@method).class.should == cl end ruby_version_is "3.4" do diff --git a/spec/ruby/core/proc/shared/equal.rb b/spec/ruby/core/proc/shared/equal.rb index d0503fb064..4f6f6c41be 100644 --- a/spec/ruby/core/proc/shared/equal.rb +++ b/spec/ruby/core/proc/shared/equal.rb @@ -3,29 +3,29 @@ require_relative '../fixtures/common' describe :proc_equal, shared: true do it "is a public method" do - Proc.should have_public_instance_method(@method, false) + Proc.public_instance_methods(false).should.include?(@method) end it "returns true if self and other are the same object" do p = proc { :foo } - p.send(@method, p).should be_true + p.send(@method, p).should == true p = Proc.new { :foo } - p.send(@method, p).should be_true + p.send(@method, p).should == true p = -> { :foo } - p.send(@method, p).should be_true + p.send(@method, p).should == true end it "returns true if other is a dup of the original" do p = proc { :foo } - p.send(@method, p.dup).should be_true + p.send(@method, p.dup).should == true p = Proc.new { :foo } - p.send(@method, p.dup).should be_true + p.send(@method, p.dup).should == true p = -> { :foo } - p.send(@method, p.dup).should be_true + p.send(@method, p.dup).should == true end # identical here means the same method invocation. @@ -33,51 +33,51 @@ describe :proc_equal, shared: true do a = ProcSpecs.proc_for_1 b = ProcSpecs.proc_for_1 - a.send(@method, b).should be_false + a.send(@method, b).should == false end it "returns false if procs are distinct but have the same body and environment" do p = proc { :foo } p2 = proc { :foo } - p.send(@method, p2).should be_false + p.send(@method, p2).should == false end it "returns false if lambdas are distinct but have same body and environment" do x = -> { :foo } x2 = -> { :foo } - x.send(@method, x2).should be_false + x.send(@method, x2).should == false end it "returns false if using comparing lambda to proc, even with the same body and env" do p = -> { :foo } p2 = proc { :foo } - p.send(@method, p2).should be_false + p.send(@method, p2).should == false x = proc { :bar } x2 = -> { :bar } - x.send(@method, x2).should be_false + x.send(@method, x2).should == false end it "returns false if other is not a Proc" do p = proc { :foo } - p.send(@method, []).should be_false + p.send(@method, []).should == false p = Proc.new { :foo } - p.send(@method, Object.new).should be_false + p.send(@method, Object.new).should == false p = -> { :foo } - p.send(@method, :foo).should be_false + p.send(@method, :foo).should == false end it "returns false if self and other are both procs but have different bodies" do p = proc { :bar } p2 = proc { :foo } - p.send(@method, p2).should be_false + p.send(@method, p2).should == false end it "returns false if self and other are both lambdas but have different bodies" do p = -> { :foo } p2 = -> { :bar } - p.send(@method, p2).should be_false + p.send(@method, p2).should == false end end diff --git a/spec/ruby/core/proc/source_location_spec.rb b/spec/ruby/core/proc/source_location_spec.rb index 484466f577..d27ad0559e 100644 --- a/spec/ruby/core/proc/source_location_spec.rb +++ b/spec/ruby/core/proc/source_location_spec.rb @@ -10,71 +10,64 @@ describe "Proc#source_location" do end it "returns an Array" do - @proc.source_location.should be_an_instance_of(Array) - @proc_new.source_location.should be_an_instance_of(Array) - @lambda.source_location.should be_an_instance_of(Array) - @method.source_location.should be_an_instance_of(Array) + @proc.source_location.should.instance_of?(Array) + @proc_new.source_location.should.instance_of?(Array) + @lambda.source_location.should.instance_of?(Array) + @method.source_location.should.instance_of?(Array) end it "sets the first value to the path of the file in which the proc was defined" do - file = @proc.source_location[0] - file.should be_an_instance_of(String) + file = @proc.source_location.first + file.should.instance_of?(String) file.should == File.realpath('fixtures/source_location.rb', __dir__) - file = @proc_new.source_location[0] - file.should be_an_instance_of(String) + file = @proc_new.source_location.first + file.should.instance_of?(String) file.should == File.realpath('fixtures/source_location.rb', __dir__) - file = @lambda.source_location[0] - file.should be_an_instance_of(String) + file = @lambda.source_location.first + file.should.instance_of?(String) file.should == File.realpath('fixtures/source_location.rb', __dir__) - file = @method.source_location[0] - file.should be_an_instance_of(String) + file = @method.source_location.first + file.should.instance_of?(String) file.should == File.realpath('fixtures/source_location.rb', __dir__) end - it "sets the second value to an Integer representing the line on which the proc was defined" do - line = @proc.source_location[1] - line.should be_an_instance_of(Integer) + it "sets the last value to an Integer representing the line on which the proc was defined" do + line = @proc.source_location.last + line.should.instance_of?(Integer) line.should == 4 - line = @proc_new.source_location[1] - line.should be_an_instance_of(Integer) + line = @proc_new.source_location.last + line.should.instance_of?(Integer) line.should == 12 - line = @lambda.source_location[1] - line.should be_an_instance_of(Integer) + line = @lambda.source_location.last + line.should.instance_of?(Integer) line.should == 8 - line = @method.source_location[1] - line.should be_an_instance_of(Integer) + line = @method.source_location.last + line.should.instance_of?(Integer) line.should == 15 end it "works even if the proc was created on the same line" do - ruby_version_is(""..."3.5") do - proc { true }.source_location.should == [__FILE__, __LINE__] - Proc.new { true }.source_location.should == [__FILE__, __LINE__] - -> { true }.source_location.should == [__FILE__, __LINE__] - end - ruby_version_is("3.5") do - proc { true }.source_location.should == [__FILE__, __LINE__, 11, __LINE__, 19] - Proc.new { true }.source_location.should == [__FILE__, __LINE__, 15, __LINE__, 23] - -> { true }.source_location.should == [__FILE__, __LINE__, 8, __LINE__, 17] - end + proc { true }.source_location.should == [__FILE__, __LINE__] + Proc.new { 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 - ProcSpecs::SourceLocation.my_multiline_proc.source_location[1].should == 20 - ProcSpecs::SourceLocation.my_multiline_proc_new.source_location[1].should == 34 - ProcSpecs::SourceLocation.my_multiline_lambda.source_location[1].should == 27 + ProcSpecs::SourceLocation.my_multiline_proc.source_location.last.should == 20 + ProcSpecs::SourceLocation.my_multiline_proc_new.source_location.last.should == 34 + ProcSpecs::SourceLocation.my_multiline_lambda.source_location.last.should == 27 end it "returns the location of the proc's body; not necessarily the proc itself" do - ProcSpecs::SourceLocation.my_detached_proc.source_location[1].should == 41 - ProcSpecs::SourceLocation.my_detached_proc_new.source_location[1].should == 51 - ProcSpecs::SourceLocation.my_detached_lambda.source_location[1].should == 46 + ProcSpecs::SourceLocation.my_detached_proc.source_location.last.should == 41 + ProcSpecs::SourceLocation.my_detached_proc_new.source_location.last.should == 51 + ProcSpecs::SourceLocation.my_detached_lambda.source_location.last.should == 46 end it "returns the same value for a proc-ified method as the method reports" do @@ -93,12 +86,6 @@ describe "Proc#source_location" do it "works for eval with a given line" do proc = eval('-> {}', nil, "foo", 100) - location = proc.source_location - ruby_version_is(""..."3.5") do - location.should == ["foo", 100] - end - ruby_version_is("3.5") do - location.should == ["foo", 100, 2, 100, 5] - end + proc.source_location.should == ["foo", 100] end end diff --git a/spec/ruby/core/proc/to_proc_spec.rb b/spec/ruby/core/proc/to_proc_spec.rb index ffaa34929b..7f35a4f19b 100644 --- a/spec/ruby/core/proc/to_proc_spec.rb +++ b/spec/ruby/core/proc/to_proc_spec.rb @@ -3,7 +3,7 @@ require_relative '../../spec_helper' describe "Proc#to_proc" do it "returns self" do [Proc.new {}, -> {}, proc {}].each { |p| - p.to_proc.should equal(p) + p.to_proc.should.equal?(p) } end end |
