diff options
Diffstat (limited to 'spec/ruby/language')
-rw-r--r-- | spec/ruby/language/block_spec.rb | 29 | ||||
-rw-r--r-- | spec/ruby/language/method_spec.rb | 91 |
2 files changed, 30 insertions, 90 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 diff --git a/spec/ruby/language/method_spec.rb b/spec/ruby/language/method_spec.rb index c5612ed19f..49837fa638 100644 --- a/spec/ruby/language/method_spec.rb +++ b/spec/ruby/language/method_spec.rb @@ -849,12 +849,7 @@ describe "A method" do m(b: 2).should == [1, 2] m(2, b: 1).should == [2, 1] - ruby_version_is ""..."2.6" do - m("a" => 1, b: 2).should == [{"a" => 1}, 2] - end - ruby_version_is "2.6" do - lambda {m("a" => 1, b: 2)}.should raise_error(ArgumentError) - end + m("a" => 1, b: 2).should == [{"a" => 1}, 2] end evaluate <<-ruby do @@ -864,12 +859,7 @@ describe "A method" do m().should == [1, 2] m(2).should == [2, 2] m(b: 3).should == [1, 3] - ruby_version_is ""..."2.6" do - m("a" => 1, b: 2).should == [{"a" => 1}, 2] - end - ruby_version_is "2.6" do - lambda {m("a" => 1, b: 2)}.should raise_error(ArgumentError) - end + m("a" => 1, b: 2).should == [{"a" => 1}, 2] end evaluate <<-ruby do @@ -878,12 +868,7 @@ describe "A method" do m().should == 1 m(2, a: 1, b: 0).should == 2 - ruby_version_is ""..."2.6" do - m("a" => 1, a: 2).should == {"a" => 1} - end - ruby_version_is "2.6" do - lambda {m("a" => 1, a: 2)}.should raise_error(ArgumentError) - end + m("a" => 1, a: 2).should == {"a" => 1} end evaluate <<-ruby do @@ -929,12 +914,7 @@ describe "A method" do m(a: 1).should == 1 m(1, 2, a: 3).should == 3 - ruby_version_is ""..."2.6" do - m("a" => 1, a: 2).should == 2 - end - ruby_version_is "2.6" do - lambda {m("a" => 1, a: 2)}.should raise_error(ArgumentError) - end + m("a" => 1, a: 2).should == 2 end evaluate <<-ruby do @@ -943,12 +923,7 @@ describe "A method" do m(b: 1).should == [[], 1] m(1, 2, b: 3).should == [[1, 2], 3] - ruby_version_is ""..."2.6" do - m("a" => 1, b: 2).should == [[{"a" => 1}], 2] - end - ruby_version_is "2.6" do - lambda {m("a" => 1, b: 2)}.should raise_error(ArgumentError) - end + m("a" => 1, b: 2).should == [[{"a" => 1}], 2] end evaluate <<-ruby do @@ -959,12 +934,7 @@ describe "A method" do m(1, 2).should == 1 m(a: 2).should == 2 m(1, a: 2).should == 2 - ruby_version_is ""..."2.6" do - m("a" => 1, a: 2).should == 2 - end - ruby_version_is "2.6" do - lambda {m("a" => 1, a: 2)}.should raise_error(ArgumentError) - end + m("a" => 1, a: 2).should == 2 end evaluate <<-ruby do @@ -973,12 +943,7 @@ describe "A method" do m().should == [[], 1] m(1, 2, 3, b: 4).should == [[1, 2, 3], 4] - ruby_version_is ""..."2.6" do - m("a" => 1, b: 2).should == [[{"a" => 1}], 2] - end - ruby_version_is "2.6" do - lambda {m("a" => 1, b: 2)}.should raise_error(ArgumentError) - end + m("a" => 1, b: 2).should == [[{"a" => 1}], 2] a = mock("splat") a.should_not_receive(:to_ary) @@ -1009,12 +974,7 @@ describe "A method" do m().should == [] m(1, 2, 3, a: 4, b: 5).should == [1, 2, 3] - ruby_version_is ""..."2.6" do - m("a" => 1, a: 1).should == [{"a" => 1}] - end - ruby_version_is "2.6" do - lambda {m("a" => 1, a: 1)}.should raise_error(ArgumentError) - end + m("a" => 1, a: 1).should == [{"a" => 1}] m(1, **{a: 2}).should == [1] h = mock("keyword splat") @@ -1028,12 +988,7 @@ describe "A method" do m().should == {} m(1, 2, 3, a: 4, b: 5).should == {a: 4, b: 5} - ruby_version_is ""..."2.6" do - m("a" => 1, a: 1).should == {a: 1} - end - ruby_version_is "2.6" do - lambda {m("a" => 1, a: 1)}.should raise_error(ArgumentError) - end + m("a" => 1, a: 1).should == {a: 1} h = mock("keyword splat") h.should_receive(:to_hash).and_return({a: 1}) @@ -1047,22 +1002,12 @@ describe "A method" do m().should == [nil, {}] m("a" => 1).should == [{"a" => 1}, {}] m(a: 1).should == [nil, {a: 1}] - ruby_version_is ""..."2.6" do - m("a" => 1, a: 1).should == [{"a" => 1}, {a: 1}] - end - ruby_version_is "2.6" do - lambda {m("a" => 1, a: 1)}.should raise_error(ArgumentError) - end + m("a" => 1, a: 1).should == [{"a" => 1}, {a: 1}] m({ "a" => 1 }, a: 1).should == [{"a" => 1}, {a: 1}] m({a: 1}, {}).should == [{a: 1}, {}] h = {"a" => 1, b: 2} - ruby_version_is ""..."2.6" do - m(h).should == [{"a" => 1}, {b: 2}] - end - ruby_version_is "2.6" do - lambda {m(h)}.should raise_error(ArgumentError) - end + m(h).should == [{"a" => 1}, {b: 2}] h.should == {"a" => 1, b: 2} h = {"a" => 1} @@ -1082,12 +1027,7 @@ describe "A method" do h = mock("keyword splat") h.should_receive(:to_hash).and_return({"a" => 1, a: 2}) - ruby_version_is ""..."2.6" do - m(h).should == [{"a" => 1}, {a: 2}] - end - ruby_version_is "2.6" do - lambda {m(h)}.should raise_error(ArgumentError) - end + m(h).should == [{"a" => 1}, {a: 2}] end evaluate <<-ruby do @@ -1101,12 +1041,7 @@ describe "A method" do m("a" => 1).should == [[{"a" => 1}], {}] m(a: 1).should == [[], {a: 1}] - ruby_version_is ""..."2.6" do - m("a" => 1, a: 1).should == [[{"a" => 1}], {a: 1}] - end - ruby_version_is "2.6" do - lambda {m("a" => 1, a: 1)}.should raise_error(ArgumentError) - end + m("a" => 1, a: 1).should == [[{"a" => 1}], {a: 1}] m({ "a" => 1 }, a: 1).should == [[{"a" => 1}], {a: 1}] m({a: 1}, {}).should == [[{a: 1}], {}] m({a: 1}, {"a" => 1}).should == [[{a: 1}, {"a" => 1}], {}] |