diff options
author | Benoit Daloze <[email protected]> | 2019-09-29 16:03:58 +0200 |
---|---|---|
committer | Benoit Daloze <[email protected]> | 2019-09-29 16:03:58 +0200 |
commit | 1c938a72aa9378f982dbc55327e86150c47b8707 (patch) | |
tree | 34a0bb0a45396c26eed111877a810c3aa793bff5 /spec/ruby/language | |
parent | 31bb66a19df26409c9d47afcf37919c9a065516a (diff) |
Update to ruby/spec@519df35
Diffstat (limited to 'spec/ruby/language')
-rw-r--r-- | spec/ruby/language/block_spec.rb | 24 | ||||
-rw-r--r-- | spec/ruby/language/hash_spec.rb | 2 | ||||
-rw-r--r-- | spec/ruby/language/lambda_spec.rb | 16 | ||||
-rw-r--r-- | spec/ruby/language/method_spec.rb | 43 | ||||
-rw-r--r-- | spec/ruby/language/return_spec.rb | 9 | ||||
-rw-r--r-- | spec/ruby/language/send_spec.rb | 5 |
6 files changed, 33 insertions, 66 deletions
diff --git a/spec/ruby/language/block_spec.rb b/spec/ruby/language/block_spec.rb index f8bfc8d9ed..e5c9fcb762 100644 --- a/spec/ruby/language/block_spec.rb +++ b/spec/ruby/language/block_spec.rb @@ -6,14 +6,6 @@ describe "A block yielded a single" do def m(a) yield a end end - def supress_keyword_warning(&block) - if RUBY_VERSION > '2.7' - suppress_warning(&block) - else - yield - end - end - context "Array" do it "assigns the Array to a single argument" do m([1, 2]) { |a| a }.should == [1, 2] @@ -53,21 +45,21 @@ describe "A block yielded a single" do end it "assigns elements to mixed argument types" do - supress_keyword_warning do + suppress_keyword_warning do result = m([1, 2, 3, {x: 9}]) { |a, b=5, *c, d, e: 2, **k| [a, b, c, d, e, k] } result.should == [1, 2, [], 3, 2, {x: 9}] end end it "assigns symbol keys from a Hash to keyword arguments" do - supress_keyword_warning do + suppress_keyword_warning do result = m(["a" => 1, a: 10]) { |a=nil, **b| [a, b] } result.should == [{"a" => 1}, a: 10] end end it "assigns symbol keys from a Hash returned by #to_hash to keyword arguments" do - supress_keyword_warning do + suppress_keyword_warning do obj = mock("coerce block keyword arguments") obj.should_receive(:to_hash).and_return({"a" => 1, b: 2}) @@ -76,7 +68,7 @@ describe "A block yielded a single" do end end - ruby_version_is "0"..."2.7" do + ruby_version_is ""..."2.7" do it "calls #to_hash on the argument and uses resulting hash as first argument when optional argument and keyword argument accepted" do obj = mock("coerce block keyword arguments") obj.should_receive(:to_hash).and_return({"a" => 1, "b" => 2}) @@ -98,7 +90,7 @@ describe "A block yielded a single" do describe "when non-symbol keys are in a keyword arguments Hash" do it "separates non-symbol keys and symbol keys" do - supress_keyword_warning do + suppress_keyword_warning do result = m(["a" => 10, b: 2]) { |a=nil, **b| [a, b] } result.should == [{"a" => 10}, {b: 2}] end @@ -111,7 +103,7 @@ describe "A block yielded a single" do end it "calls #to_hash on the last element if keyword arguments are present" do - supress_keyword_warning do + suppress_keyword_warning do obj = mock("destructure block keyword arguments") obj.should_receive(:to_hash).and_return({x: 9}) @@ -121,7 +113,7 @@ describe "A block yielded a single" do end it "assigns the last element to a non-keyword argument if #to_hash returns nil" do - supress_keyword_warning do + suppress_keyword_warning do obj = mock("destructure block keyword arguments") obj.should_receive(:to_hash).and_return(nil) @@ -131,7 +123,7 @@ describe "A block yielded a single" do end it "calls #to_hash on the last element when there are more arguments than parameters" do - supress_keyword_warning do + suppress_keyword_warning do x = mock("destructure matching block keyword argument") x.should_receive(:to_hash).and_return({x: 9}) diff --git a/spec/ruby/language/hash_spec.rb b/spec/ruby/language/hash_spec.rb index 79131e9da6..6f2e8e5cf0 100644 --- a/spec/ruby/language/hash_spec.rb +++ b/spec/ruby/language/hash_spec.rb @@ -128,7 +128,7 @@ describe "Hash literal" do {a: 1, **obj, c: 3}.should == {a:1, b: 2, c: 3, d: 4} end - ruby_version_is "0"..."2.7" do + ruby_version_is ""..."2.7" do it "raises a TypeError if any splatted elements keys are not symbols" do h = {1 => 2, b: 3} -> { {a: 1, **h} }.should raise_error(TypeError) diff --git a/spec/ruby/language/lambda_spec.rb b/spec/ruby/language/lambda_spec.rb index 3b06a0d595..5fa7fa6bfa 100644 --- a/spec/ruby/language/lambda_spec.rb +++ b/spec/ruby/language/lambda_spec.rb @@ -186,14 +186,6 @@ describe "A lambda literal -> () { }" do @a.().should == {} @a.(1, 2, 3, a: 4, b: 5).should == {a: 4, b: 5} - def self.suppress_keyword_warning(&block) - if RUBY_VERSION > '2.7' - suppress_warning(&block) - else - yield - end - end - suppress_keyword_warning do h = mock("keyword splat") h.should_receive(:to_hash).and_return({a: 1}) @@ -530,14 +522,6 @@ describe "A lambda expression 'lambda { ... }'" do @a.().should == {} @a.(1, 2, 3, a: 4, b: 5).should == {a: 4, b: 5} - def self.suppress_keyword_warning(&block) - if RUBY_VERSION > '2.7' - suppress_warning(&block) - else - yield - end - end - suppress_keyword_warning do h = mock("keyword splat") h.should_receive(:to_hash).and_return({a: 1}) diff --git a/spec/ruby/language/method_spec.rb b/spec/ruby/language/method_spec.rb index 410dba99e2..0486025792 100644 --- a/spec/ruby/language/method_spec.rb +++ b/spec/ruby/language/method_spec.rb @@ -480,15 +480,6 @@ describe "A method" do end context "assigns local variables from method parameters" do - - suppress_keyword_warning = ->(&block) do - if RUBY_VERSION >= '2.7' - suppress_warning(&block) - else - block.call - end - end - evaluate <<-ruby do def m(a) a end ruby @@ -555,7 +546,7 @@ describe "A method" do -> { m() }.should raise_error(ArgumentError) m(a: 1).should == 1 - suppress_keyword_warning.call do + suppress_keyword_warning do -> { m("a" => 1, a: 1) }.should raise_error(ArgumentError) end end @@ -717,7 +708,7 @@ describe "A method" do ruby m(1, b: 2).should == [1, 2] - suppress_keyword_warning.call do + suppress_keyword_warning do -> { m("a" => 1, b: 2) }.should raise_error(ArgumentError) end end @@ -728,7 +719,7 @@ describe "A method" do m(2).should == [2, 1] m(1, b: 2).should == [1, 2] - suppress_keyword_warning.call do + suppress_keyword_warning do m("a" => 1, b: 2).should == [{"a" => 1, b: 2}, 1] end end @@ -739,7 +730,7 @@ describe "A method" do m(1).should == 1 m(1, a: 2, b: 3).should == 1 - suppress_keyword_warning.call do + suppress_keyword_warning do m("a" => 1, b: 2).should == {"a" => 1, b: 2} end end @@ -750,7 +741,7 @@ describe "A method" do m(1).should == [1, {}] m(1, a: 2, b: 3).should == [1, {a: 2, b: 3}] - suppress_keyword_warning.call do + suppress_keyword_warning do m("a" => 1, b: 2).should == [{"a" => 1, b: 2}, {}] end end @@ -869,7 +860,7 @@ describe "A method" do m(b: 2).should == [1, 2] m(2, b: 1).should == [2, 1] - suppress_keyword_warning.call do + suppress_keyword_warning do m("a" => 1, b: 2).should == [{"a" => 1}, 2] end end @@ -881,12 +872,12 @@ describe "A method" do m().should == [1, 2] m(2).should == [2, 2] m(b: 3).should == [1, 3] - suppress_keyword_warning.call do + suppress_keyword_warning do m("a" => 1, b: 2).should == [{"a" => 1}, 2] end end - ruby_version_is "0"..."2.7" do + ruby_version_is ""..."2.7" do evaluate <<-ruby do def m(a=1, **) a end ruby @@ -951,7 +942,7 @@ describe "A method" do m(a: 1).should == 1 m(1, 2, a: 3).should == 3 - suppress_keyword_warning.call do + suppress_keyword_warning do m("a" => 1, a: 2).should == 2 end end @@ -962,7 +953,7 @@ describe "A method" do m(b: 1).should == [[], 1] m(1, 2, b: 3).should == [[1, 2], 3] - suppress_keyword_warning.call do + suppress_keyword_warning do m("a" => 1, b: 2).should == [[{"a" => 1}], 2] end end @@ -975,7 +966,7 @@ describe "A method" do m(1, 2).should == 1 m(a: 2).should == 2 m(1, a: 2).should == 2 - suppress_keyword_warning.call do + suppress_keyword_warning do m("a" => 1, a: 2).should == 2 end end @@ -986,7 +977,7 @@ describe "A method" do m().should == [[], 1] m(1, 2, 3, b: 4).should == [[1, 2, 3], 4] - suppress_keyword_warning.call do + suppress_keyword_warning do m("a" => 1, b: 2).should == [[{"a" => 1}], 2] end @@ -1005,7 +996,7 @@ describe "A method" do h = mock("keyword splat") h.should_receive(:to_hash).and_return({a: 1}) - suppress_keyword_warning.call do + suppress_keyword_warning do m(h).should be_nil end @@ -1015,7 +1006,7 @@ describe "A method" do -> { m(h) }.should raise_error(error) end - ruby_version_is "0"..."2.7" do + ruby_version_is ""..."2.7" do evaluate <<-ruby do def m(*a, **) a end ruby @@ -1218,7 +1209,7 @@ describe "A method" do ruby m(a: 1, b: 2).should == [1, 2] - suppress_keyword_warning.call do + suppress_keyword_warning do -> { m("a" => 1, a: 1, b: 2) }.should raise_error(ArgumentError) end end @@ -1229,12 +1220,12 @@ describe "A method" do m(a: 1).should == [1, 1] m(a: 1, b: 2).should == [1, 2] - suppress_keyword_warning.call do + suppress_keyword_warning do -> { m("a" => 1, a: 1, b: 2) }.should raise_error(ArgumentError) end end - ruby_version_is '0'...'2.7' do + ruby_version_is ''...'2.7' do evaluate <<-ruby do def m(a:, **) a end ruby diff --git a/spec/ruby/language/return_spec.rb b/spec/ruby/language/return_spec.rb index 27729750f1..7f740be25b 100644 --- a/spec/ruby/language/return_spec.rb +++ b/spec/ruby/language/return_spec.rb @@ -496,13 +496,12 @@ describe "The return keyword" do ruby_version_is "2.7" do it "warns but does not affect exit status" do - ruby_exe(<<-END_OF_CODE).should == "-e: warning: argument of top-level return is ignored\n" - $stderr.reopen($stdout) - system(ENV['RUBY_EXE'], '-e', 'return 10') - exit($?.exitstatus) + err = ruby_exe(<<-END_OF_CODE, args: "2>&1") + return 10 END_OF_CODE - $?.exitstatus.should == 0 + + err.should =~ /warning: argument of top-level return is ignored/ end end end diff --git a/spec/ruby/language/send_spec.rb b/spec/ruby/language/send_spec.rb index 5e6571893c..c56d5e8c26 100644 --- a/spec/ruby/language/send_spec.rb +++ b/spec/ruby/language/send_spec.rb @@ -265,11 +265,12 @@ describe "Invoking a private getter method" do -> { receiver.call_self_foo_or_equals(6) }.should raise_error(NoMethodError) end end + ruby_version_is "2.7" do it "permits self as a receiver" do receiver = LangSendSpecs::PrivateGetter.new - -> { receiver.call_self_foo }.should_not raise_error(NoMethodError) - -> { receiver.call_self_foo_or_equals(6) }.should_not raise_error(NoMethodError) + receiver.call_self_foo_or_equals(6) + receiver.call_self_foo.should == 6 end end end |