diff options
author | Andrew Konchin <[email protected]> | 2025-03-26 19:56:40 +0200 |
---|---|---|
committer | Benoit Daloze <[email protected]> | 2025-03-27 11:09:24 +0100 |
commit | bac22c985ecc7e4309b5b5e5ae1074c81319e889 (patch) | |
tree | 5c164d3ed99240737205068f612d47496487758e /spec/ruby/language | |
parent | 53a930f1570c81d2f7829f932e8d7ad67e8462b8 (diff) |
Update to ruby/spec@5e579e2
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/12984
Diffstat (limited to 'spec/ruby/language')
23 files changed, 436 insertions, 438 deletions
diff --git a/spec/ruby/language/assignments_spec.rb b/spec/ruby/language/assignments_spec.rb index 2773508d8d..222d8699c5 100644 --- a/spec/ruby/language/assignments_spec.rb +++ b/spec/ruby/language/assignments_spec.rb @@ -276,117 +276,73 @@ end describe 'Multiple assignments' do describe 'evaluation order' do - ruby_version_is ''...'3.1' do - it 'evaluates expressions right to left when assignment with an accessor' do - object = Object.new - def object.a=(value) end - ScratchPad.record [] - - (ScratchPad << :a; object).a, (ScratchPad << :b; object).a = (ScratchPad << :c; :c), (ScratchPad << :d; :d) - ScratchPad.recorded.should == [:c, :d, :a, :b] - end - - it 'evaluates expressions right to left when assignment with a nested accessor' do - object = Object.new - def object.a=(value) end - ScratchPad.record [] + it 'evaluates expressions left to right when assignment with an accessor' do + object = Object.new + def object.a=(value) end + ScratchPad.record [] - ((ScratchPad << :a; object).a, foo), bar = [(ScratchPad << :b; :b)] - ScratchPad.recorded.should == [:b, :a] - end + (ScratchPad << :a; object).a, (ScratchPad << :b; object).a = (ScratchPad << :c; :c), (ScratchPad << :d; :d) + ScratchPad.recorded.should == [:a, :b, :c, :d] end - ruby_version_is '3.1' do - it 'evaluates expressions left to right when assignment with an accessor' do - object = Object.new - def object.a=(value) end - ScratchPad.record [] - - (ScratchPad << :a; object).a, (ScratchPad << :b; object).a = (ScratchPad << :c; :c), (ScratchPad << :d; :d) - ScratchPad.recorded.should == [:a, :b, :c, :d] - end - - it 'evaluates expressions left to right when assignment with a nested accessor' do - object = Object.new - def object.a=(value) end - ScratchPad.record [] - - ((ScratchPad << :a; object).a, foo), bar = [(ScratchPad << :b; :b)] - ScratchPad.recorded.should == [:a, :b] - end - - it 'evaluates expressions left to right when assignment with a deeply nested accessor' do - o = Object.new - def o.a=(value) end - def o.b=(value) end - def o.c=(value) end - def o.d=(value) end - def o.e=(value) end - def o.f=(value) end - ScratchPad.record [] - - (ScratchPad << :a; o).a, - ((ScratchPad << :b; o).b, - ((ScratchPad << :c; o).c, (ScratchPad << :d; o).d), - (ScratchPad << :e; o).e), - (ScratchPad << :f; o).f = (ScratchPad << :value; :value) + it 'evaluates expressions left to right when assignment with a nested accessor' do + object = Object.new + def object.a=(value) end + ScratchPad.record [] - ScratchPad.recorded.should == [:a, :b, :c, :d, :e, :f, :value] - end + ((ScratchPad << :a; object).a, foo), bar = [(ScratchPad << :b; :b)] + ScratchPad.recorded.should == [:a, :b] end - ruby_version_is ''...'3.1' do - it 'evaluates expressions right to left when assignment with a #[]=' do - object = Object.new - def object.[]=(_, _) end - ScratchPad.record [] - - (ScratchPad << :a; object)[(ScratchPad << :b; :b)], (ScratchPad << :c; object)[(ScratchPad << :d; :d)] = (ScratchPad << :e; :e), (ScratchPad << :f; :f) - ScratchPad.recorded.should == [:e, :f, :a, :b, :c, :d] - end - - it 'evaluates expressions right to left when assignment with a nested #[]=' do - object = Object.new - def object.[]=(_, _) end - ScratchPad.record [] - - ((ScratchPad << :a; object)[(ScratchPad << :b; :b)], foo), bar = [(ScratchPad << :c; :c)] - ScratchPad.recorded.should == [:c, :a, :b] - end + it 'evaluates expressions left to right when assignment with a deeply nested accessor' do + o = Object.new + def o.a=(value) end + def o.b=(value) end + def o.c=(value) end + def o.d=(value) end + def o.e=(value) end + def o.f=(value) end + ScratchPad.record [] + + (ScratchPad << :a; o).a, + ((ScratchPad << :b; o).b, + ((ScratchPad << :c; o).c, (ScratchPad << :d; o).d), + (ScratchPad << :e; o).e), + (ScratchPad << :f; o).f = (ScratchPad << :value; :value) + + ScratchPad.recorded.should == [:a, :b, :c, :d, :e, :f, :value] end - ruby_version_is '3.1' do - it 'evaluates expressions left to right when assignment with a #[]=' do - object = Object.new - def object.[]=(_, _) end - ScratchPad.record [] + it 'evaluates expressions left to right when assignment with a #[]=' do + object = Object.new + def object.[]=(_, _) end + ScratchPad.record [] - (ScratchPad << :a; object)[(ScratchPad << :b; :b)], (ScratchPad << :c; object)[(ScratchPad << :d; :d)] = (ScratchPad << :e; :e), (ScratchPad << :f; :f) - ScratchPad.recorded.should == [:a, :b, :c, :d, :e, :f] - end + (ScratchPad << :a; object)[(ScratchPad << :b; :b)], (ScratchPad << :c; object)[(ScratchPad << :d; :d)] = (ScratchPad << :e; :e), (ScratchPad << :f; :f) + ScratchPad.recorded.should == [:a, :b, :c, :d, :e, :f] + end - it 'evaluates expressions left to right when assignment with a nested #[]=' do - object = Object.new - def object.[]=(_, _) end - ScratchPad.record [] + it 'evaluates expressions left to right when assignment with a nested #[]=' do + object = Object.new + def object.[]=(_, _) end + ScratchPad.record [] - ((ScratchPad << :a; object)[(ScratchPad << :b; :b)], foo), bar = [(ScratchPad << :c; :c)] - ScratchPad.recorded.should == [:a, :b, :c] - end + ((ScratchPad << :a; object)[(ScratchPad << :b; :b)], foo), bar = [(ScratchPad << :c; :c)] + ScratchPad.recorded.should == [:a, :b, :c] + end - it 'evaluates expressions left to right when assignment with a deeply nested #[]=' do - o = Object.new - def o.[]=(_, _) end - ScratchPad.record [] + it 'evaluates expressions left to right when assignment with a deeply nested #[]=' do + o = Object.new + def o.[]=(_, _) end + ScratchPad.record [] - (ScratchPad << :ra; o)[(ScratchPad << :aa; :aa)], - ((ScratchPad << :rb; o)[(ScratchPad << :ab; :ab)], - ((ScratchPad << :rc; o)[(ScratchPad << :ac; :ac)], (ScratchPad << :rd; o)[(ScratchPad << :ad; :ad)]), - (ScratchPad << :re; o)[(ScratchPad << :ae; :ae)]), - (ScratchPad << :rf; o)[(ScratchPad << :af; :af)] = (ScratchPad << :value; :value) + (ScratchPad << :ra; o)[(ScratchPad << :aa; :aa)], + ((ScratchPad << :rb; o)[(ScratchPad << :ab; :ab)], + ((ScratchPad << :rc; o)[(ScratchPad << :ac; :ac)], (ScratchPad << :rd; o)[(ScratchPad << :ad; :ad)]), + (ScratchPad << :re; o)[(ScratchPad << :ae; :ae)]), + (ScratchPad << :rf; o)[(ScratchPad << :af; :af)] = (ScratchPad << :value; :value) - ScratchPad.recorded.should == [:ra, :aa, :rb, :ab, :rc, :ac, :rd, :ad, :re, :ae, :rf, :af, :value] - end + ScratchPad.recorded.should == [:ra, :aa, :rb, :ab, :rc, :ac, :rd, :ad, :re, :ae, :rf, :af, :value] end ruby_version_is ''...'3.2' do diff --git a/spec/ruby/language/block_spec.rb b/spec/ruby/language/block_spec.rb index 75c1e71bc2..1a73b415f2 100644 --- a/spec/ruby/language/block_spec.rb +++ b/spec/ruby/language/block_spec.rb @@ -294,7 +294,7 @@ describe "A block" do end it "may include a rescue clause" do - eval("@y.z do raise ArgumentError; rescue ArgumentError; 7; end").should == 7 + @y.z do raise ArgumentError; rescue ArgumentError; 7; end.should == 7 end end @@ -308,7 +308,7 @@ describe "A block" do end it "may include a rescue clause" do - eval('@y.z do || raise ArgumentError; rescue ArgumentError; 7; end').should == 7 + @y.z do || raise ArgumentError; rescue ArgumentError; 7; end.should == 7 end end @@ -337,7 +337,7 @@ describe "A block" do end it "may include a rescue clause" do - eval('@y.s(1) do |x| raise ArgumentError; rescue ArgumentError; 7; end').should == 7 + @y.s(1) do |x| raise ArgumentError; rescue ArgumentError; 7; end.should == 7 end end @@ -737,9 +737,9 @@ describe "A block" do end it "accepts unnamed arguments" do - eval("lambda { |_,_| }").should be_an_instance_of(Proc) - eval("->(_,_) {}").should be_an_instance_of(Proc) - eval("Proc.new { |_,_| }").should be_an_instance_of(Proc) + lambda { |_,_| }.should be_an_instance_of(Proc) # rubocop:disable Style/Lambda + -> _,_ {}.should be_an_instance_of(Proc) + Proc.new { |_,_| }.should be_an_instance_of(Proc) end end @@ -1001,55 +1001,43 @@ end # tested more thoroughly in language/delegation_spec.rb describe "Anonymous block forwarding" do - ruby_version_is "3.1" do - it "forwards blocks to other method that formally declares anonymous block" do - eval <<-EOF - def b(&); c(&) end - def c(&); yield :non_null end - EOF + it "forwards blocks to other method that formally declares anonymous block" do + def b(&); c(&) end + def c(&); yield :non_null end - b { |c| c }.should == :non_null - end + b { |c| c }.should == :non_null + end - it "requires the anonymous block parameter to be declared if directly passing a block" do - -> { eval "def a; b(&); end; def b; end" }.should raise_error(SyntaxError) - end + it "requires the anonymous block parameter to be declared if directly passing a block" do + -> { eval "def a; b(&); end; def b; end" }.should raise_error(SyntaxError) + end - it "works when it's the only declared parameter" do - eval <<-EOF - def inner; yield end - def block_only(&); inner(&) end - EOF + it "works when it's the only declared parameter" do + def inner; yield end + def block_only(&); inner(&) end - block_only { 1 }.should == 1 - end + block_only { 1 }.should == 1 + end - it "works alongside positional parameters" do - eval <<-EOF - def inner; yield end - def pos(arg1, &); inner(&) end - EOF + it "works alongside positional parameters" do + def inner; yield end + def pos(arg1, &); inner(&) end - pos(:a) { 1 }.should == 1 - end + pos(:a) { 1 }.should == 1 + end - it "works alongside positional arguments and splatted keyword arguments" do - eval <<-EOF - def inner; yield end - def pos_kwrest(arg1, **kw, &); inner(&) end - EOF + it "works alongside positional arguments and splatted keyword arguments" do + def inner; yield end + def pos_kwrest(arg1, **kw, &); inner(&) end - pos_kwrest(:a, arg: 3) { 1 }.should == 1 - end + pos_kwrest(:a, arg: 3) { 1 }.should == 1 + end - it "works alongside positional arguments and disallowed keyword arguments" do - eval <<-EOF - def inner; yield end - def no_kw(arg1, **nil, &); inner(&) end - EOF + it "works alongside positional arguments and disallowed keyword arguments" do + def inner; yield end + def no_kw(arg1, **nil, &); inner(&) end - no_kw(:a) { 1 }.should == 1 - end + no_kw(:a) { 1 }.should == 1 end ruby_version_is "3.2" do diff --git a/spec/ruby/language/class_spec.rb b/spec/ruby/language/class_spec.rb index eab3cd0651..0b770d69b5 100644 --- a/spec/ruby/language/class_spec.rb +++ b/spec/ruby/language/class_spec.rb @@ -271,6 +271,8 @@ describe "A class definition" do AnonWithConstant.name.should == 'AnonWithConstant' klass.get_class_name.should == 'AnonWithConstant' + ensure + Object.send(:remove_const, :AnonWithConstant) end end end diff --git a/spec/ruby/language/constants_spec.rb b/spec/ruby/language/constants_spec.rb index 08c534487e..35913b9e30 100644 --- a/spec/ruby/language/constants_spec.rb +++ b/spec/ruby/language/constants_spec.rb @@ -72,39 +72,60 @@ describe "Literal (A::X) constant resolution" do ConstantSpecs::ModuleA::CS_CONST101 = :const101_5 ConstantSpecs::ModuleA::CS_CONST101.should == :const101_5 + ensure + ConstantSpecs::ClassB.send(:remove_const, :CS_CONST101) + ConstantSpecs::ParentB.send(:remove_const, :CS_CONST101) + ConstantSpecs::ContainerB.send(:remove_const, :CS_CONST101) + ConstantSpecs::ContainerB::ChildB.send(:remove_const, :CS_CONST101) + ConstantSpecs::ModuleA.send(:remove_const, :CS_CONST101) end it "searches a module included in the immediate class before the superclass" do ConstantSpecs::ParentB::CS_CONST102 = :const102_1 ConstantSpecs::ModuleF::CS_CONST102 = :const102_2 ConstantSpecs::ContainerB::ChildB::CS_CONST102.should == :const102_2 + ensure + ConstantSpecs::ParentB.send(:remove_const, :CS_CONST102) + ConstantSpecs::ModuleF.send(:remove_const, :CS_CONST102) end it "searches the superclass before a module included in the superclass" do ConstantSpecs::ModuleE::CS_CONST103 = :const103_1 ConstantSpecs::ParentB::CS_CONST103 = :const103_2 ConstantSpecs::ContainerB::ChildB::CS_CONST103.should == :const103_2 + ensure + ConstantSpecs::ModuleE.send(:remove_const, :CS_CONST103) + ConstantSpecs::ParentB.send(:remove_const, :CS_CONST103) end it "searches a module included in the superclass" do ConstantSpecs::ModuleA::CS_CONST104 = :const104_1 ConstantSpecs::ModuleE::CS_CONST104 = :const104_2 ConstantSpecs::ContainerB::ChildB::CS_CONST104.should == :const104_2 + ensure + ConstantSpecs::ModuleA.send(:remove_const, :CS_CONST104) + ConstantSpecs::ModuleE.send(:remove_const, :CS_CONST104) end it "searches the superclass chain" do ConstantSpecs::ModuleA::CS_CONST105 = :const105 ConstantSpecs::ContainerB::ChildB::CS_CONST105.should == :const105 + ensure + ConstantSpecs::ModuleA.send(:remove_const, :CS_CONST105) end it "searches Object if no class or module qualifier is given" do CS_CONST106 = :const106 CS_CONST106.should == :const106 + ensure + Object.send(:remove_const, :CS_CONST106) end it "searches Object if a toplevel qualifier (::X) is given" do ::CS_CONST107 = :const107 ::CS_CONST107.should == :const107 + ensure + Object.send(:remove_const, :CS_CONST107) end it "does not search the singleton class of the class or module" do @@ -123,6 +144,9 @@ describe "Literal (A::X) constant resolution" do end -> { ConstantSpecs::CS_CONST108 }.should raise_error(NameError) + ensure + ConstantSpecs::ContainerB::ChildB.singleton_class.send(:remove_const, :CS_CONST108) + ConstantSpecs.singleton_class.send(:remove_const, :CS_CONST108) end it "returns the updated value when a constant is reassigned" do @@ -133,6 +157,8 @@ describe "Literal (A::X) constant resolution" do ConstantSpecs::ClassB::CS_CONST109 = :const109_2 }.should complain(/already initialized constant/) ConstantSpecs::ClassB::CS_CONST109.should == :const109_2 + ensure + ConstantSpecs::ClassB.send(:remove_const, :CS_CONST109) end ruby_version_is "3.2" do @@ -292,6 +318,12 @@ describe "Constant resolution within methods" do ConstantSpecs::ClassB.new.const201.should == :const201_2 ConstantSpecs::ParentB.new.const201.should == :const201_3 ConstantSpecs::ContainerB::ChildB.new.const201.should == :const201_5 + ensure + ConstantSpecs::ModuleA.send(:remove_const, :CS_CONST201) + ConstantSpecs::ClassB.send(:remove_const, :CS_CONST201) + ConstantSpecs::ParentB.send(:remove_const, :CS_CONST201) + ConstantSpecs::ContainerB.send(:remove_const, :CS_CONST201) + ConstantSpecs::ContainerB::ChildB.send(:remove_const, :CS_CONST201) end it "searches a module included in the immediate class before the superclass" do @@ -300,6 +332,9 @@ describe "Constant resolution within methods" do ConstantSpecs::ContainerB::ChildB.const202.should == :const202_1 ConstantSpecs::ContainerB::ChildB.new.const202.should == :const202_1 + ensure + ConstantSpecs::ParentB.send(:remove_const, :CS_CONST202) + ConstantSpecs::ContainerB::ChildB.send(:remove_const, :CS_CONST202) end it "searches the superclass before a module included in the superclass" do @@ -308,6 +343,9 @@ describe "Constant resolution within methods" do ConstantSpecs::ContainerB::ChildB.const203.should == :const203_1 ConstantSpecs::ContainerB::ChildB.new.const203.should == :const203_1 + ensure + ConstantSpecs::ParentB.send(:remove_const, :CS_CONST203) + ConstantSpecs::ModuleE.send(:remove_const, :CS_CONST203) end it "searches a module included in the superclass" do @@ -316,6 +354,9 @@ describe "Constant resolution within methods" do ConstantSpecs::ContainerB::ChildB.const204.should == :const204_1 ConstantSpecs::ContainerB::ChildB.new.const204.should == :const204_1 + ensure + ConstantSpecs::ModuleA.send(:remove_const, :CS_CONST204) + ConstantSpecs::ModuleE.send(:remove_const, :CS_CONST204) end it "searches the superclass chain" do @@ -323,6 +364,8 @@ describe "Constant resolution within methods" do ConstantSpecs::ContainerB::ChildB.const205.should == :const205 ConstantSpecs::ContainerB::ChildB.new.const205.should == :const205 + ensure + ConstantSpecs::ModuleA.send(:remove_const, :CS_CONST205) end it "searches the lexical scope of the method not the receiver's immediate class" do @@ -334,6 +377,9 @@ describe "Constant resolution within methods" do end ConstantSpecs::ContainerB::ChildB.const206.should == :const206_1 + ensure + ConstantSpecs::ContainerB::ChildB.send(:remove_const, :CS_CONST206) + ConstantSpecs::ContainerB::ChildB.singleton_class.send(:remove_const, :CS_CONST206) end it "searches the lexical scope of a singleton method" do @@ -341,12 +387,17 @@ describe "Constant resolution within methods" do ConstantSpecs::ClassB::CS_CONST207 = :const207_2 ConstantSpecs::CS_CONST208.const207.should == :const207_1 + ensure + ConstantSpecs.send(:remove_const, :CS_CONST207) + ConstantSpecs::ClassB.send(:remove_const, :CS_CONST207) end it "does not search the lexical scope of the caller" do ConstantSpecs::ClassB::CS_CONST209 = :const209 -> { ConstantSpecs::ClassB.const209 }.should raise_error(NameError) + ensure + ConstantSpecs::ClassB.send(:remove_const, :CS_CONST209) end it "searches the lexical scope of a block" do @@ -354,6 +405,9 @@ describe "Constant resolution within methods" do ConstantSpecs::ParentB::CS_CONST210 = :const210_2 ConstantSpecs::ClassB.const210.should == :const210_1 + ensure + ConstantSpecs::ClassB.send(:remove_const, :CS_CONST210) + ConstantSpecs::ParentB.send(:remove_const, :CS_CONST210) end it "searches Object as a lexical scope only if Object is explicitly opened" do @@ -364,6 +418,11 @@ describe "Constant resolution within methods" do Object::CS_CONST212 = :const212_2 ConstantSpecs::ParentB::CS_CONST212 = :const212_1 ConstantSpecs::ContainerB::ChildB.const212.should == :const212_1 + ensure + Object.send(:remove_const, :CS_CONST211) + ConstantSpecs::ParentB.send(:remove_const, :CS_CONST211) + Object.send(:remove_const, :CS_CONST212) + ConstantSpecs::ParentB.send(:remove_const, :CS_CONST212) end it "returns the updated value when a constant is reassigned" do @@ -376,6 +435,8 @@ describe "Constant resolution within methods" do }.should complain(/already initialized constant/) ConstantSpecs::ContainerB::ChildB.const213.should == :const213_2 ConstantSpecs::ContainerB::ChildB.new.const213.should == :const213_2 + ensure + ConstantSpecs::ParentB.send(:remove_const, :CS_CONST213) end it "does not search the lexical scope of qualifying modules" do @@ -384,6 +445,8 @@ describe "Constant resolution within methods" do -> do ConstantSpecs::ContainerB::ChildB.const214 end.should raise_error(NameError) + ensure + ConstantSpecs::ContainerB.send(:remove_const, :CS_CONST214) end end @@ -484,6 +547,10 @@ describe "Module#private_constant marked constants" do PrivateModule::X.should == 1 end + ensure + module ::ConstantVisibility::ModuleContainer + PrivateModule.send(:remove_const, :X) + end end it "can be reopened as a class where constant is not private" do @@ -494,6 +561,10 @@ describe "Module#private_constant marked constants" do PrivateClass::X.should == 1 end + ensure + module ::ConstantVisibility::ModuleContainer + PrivateClass.send(:remove_const, :X) + end end it "is not defined? with A::B form" do @@ -565,6 +636,10 @@ describe "Module#private_constant marked constants" do PrivateModule::X.should == 1 end + ensure + class ::ConstantVisibility::ClassContainer + PrivateModule.send(:remove_const, :X) + end end it "can be reopened as a class where constant is not private" do @@ -575,6 +650,10 @@ describe "Module#private_constant marked constants" do PrivateClass::X.should == 1 end + ensure + class ::ConstantVisibility::ClassContainer + PrivateClass.send(:remove_const, :X) + end end it "is not defined? with A::B form" do diff --git a/spec/ruby/language/def_spec.rb b/spec/ruby/language/def_spec.rb index ce8077eb69..eb44331bb5 100644 --- a/spec/ruby/language/def_spec.rb +++ b/spec/ruby/language/def_spec.rb @@ -524,6 +524,8 @@ describe "A nested method definition" do obj = DefSpecNested.new obj.inherited_method.should == obj + ensure + DefSpecNested.send(:remove_const, :TARGET) end # See http://yugui.jp/articles/846#label-3 @@ -545,6 +547,8 @@ describe "A nested method definition" do DefSpecNested.should_not have_instance_method :arg_method DefSpecNested.should_not have_instance_method :body_method + ensure + DefSpecNested.send(:remove_const, :OBJ) end it "creates an instance method inside Class.new" do diff --git a/spec/ruby/language/delegation_spec.rb b/spec/ruby/language/delegation_spec.rb index b75f3f5f7c..0fcd3e57bf 100644 --- a/spec/ruby/language/delegation_spec.rb +++ b/spec/ruby/language/delegation_spec.rb @@ -137,27 +137,25 @@ ruby_version_is "3.2" do end end -ruby_version_is "3.1" do - describe "delegation with def(&)" do - it "delegates an anonymous block parameter" do - a = Class.new(DelegationSpecs::Target) - a.class_eval(<<-RUBY) - def delegate(&) - target(&) - end - RUBY - - block = proc {} - a.new.delegate(&block).should == [[], {}, block] +describe "delegation with def(&)" do + it "delegates an anonymous block parameter" do + a = Class.new(DelegationSpecs::Target) + a.class_eval(<<-RUBY) + def delegate(&) + target(&) end + RUBY - ruby_version_is "3.3" do - context "within a block that accepts anonymous block within a method that accepts anonymous block" do - it "does not allow delegating a block" do - -> { - eval "def m(&); proc { |&| n(&) } end" - }.should raise_error(SyntaxError, /anonymous block parameter is also used within block/) - end + block = proc {} + a.new.delegate(&block).should == [[], {}, block] + end + + ruby_version_is "3.3" do + context "within a block that accepts anonymous block within a method that accepts anonymous block" do + it "does not allow delegating a block" do + -> { + eval "def m(&); proc { |&| n(&) } end" + }.should raise_error(SyntaxError, /anonymous block parameter is also used within block/) end end end diff --git a/spec/ruby/language/ensure_spec.rb b/spec/ruby/language/ensure_spec.rb index 16e626b4d0..b76292c007 100644 --- a/spec/ruby/language/ensure_spec.rb +++ b/spec/ruby/language/ensure_spec.rb @@ -339,10 +339,8 @@ describe "An ensure block inside 'do end' block" do end end line = __LINE__ - foo.should == [ - "#{__FILE__}:#{line-3}:in 'foo'", - "#{__FILE__}:#{line+1}:in 'block (3 levels) in <top (required)>'" - ] + foo[0].should =~ /#{__FILE__}:#{line-3}:in 'foo'/ + foo[1].should =~ /#{__FILE__}:#{line+2}:in 'block/ end end end diff --git a/spec/ruby/language/hash_spec.rb b/spec/ruby/language/hash_spec.rb index 068ac0f39c..b119b6ca73 100644 --- a/spec/ruby/language/hash_spec.rb +++ b/spec/ruby/language/hash_spec.rb @@ -60,14 +60,12 @@ describe "Hash literal" do @h.should == {1000 => :foo} end - ruby_version_is "3.1" do - it "checks duplicated float keys on initialization" do - -> { - @h = eval "{1.0 => :bar, 1.0 => :foo}" - }.should complain(/key 1.0 is duplicated|duplicated key/) - @h.keys.size.should == 1 - @h.should == {1.0 => :foo} - end + it "checks duplicated float keys on initialization" do + -> { + @h = eval "{1.0 => :bar, 1.0 => :foo}" + }.should complain(/key 1.0 is duplicated|duplicated key/) + @h.keys.size.should == 1 + @h.should == {1.0 => :foo} end it "accepts a hanging comma" do @@ -77,9 +75,9 @@ describe "Hash literal" do end it "recognizes '=' at the end of the key" do - eval("{:a==>1}").should == {:"a=" => 1} - eval("{:a= =>1}").should == {:"a=" => 1} - eval("{:a= => 1}").should == {:"a=" => 1} + {:a==>1}.should == {:"a=" => 1} + {:a= =>1}.should == {:"a=" => 1} + {:a= => 1}.should == {:"a=" => 1} end it "with '==>' in the middle raises SyntaxError" do @@ -87,11 +85,11 @@ describe "Hash literal" do end it "recognizes '!' at the end of the key" do - eval("{:a! =>1}").should == {:"a!" => 1} - eval("{:a! => 1}").should == {:"a!" => 1} + {:a! =>1}.should == {:"a!" => 1} + {:a! => 1}.should == {:"a!" => 1} - eval("{a!:1}").should == {:"a!" => 1} - eval("{a!: 1}").should == {:"a!" => 1} + {a!:1}.should == {:"a!" => 1} + {a!: 1}.should == {:"a!" => 1} end it "raises a SyntaxError if there is no space between `!` and `=>`" do @@ -99,11 +97,11 @@ describe "Hash literal" do end it "recognizes '?' at the end of the key" do - eval("{:a? =>1}").should == {:"a?" => 1} - eval("{:a? => 1}").should == {:"a?" => 1} + {:a? =>1}.should == {:"a?" => 1} + {:a? => 1}.should == {:"a?" => 1} - eval("{a?:1}").should == {:"a?" => 1} - eval("{a?: 1}").should == {:"a?" => 1} + {a?:1}.should == {:"a?" => 1} + {a?: 1}.should == {:"a?" => 1} end it "raises a SyntaxError if there is no space between `?` and `=>`" do @@ -129,7 +127,7 @@ describe "Hash literal" do it "accepts mixed 'key: value', 'key => value' and '\"key\"': value' syntax" do h = {:a => 1, :b => 2, "c" => 3, :d => 4} - eval('{a: 1, :b => 2, "c" => 3, "d": 4}').should == h + {a: 1, :b => 2, "c" => 3, "d": 4}.should == h end it "expands an '**{}' element into the containing Hash literal initialization" do @@ -259,50 +257,48 @@ describe "The ** operator" do end end - ruby_version_is "3.1" do - describe "hash with omitted value" do - it "accepts short notation 'key' for 'key: value' syntax" do - a, b, c = 1, 2, 3 - h = eval('{a:}') - {a: 1}.should == h - h = eval('{a:, b:, c:}') - {a: 1, b: 2, c: 3}.should == h - end + describe "hash with omitted value" do + it "accepts short notation 'key' for 'key: value' syntax" do + a, b, c = 1, 2, 3 + h = {a:} + {a: 1}.should == h + h = {a:, b:, c:} + {a: 1, b: 2, c: 3}.should == h + end - it "ignores hanging comma on short notation" do - a, b, c = 1, 2, 3 - h = eval('{a:, b:, c:,}') - {a: 1, b: 2, c: 3}.should == h - end + it "ignores hanging comma on short notation" do + a, b, c = 1, 2, 3 + h = {a:, b:, c:,} + {a: 1, b: 2, c: 3}.should == h + end - it "accepts mixed syntax" do - a, e = 1, 5 - h = eval('{a:, b: 2, "c" => 3, :d => 4, e:}') - eval('{a: 1, :b => 2, "c" => 3, "d": 4, e: 5}').should == h - end + it "accepts mixed syntax" do + a, e = 1, 5 + h = {a:, b: 2, "c" => 3, :d => 4, e:} + {a: 1, :b => 2, "c" => 3, "d": 4, e: 5}.should == h + end - it "works with methods and local vars" do - a = Class.new - a.class_eval(<<-RUBY) - def bar - "baz" - end + it "works with methods and local vars" do + a = Class.new + a.class_eval(<<-RUBY) + def bar + "baz" + end - def foo(val) - {bar:, val:} - end - RUBY + def foo(val) + {bar:, val:} + end + RUBY - a.new.foo(1).should == {bar: "baz", val: 1} - end + a.new.foo(1).should == {bar: "baz", val: 1} + end - it "raises a SyntaxError when the hash key ends with `!`" do - -> { eval("{a!:}") }.should raise_error(SyntaxError, /identifier a! is not valid to get/) - end + it "raises a SyntaxError when the hash key ends with `!`" do + -> { eval("{a!:}") }.should raise_error(SyntaxError, /identifier a! is not valid to get/) + end - it "raises a SyntaxError when the hash key ends with `?`" do - -> { eval("{a?:}") }.should raise_error(SyntaxError, /identifier a\? is not valid to get/) - end + it "raises a SyntaxError when the hash key ends with `?`" do + -> { eval("{a?:}") }.should raise_error(SyntaxError, /identifier a\? is not valid to get/) end end end diff --git a/spec/ruby/language/keyword_arguments_spec.rb b/spec/ruby/language/keyword_arguments_spec.rb index 8668799d26..3f8ddfa40d 100644 --- a/spec/ruby/language/keyword_arguments_spec.rb +++ b/spec/ruby/language/keyword_arguments_spec.rb @@ -323,18 +323,16 @@ describe "Keyword arguments" do m({a: 1}).should == [[{a: 1}], {}] end - ruby_version_is "3.1" do - describe "omitted values" do - it "accepts short notation 'key' for 'key: value' syntax" do - def m(a:, b:) - [a, b] - end + describe "omitted values" do + it "accepts short notation 'key' for 'key: value' syntax" do + def m(a:, b:) + [a, b] + end - a = 1 - b = 2 + a = 1 + b = 2 - eval('m(a:, b:).should == [1, 2]') - end + m(a:, b:).should == [1, 2] end end diff --git a/spec/ruby/language/method_spec.rb b/spec/ruby/language/method_spec.rb index 9abe4cde20..b0d7058dbe 100644 --- a/spec/ruby/language/method_spec.rb +++ b/spec/ruby/language/method_spec.rb @@ -1416,53 +1416,49 @@ describe "Keyword arguments are now separated from positional arguments" do end end -ruby_version_is "3.1" do - describe "kwarg with omitted value in a method call" do - context "accepts short notation 'kwarg' in method call" do - evaluate <<-ruby do - def call(*args, **kwargs) = [args, kwargs] - ruby +describe "kwarg with omitted value in a method call" do + context "accepts short notation 'kwarg' in method call" do + evaluate <<-ruby do + def call(*args, **kwargs) = [args, kwargs] + ruby - a, b, c = 1, 2, 3 - arr, h = eval('call a:') - h.should == {a: 1} - arr.should == [] + a, b, c = 1, 2, 3 + arr, h = call(a:) + h.should == {a: 1} + arr.should == [] - arr, h = eval('call(a:, b:, c:)') - h.should == {a: 1, b: 2, c: 3} - arr.should == [] + arr, h = call(a:, b:, c:) + h.should == {a: 1, b: 2, c: 3} + arr.should == [] - arr, h = eval('call(a:, b: 10, c:)') - h.should == {a: 1, b: 10, c: 3} - arr.should == [] - end + arr, h = call(a:, b: 10, c:) + h.should == {a: 1, b: 10, c: 3} + arr.should == [] end + end - context "with methods and local variables" do - evaluate <<-ruby do - def call(*args, **kwargs) = [args, kwargs] + context "with methods and local variables" do + evaluate <<-ruby do + def call(*args, **kwargs) = [args, kwargs] - def bar - "baz" - end + def bar + "baz" + end - def foo(val) - call bar:, val: - end - ruby + def foo(val) + call bar:, val: + end + ruby - foo(1).should == [[], {bar: "baz", val: 1}] - end + foo(1).should == [[], {bar: "baz", val: 1}] end end +end - describe "Inside 'endless' method definitions" do - it "allows method calls without parenthesis" do - eval <<-ruby - def greet(person) = "Hi, ".dup.concat person - ruby +describe "Inside 'endless' method definitions" do + it "allows method calls without parenthesis" do + def greet(person) = "Hi, ".dup.concat person - greet("Homer").should == "Hi, Homer" - end + greet("Homer").should == "Hi, Homer" end end diff --git a/spec/ruby/language/module_spec.rb b/spec/ruby/language/module_spec.rb index fffcf9c90d..0bfd148868 100644 --- a/spec/ruby/language/module_spec.rb +++ b/spec/ruby/language/module_spec.rb @@ -26,12 +26,16 @@ describe "The module keyword" do it "reopens an existing module" do module ModuleSpecs; Reopened = true; end ModuleSpecs::Reopened.should be_true + ensure + ModuleSpecs.send(:remove_const, :Reopened) end ruby_version_is '3.2' do it "does not reopen a module included in Object" do module IncludedModuleSpecs; Reopened = true; end ModuleSpecs::IncludedInObject::IncludedModuleSpecs.should_not == Object::IncludedModuleSpecs + ensure + IncludedModuleSpecs.send(:remove_const, :Reopened) end end @@ -76,6 +80,8 @@ describe "Assigning an anonymous module to a constant" do ::ModuleSpecs_CS1 = mod mod.name.should == "ModuleSpecs_CS1" + ensure + Object.send(:remove_const, :ModuleSpecs_CS1) end it "sets the name of a module scoped by an anonymous module" do @@ -96,5 +102,7 @@ describe "Assigning an anonymous module to a constant" do b.name.should == "ModuleSpecs_CS2::B" c.name.should == "ModuleSpecs_CS2::B::C" d.name.should == "ModuleSpecs_CS2::D" + ensure + Object.send(:remove_const, :ModuleSpecs_CS2) end end diff --git a/spec/ruby/language/optional_assignments_spec.rb b/spec/ruby/language/optional_assignments_spec.rb index 2443cc6b79..5fe3e3671b 100644 --- a/spec/ruby/language/optional_assignments_spec.rb +++ b/spec/ruby/language/optional_assignments_spec.rb @@ -698,6 +698,8 @@ describe 'Optional constant assignment' do x.should == 1 y.should == 0 ConstantSpecs::ClassA::NIL_OR_ASSIGNED_CONSTANT3.should == nil + ensure + ConstantSpecs::ClassA.send(:remove_const, :NIL_OR_ASSIGNED_CONSTANT3) end end diff --git a/spec/ruby/language/pattern_matching/3.1.rb b/spec/ruby/language/pattern_matching/3.1.rb deleted file mode 100644 index 7a09084e41..0000000000 --- a/spec/ruby/language/pattern_matching/3.1.rb +++ /dev/null @@ -1,75 +0,0 @@ -describe "Pattern matching" do - before :each do - ScratchPad.record [] - end - - describe "Ruby 3.1 improvements" do - ruby_version_is "3.1" do - it "can omit parentheses in one line pattern matching" do - [1, 2] => a, b - [a, b].should == [1, 2] - - {a: 1} => a: - a.should == 1 - end - - it "supports pinning instance variables" do - @a = /a/ - case 'abc' - in ^@a - true - end.should == true - end - - it "supports pinning class variables" do - result = nil - Module.new do - result = module_eval(<<~RUBY) - @@a = 0..10 - - case 2 - in ^@@a - true - end - RUBY - end - - result.should == true - end - - it "supports pinning global variables" do - $a = /a/ - case 'abc' - in ^$a - true - end.should == true - end - - it "supports pinning expressions" do - case 'abc' - in ^(/a/) - true - end.should == true - - case 0 - in ^(0 + 0) - true - end.should == true - end - - it "supports pinning expressions in array pattern" do - case [3] - in [^(1 + 2)] - true - end.should == true - end - - it "supports pinning expressions in hash pattern" do - case {name: '2.6', released_at: Time.new(2018, 12, 25)} - in {released_at: ^(Time.new(2010)..Time.new(2020))} - true - end.should == true - end - end - end -end diff --git a/spec/ruby/language/pattern_matching_spec.rb b/spec/ruby/language/pattern_matching_spec.rb index 94432b1fa0..cb4f5864d7 100644 --- a/spec/ruby/language/pattern_matching_spec.rb +++ b/spec/ruby/language/pattern_matching_spec.rb @@ -164,16 +164,8 @@ describe "Pattern matching" do @src = '[0, 1] => [a, b]' end - ruby_version_is ""..."3.1" do - it "warns about pattern matching is experimental feature" do - -> { eval @src }.should complain(/pattern matching is experimental, and the behavior may change in future versions of Ruby!/i) - end - end - - ruby_version_is "3.1" do - it "does not warn about pattern matching is experimental feature" do - -> { eval @src }.should_not complain - end + it "does not warn about pattern matching is experimental feature" do + -> { eval @src }.should_not complain end end end @@ -1220,8 +1212,99 @@ describe "Pattern matching" do result.should == true end end -end -ruby_version_is "3.1" do - require_relative 'pattern_matching/3.1' + describe "Ruby 3.1 improvements" do + it "can omit parentheses in one line pattern matching" do + [1, 2] => a, b + [a, b].should == [1, 2] + + {a: 1} => a: + a.should == 1 + end + + it "supports pinning instance variables" do + @a = /a/ + case 'abc' + in ^@a + true + end.should == true + end + + it "supports pinning class variables" do + result = nil + Module.new do + # avoid "class variable access from toplevel" runtime error with #module_eval + result = module_eval(<<~RUBY) + @@a = 0..10 + + case 2 + in ^@@a + true + end + RUBY + end + + result.should == true + end + + it "supports pinning global variables" do + $a = /a/ + case 'abc' + in ^$a + true + end.should == true + end + + it "supports pinning expressions" do + case 'abc' + in ^(/a/) + true + end.should == true + + case 0 + in ^(0 + 0) + true + end.should == true + end + + it "supports pinning expressions in array pattern" do + case [3] + in [^(1 + 2)] + true + end.should == true + end + + it "supports pinning expressions in hash pattern" do + case {name: '2.6', released_at: Time.new(2018, 12, 25)} + in {released_at: ^(Time.new(2010)..Time.new(2020))} + true + end.should == true + end + end + + describe "value in pattern" do + it "returns true if the pattern matches" do + (1 in 1).should == true + + (1 in Integer).should == true + + e = nil + ([1, 2] in [1, e]).should == true + e.should == 2 + + k = nil + ({k: 1} in {k:}).should == true + k.should == 1 + end + + it "returns false if the pattern does not match" do + (1 in 2).should == false + + (1 in Float).should == false + + ([1, 2] in [2, e]).should == false + + ({k: 1} in {k: 2}).should == false + end + end end diff --git a/spec/ruby/language/predefined_spec.rb b/spec/ruby/language/predefined_spec.rb index cc231e341e..9338a04715 100644 --- a/spec/ruby/language/predefined_spec.rb +++ b/spec/ruby/language/predefined_spec.rb @@ -71,7 +71,7 @@ describe "Predefined global $~" do match2.should_not == nil $~.should == match2 - eval 'match3 = /baz/.match("baz")' + match3 = /baz/.match("baz") match3.should_not == nil $~.should == match3 @@ -768,7 +768,7 @@ describe "Predefined global $_" do match.should == "bar\n" $_.should == match - eval 'match = stdin.gets' + match = stdin.gets match.should == "baz\n" $_.should == match @@ -1341,16 +1341,8 @@ describe "$LOAD_PATH.resolve_feature_path" do path.should.end_with?("/etc.#{RbConfig::CONFIG['DLEXT']}") end - ruby_version_is ""..."3.1" do - it "raises LoadError if feature cannot be found" do - -> { $LOAD_PATH.resolve_feature_path('noop') }.should raise_error(LoadError) - end - end - - ruby_version_is "3.1" do - it "return nil if feature cannot be found" do - $LOAD_PATH.resolve_feature_path('noop').should be_nil - end + it "return nil if feature cannot be found" do + $LOAD_PATH.resolve_feature_path('noop').should be_nil end end diff --git a/spec/ruby/language/private_spec.rb b/spec/ruby/language/private_spec.rb index ddf185e6d2..b04aa25c9e 100644 --- a/spec/ruby/language/private_spec.rb +++ b/spec/ruby/language/private_spec.rb @@ -34,7 +34,7 @@ describe "The private keyword" do it "changes visibility of previously called method" do klass = Class.new do def foo - "foo" + "foo" end end f = klass.new diff --git a/spec/ruby/language/proc_spec.rb b/spec/ruby/language/proc_spec.rb index cc69b7799c..ca9a13aa61 100644 --- a/spec/ruby/language/proc_spec.rb +++ b/spec/ruby/language/proc_spec.rb @@ -104,7 +104,7 @@ describe "A Proc" do end it "assigns all passed values after the first to the rest argument" do - @l.call(1, 2, 3).should == [1, [2, 3]] + @l.call(1, 2, 3).should == [1, [2, 3]] end it "does not call #to_ary to convert a single passed object to an Array" do diff --git a/spec/ruby/language/regexp/anchors_spec.rb b/spec/ruby/language/regexp/anchors_spec.rb index 0129e255da..cdc06c0b4d 100644 --- a/spec/ruby/language/regexp/anchors_spec.rb +++ b/spec/ruby/language/regexp/anchors_spec.rb @@ -124,10 +124,10 @@ describe "Regexps with anchors" do /foo\b/.match("foo").to_a.should == ["foo"] /foo\b/.match("foo\n").to_a.should == ["foo"] LanguageSpecs.white_spaces.scan(/./).each do |c| - /foo\b/.match("foo" + c).to_a.should == ["foo"] + /foo\b/.match("foo" + c).to_a.should == ["foo"] end LanguageSpecs.non_alphanum_non_space.scan(/./).each do |c| - /foo\b/.match("foo" + c).to_a.should == ["foo"] + /foo\b/.match("foo" + c).to_a.should == ["foo"] end /foo\b/.match("foo\0").to_a.should == ["foo"] # Basic non-matching @@ -145,10 +145,10 @@ describe "Regexps with anchors" do /foo\B/.match("foo").should be_nil /foo\B/.match("foo\n").should be_nil LanguageSpecs.white_spaces.scan(/./).each do |c| - /foo\B/.match("foo" + c).should be_nil + /foo\B/.match("foo" + c).should be_nil end LanguageSpecs.non_alphanum_non_space.scan(/./).each do |c| - /foo\B/.match("foo" + c).should be_nil + /foo\B/.match("foo" + c).should be_nil end /foo\B/.match("foo\0").should be_nil end diff --git a/spec/ruby/language/regexp/character_classes_spec.rb b/spec/ruby/language/regexp/character_classes_spec.rb index 98d431a817..8e9a0b960b 100644 --- a/spec/ruby/language/regexp/character_classes_spec.rb +++ b/spec/ruby/language/regexp/character_classes_spec.rb @@ -226,7 +226,7 @@ describe "Regexp with character classes" do end it "matches Unicode letter characters with [[:graph:]]" do - "à".match(/[[:graph:]]/).to_a.should == ["à"] + "à".match(/[[:graph:]]/).to_a.should == ["à"] end it "matches Unicode digits with [[:graph:]]" do diff --git a/spec/ruby/language/regexp/grouping_spec.rb b/spec/ruby/language/regexp/grouping_spec.rb index 2f04a04018..313858f714 100644 --- a/spec/ruby/language/regexp/grouping_spec.rb +++ b/spec/ruby/language/regexp/grouping_spec.rb @@ -12,7 +12,7 @@ describe "Regexps with grouping" do end it "raises a SyntaxError when parentheses aren't balanced" do - -> { eval "/(hay(st)ack/" }.should raise_error(SyntaxError) + -> { eval "/(hay(st)ack/" }.should raise_error(SyntaxError) end it "supports (?: ) (non-capturing group)" do diff --git a/spec/ruby/language/rescue_spec.rb b/spec/ruby/language/rescue_spec.rb index 4dc25a5b45..79571d689f 100644 --- a/spec/ruby/language/rescue_spec.rb +++ b/spec/ruby/language/rescue_spec.rb @@ -573,10 +573,8 @@ describe "The rescue keyword" do end end line = __LINE__ - foo.should == [ - "#{__FILE__}:#{line-3}:in 'foo'", - "#{__FILE__}:#{line+1}:in 'block (3 levels) in <top (required)>'" - ] + foo[0].should =~ /#{__FILE__}:#{line-3}:in 'foo'/ + foo[1].should =~ /#{__FILE__}:#{line+2}:in 'block/ end end diff --git a/spec/ruby/language/undef_spec.rb b/spec/ruby/language/undef_spec.rb index 29dba4afb4..268c0b84c3 100644 --- a/spec/ruby/language/undef_spec.rb +++ b/spec/ruby/language/undef_spec.rb @@ -69,7 +69,7 @@ describe "The undef keyword" do it "raises a NameError when passed a missing name" do Class.new do -> { - undef not_exist + undef not_exist }.should raise_error(NameError) { |e| # a NameError and not a NoMethodError e.class.should == NameError diff --git a/spec/ruby/language/variables_spec.rb b/spec/ruby/language/variables_spec.rb index 01be61a9dc..bd993acb0f 100644 --- a/spec/ruby/language/variables_spec.rb +++ b/spec/ruby/language/variables_spec.rb @@ -14,69 +14,34 @@ describe "Evaluation order during assignment" do end context "with multiple assignment" do - ruby_version_is ""..."3.1" do - it "does not evaluate from left to right" do - obj = VariablesSpecs::EvalOrder.new - - obj.instance_eval do - foo[0], bar.baz = a, b - end - - obj.order.should == ["a", "b", "foo", "foo[]=", "bar", "bar.baz="] + it "evaluates from left to right, receivers first then methods" do + obj = VariablesSpecs::EvalOrder.new + obj.instance_eval do + foo[0], bar.baz = a, b end - it "cannot be used to swap variables with nested method calls" do - node = VariablesSpecs::EvalOrder.new.node - - original_node = node - original_node_left = node.left - original_node_left_right = node.left.right - - node.left, node.left.right, node = node.left.right, node, node.left - # Should evaluate in the order of: - # RHS: node.left.right, node, node.left - # LHS: - # * node(original_node), original_node.left = original_node_left_right - # * node(original_node), node.left(changed in the previous assignment to original_node_left_right), - # original_node_left_right.right = original_node - # * node = original_node_left - - node.should == original_node_left - node.right.should_not == original_node - node.right.left.should_not == original_node_left_right - end + obj.order.should == ["foo", "bar", "a", "b", "foo[]=", "bar.baz="] end - ruby_version_is "3.1" do - it "evaluates from left to right, receivers first then methods" do - obj = VariablesSpecs::EvalOrder.new - obj.instance_eval do - foo[0], bar.baz = a, b - end + it "can be used to swap variables with nested method calls" do + node = VariablesSpecs::EvalOrder.new.node - obj.order.should == ["foo", "bar", "a", "b", "foo[]=", "bar.baz="] - end + original_node = node + original_node_left = node.left + original_node_left_right = node.left.right - it "can be used to swap variables with nested method calls" do - node = VariablesSpecs::EvalOrder.new.node - - original_node = node - original_node_left = node.left - original_node_left_right = node.left.right - - node.left, node.left.right, node = node.left.right, node, node.left - # Should evaluate in the order of: - # LHS: node, node.left(original_node_left) - # RHS: original_node_left_right, original_node, original_node_left - # Ops: - # * node(original_node), original_node.left = original_node_left_right - # * original_node_left.right = original_node - # * node = original_node_left - - node.should == original_node_left - node.right.should == original_node - node.right.left.should == original_node_left_right - end + node.left, node.left.right, node = node.left.right, node, node.left + # Should evaluate in the order of: + # LHS: node, node.left(original_node_left) + # RHS: original_node_left_right, original_node, original_node_left + # Ops: + # * node(original_node), original_node.left = original_node_left_right + # * original_node_left.right = original_node + # * node = original_node_left + + node.should == original_node_left + node.right.should == original_node + node.right.left.should == original_node_left_right end end end @@ -381,6 +346,9 @@ describe "Multiple assignment" do SINGLE_RHS_1, SINGLE_RHS_2 = 1 [SINGLE_RHS_1, SINGLE_RHS_2].should == [1, nil] end + ensure + VariableSpecs.send(:remove_const, :SINGLE_RHS_1) + VariableSpecs.send(:remove_const, :SINGLE_RHS_2) end end @@ -619,6 +587,8 @@ describe "Multiple assignment" do (*SINGLE_SPLATTED_RHS) = *1 SINGLE_SPLATTED_RHS.should == [1] end + ensure + VariableSpecs.send(:remove_const, :SINGLE_SPLATTED_RHS) end end @@ -818,6 +788,9 @@ describe "Multiple assignment" do MRHS_VALUES_1.should == 1 MRHS_VALUES_2.should == 2 end + ensure + VariableSpecs.send(:remove_const, :MRHS_VALUES_1) + VariableSpecs.send(:remove_const, :MRHS_VALUES_2) end it "assigns all RHS values as an array to a single LHS constant" do @@ -825,6 +798,8 @@ describe "Multiple assignment" do MRHS_VALUES = 1, 2, 3 MRHS_VALUES.should == [1, 2, 3] end + ensure + VariableSpecs.send(:remove_const, :MRHS_VALUES) end end |