diff options
Diffstat (limited to 'spec/ruby/language/block_spec.rb')
-rw-r--r-- | spec/ruby/language/block_spec.rb | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/spec/ruby/language/block_spec.rb b/spec/ruby/language/block_spec.rb index 95fd74ce26..8f3c39df31 100644 --- a/spec/ruby/language/block_spec.rb +++ b/spec/ruby/language/block_spec.rb @@ -49,7 +49,20 @@ describe "A block yielded a single" do result.should == [1, 2, [], 3, 2, {x: 9}] end - it "calls #to_hash on the argument" do + 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 obj = mock("coerce block keyword arguments") obj.should_receive(:to_hash).and_return({"a" => 1, "b" => 2}) @@ -58,17 +71,9 @@ describe "A block yielded a single" do end 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 + 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 |