diff options
Diffstat (limited to 'spec/ruby/core/hash/constructor_spec.rb')
-rw-r--r-- | spec/ruby/core/hash/constructor_spec.rb | 45 |
1 files changed, 25 insertions, 20 deletions
diff --git a/spec/ruby/core/hash/constructor_spec.rb b/spec/ruby/core/hash/constructor_spec.rb index ad67274802..8d29773909 100644 --- a/spec/ruby/core/hash/constructor_spec.rb +++ b/spec/ruby/core/hash/constructor_spec.rb @@ -42,26 +42,13 @@ describe "Hash.[]" do Hash[ary].should == { a: :b } end - ruby_version_is "" ... "2.7" do - it "ignores elements that are not arrays" do - -> { - Hash[[:a]].should == {} - }.should complain(/ignoring wrong elements/) - -> { - Hash[[:nil]].should == {} - }.should complain(/ignoring wrong elements/) - end - end - - ruby_version_is "2.7" do - it "raises for elements that are not arrays" do - -> { - Hash[[:a]].should == {} - }.should raise_error(ArgumentError) - -> { - Hash[[:nil]].should == {} - }.should raise_error(ArgumentError) - end + it "raises for elements that are not arrays" do + -> { + Hash[[:a]].should == {} + }.should raise_error(ArgumentError) + -> { + Hash[[:nil]].should == {} + }.should raise_error(ArgumentError) end it "raises an ArgumentError for arrays of more than 2 elements" do @@ -116,8 +103,26 @@ describe "Hash.[]" do HashSpecs::MyInitializerHash[Hash[1, 2]].should be_an_instance_of(HashSpecs::MyInitializerHash) end + it "removes the default value" do + hash = Hash.new(1) + Hash[hash].default.should be_nil + hash[:a] = 1 + Hash[hash].default.should be_nil + end + it "removes the default_proc" do hash = Hash.new { |h, k| h[k] = [] } Hash[hash].default_proc.should be_nil + hash[:a] = 1 + Hash[hash].default_proc.should be_nil + end + + ruby_version_is '3.3' do + it "does not retain compare_by_identity_flag" do + hash = {}.compare_by_identity + Hash[hash].compare_by_identity?.should == false + hash[:a] = 1 + Hash[hash].compare_by_identity?.should == false + end end end |