diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-08-14 11:58:17 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-08-14 11:58:17 +0000 |
commit | 37279d15468ec5d5873e9a5fea49cd6323891fa6 (patch) | |
tree | 0550c01e46a0c04ce26e1177763dc97000eaee0d /spec/ruby/language/block_spec.rb | |
parent | 31bfe0fe86433beddfec2b2bdba69dfda1775f8d (diff) |
non-symbol keys in kwargs
* class.c (separate_symbol): [EXPERIMENTAL] non-symbol key in keyword
arguments hash causes an exception now.
c.f. https://twitter.com/yukihiro_matz/status/1022287578995646464
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64358 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/ruby/language/block_spec.rb')
-rw-r--r-- | spec/ruby/language/block_spec.rb | 31 |
1 files changed, 14 insertions, 17 deletions
diff --git a/spec/ruby/language/block_spec.rb b/spec/ruby/language/block_spec.rb index 27fcb4919b..f674c1d0e4 100644 --- a/spec/ruby/language/block_spec.rb +++ b/spec/ruby/language/block_spec.rb @@ -49,20 +49,7 @@ describe "A block yielded a single" do result.should == [1, 2, [], 3, 2, {x: 9}] end - it "assigns symbol keys from a Hash to keyword arguments" do - result = m(["a" => 1, a: 10]) { |a=nil, **b| [a, b] } - result.should == [{"a" => 1}, a: 10] - end - - it "assigns symbol keys from a Hash returned by #to_hash to keyword arguments" do - obj = mock("coerce block keyword arguments") - obj.should_receive(:to_hash).and_return({"a" => 1, b: 2}) - - result = m([obj]) { |a=nil, **b| [a, b] } - result.should == [{"a" => 1}, b: 2] - end - - it "calls #to_hash on the argument but does not use the result when no keywords are present" do + it "calls #to_hash on the argument" do obj = mock("coerce block keyword arguments") obj.should_receive(:to_hash).and_return({"a" => 1, "b" => 2}) @@ -70,9 +57,19 @@ describe "A block yielded a single" do result.should == [{"a" => 1, "b" => 2}, {}] end - it "assigns non-symbol keys to non-keyword arguments" do - result = m(["a" => 10, b: 2]) { |a=nil, **b| [a, b] } - result.should == [{"a" => 10}, {b: 2}] + describe("when non-symbol keys are in a keyword arguments Hash") do + ruby_version_is ""..."2.6" do + it "separates non-symbol keys and symbol keys" do + result = m(["a" => 10, b: 2]) { |a=nil, **b| [a, b] } + result.should == [{"a" => 10}, {b: 2}] + end + end + + ruby_version_is "2.6" do + it "raises an ArgumentError" do + lambda {m(["a" => 1, a: 10]) { |a=nil, **b| [a, b] }}.should raise_error(ArgumentError) + end + end end it "does not treat hashes with string keys as keyword arguments" do |