From 67b74b40877170fc44195eb773d521176b5633cf Mon Sep 17 00:00:00 2001 From: Herwin Date: Sun, 18 Jan 2026 13:20:45 +0100 Subject: [PATCH 1/2] Small improvoments to specs of Hash.[] * Remove all validations inside a block that should raise, this code should never be executed. * Update the spec with `[:nil]`, to use `[nil]` instead. The old code tested the exact same thing as `[:a]` above it. --- core/hash/constructor_spec.rb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/core/hash/constructor_spec.rb b/core/hash/constructor_spec.rb index 0f97f7b40..6ad912647 100644 --- a/core/hash/constructor_spec.rb +++ b/core/hash/constructor_spec.rb @@ -44,22 +44,20 @@ it "raises for elements that are not arrays" do -> { - Hash[[:a]].should == {} + Hash[[:a]] }.should raise_error(ArgumentError) -> { - Hash[[:nil]].should == {} + Hash[[nil]] }.should raise_error(ArgumentError) end it "raises an ArgumentError for arrays of more than 2 elements" do - ->{ Hash[[[:a, :b, :c]]].should == {} }.should raise_error(ArgumentError) + ->{ Hash[[[:a, :b, :c]]] }.should raise_error(ArgumentError) end it "raises an ArgumentError when passed a list of value-invalid-pairs in an array" do -> { - -> { - Hash[[[:a, 1], [:b], 42, [:d, 2], [:e, 2, 3], []]] - }.should complain(/ignoring wrong elements/) + Hash[[[:a, 1], [:b], 42, [:d, 2], [:e, 2, 3], []]] }.should raise_error(ArgumentError) end From a3b09747c083b3e0fe599ef9373d28049efec7af Mon Sep 17 00:00:00 2001 From: Herwin Date: Sun, 18 Jan 2026 13:24:57 +0100 Subject: [PATCH 2/2] Include message validation in expected exception of Hash.[] --- core/hash/constructor_spec.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/core/hash/constructor_spec.rb b/core/hash/constructor_spec.rb index 6ad912647..201a20c1f 100644 --- a/core/hash/constructor_spec.rb +++ b/core/hash/constructor_spec.rb @@ -45,20 +45,22 @@ it "raises for elements that are not arrays" do -> { Hash[[:a]] - }.should raise_error(ArgumentError) + }.should raise_error(ArgumentError, "wrong element type Symbol at 0 (expected array)") -> { Hash[[nil]] - }.should raise_error(ArgumentError) + }.should raise_error(ArgumentError, "wrong element type nil at 0 (expected array)") end it "raises an ArgumentError for arrays of more than 2 elements" do - ->{ Hash[[[:a, :b, :c]]] }.should raise_error(ArgumentError) + ->{ + Hash[[[:a, :b, :c]]] + }.should raise_error(ArgumentError, "invalid number of elements (3 for 1..2)") end it "raises an ArgumentError when passed a list of value-invalid-pairs in an array" do -> { Hash[[[:a, 1], [:b], 42, [:d, 2], [:e, 2, 3], []]] - }.should raise_error(ArgumentError) + }.should raise_error(ArgumentError, "wrong element type Integer at 2 (expected array)") end describe "passed a single argument which responds to #to_hash" do