diff options
author | Benoit Daloze <eregontp@gmail.com> | 2021-07-29 22:11:21 +0200 |
---|---|---|
committer | Benoit Daloze <eregontp@gmail.com> | 2021-07-29 22:11:21 +0200 |
commit | 6998d758248d778fa95b008c78d05473e48b8428 (patch) | |
tree | 8abc6926f647ea5f374a5b34c3a4820c5861e32e /spec/ruby/core/hash | |
parent | 15d05f8120745a121b93fab9fd2addf5f094e8d2 (diff) | |
download | ruby-6998d758248d778fa95b008c78d05473e48b8428.tar.gz |
Update to ruby/spec@b65d01f
Diffstat (limited to 'spec/ruby/core/hash')
-rw-r--r-- | spec/ruby/core/hash/filter_spec.rb | 12 | ||||
-rw-r--r-- | spec/ruby/core/hash/merge_spec.rb | 24 | ||||
-rw-r--r-- | spec/ruby/core/hash/shared/update.rb | 16 | ||||
-rw-r--r-- | spec/ruby/core/hash/to_h_spec.rb | 58 | ||||
-rw-r--r-- | spec/ruby/core/hash/transform_keys_spec.rb | 27 |
5 files changed, 55 insertions, 82 deletions
diff --git a/spec/ruby/core/hash/filter_spec.rb b/spec/ruby/core/hash/filter_spec.rb index 4382c94e62..7dabe44984 100644 --- a/spec/ruby/core/hash/filter_spec.rb +++ b/spec/ruby/core/hash/filter_spec.rb @@ -1,12 +1,10 @@ require_relative '../../spec_helper' require_relative 'shared/select' -ruby_version_is "2.6" do - describe "Hash#filter" do - it_behaves_like :hash_select, :filter - end +describe "Hash#filter" do + it_behaves_like :hash_select, :filter +end - describe "Hash#filter!" do - it_behaves_like :hash_select!, :filter! - end +describe "Hash#filter!" do + it_behaves_like :hash_select!, :filter! end diff --git a/spec/ruby/core/hash/merge_spec.rb b/spec/ruby/core/hash/merge_spec.rb index 91ded30eb7..5521864297 100644 --- a/spec/ruby/core/hash/merge_spec.rb +++ b/spec/ruby/core/hash/merge_spec.rb @@ -81,19 +81,17 @@ describe "Hash#merge" do merge_pairs.should == expected_pairs end - ruby_version_is "2.6" do - it "accepts multiple hashes" do - result = { a: 1 }.merge({ b: 2 }, { c: 3 }, { d: 4 }) - result.should == { a: 1, b: 2, c: 3, d: 4 } - end - - it "accepts zero arguments and returns a copy of self" do - hash = { a: 1 } - merged = hash.merge - - merged.should eql(hash) - merged.should_not equal(hash) - end + it "accepts multiple hashes" do + result = { a: 1 }.merge({ b: 2 }, { c: 3 }, { d: 4 }) + result.should == { a: 1, b: 2, c: 3, d: 4 } + end + + it "accepts zero arguments and returns a copy of self" do + hash = { a: 1 } + merged = hash.merge + + merged.should eql(hash) + merged.should_not equal(hash) end end diff --git a/spec/ruby/core/hash/shared/update.rb b/spec/ruby/core/hash/shared/update.rb index 4bb20e5b85..1b0eb809bf 100644 --- a/spec/ruby/core/hash/shared/update.rb +++ b/spec/ruby/core/hash/shared/update.rb @@ -64,15 +64,13 @@ describe :hash_update, shared: true do hash.should == {1 => :foo, 3 => :bar, 5 => 6} end - ruby_version_is "2.6" do - it "accepts multiple hashes" do - result = { a: 1 }.send(@method, { b: 2 }, { c: 3 }, { d: 4 }) - result.should == { a: 1, b: 2, c: 3, d: 4 } - end + it "accepts multiple hashes" do + result = { a: 1 }.send(@method, { b: 2 }, { c: 3 }, { d: 4 }) + result.should == { a: 1, b: 2, c: 3, d: 4 } + end - it "accepts zero arguments" do - hash = { a: 1 } - hash.send(@method).should eql(hash) - end + it "accepts zero arguments" do + hash = { a: 1 } + hash.send(@method).should eql(hash) end end diff --git a/spec/ruby/core/hash/to_h_spec.rb b/spec/ruby/core/hash/to_h_spec.rb index d6eaac9f33..75ebce68b1 100644 --- a/spec/ruby/core/hash/to_h_spec.rb +++ b/spec/ruby/core/hash/to_h_spec.rb @@ -32,43 +32,41 @@ describe "Hash#to_h" do end end - ruby_version_is "2.6" do - context "with block" do - it "converts [key, value] pairs returned by the block to a hash" do - { a: 1, b: 2 }.to_h { |k, v| [k.to_s, v*v]}.should == { "a" => 1, "b" => 4 } - end + context "with block" do + it "converts [key, value] pairs returned by the block to a hash" do + { a: 1, b: 2 }.to_h { |k, v| [k.to_s, v*v]}.should == { "a" => 1, "b" => 4 } + end - it "raises ArgumentError if block returns longer or shorter array" do - -> do - { a: 1, b: 2 }.to_h { |k, v| [k.to_s, v*v, 1] } - end.should raise_error(ArgumentError, /element has wrong array length/) + it "raises ArgumentError if block returns longer or shorter array" do + -> do + { a: 1, b: 2 }.to_h { |k, v| [k.to_s, v*v, 1] } + end.should raise_error(ArgumentError, /element has wrong array length/) - -> do - { a: 1, b: 2 }.to_h { |k, v| [k] } - end.should raise_error(ArgumentError, /element has wrong array length/) - end + -> do + { a: 1, b: 2 }.to_h { |k, v| [k] } + end.should raise_error(ArgumentError, /element has wrong array length/) + end - it "raises TypeError if block returns something other than Array" do - -> do - { a: 1, b: 2 }.to_h { |k, v| "not-array" } - end.should raise_error(TypeError, /wrong element type String/) - end + it "raises TypeError if block returns something other than Array" do + -> do + { a: 1, b: 2 }.to_h { |k, v| "not-array" } + end.should raise_error(TypeError, /wrong element type String/) + end - it "coerces returned pair to Array with #to_ary" do - x = mock('x') - x.stub!(:to_ary).and_return([:b, 'b']) + it "coerces returned pair to Array with #to_ary" do + x = mock('x') + x.stub!(:to_ary).and_return([:b, 'b']) - { a: 1 }.to_h { |k| x }.should == { :b => 'b' } - end + { a: 1 }.to_h { |k| x }.should == { :b => 'b' } + end - it "does not coerce returned pair to Array with #to_a" do - x = mock('x') - x.stub!(:to_a).and_return([:b, 'b']) + it "does not coerce returned pair to Array with #to_a" do + x = mock('x') + x.stub!(:to_a).and_return([:b, 'b']) - -> do - { a: 1 }.to_h { |k| x } - end.should raise_error(TypeError, /wrong element type MockObject/) - end + -> do + { a: 1 }.to_h { |k| x } + end.should raise_error(TypeError, /wrong element type MockObject/) end end end diff --git a/spec/ruby/core/hash/transform_keys_spec.rb b/spec/ruby/core/hash/transform_keys_spec.rb index 4f4544a6c5..70a4cdde36 100644 --- a/spec/ruby/core/hash/transform_keys_spec.rb +++ b/spec/ruby/core/hash/transform_keys_spec.rb @@ -60,31 +60,12 @@ describe "Hash#transform_keys!" do end # https://bugs.ruby-lang.org/issues/14380 - ruby_version_is ""..."2.5.1" do - it "does not prevent conflicts between new keys and old ones" do - @hash.transform_keys!(&:succ) - @hash.should == { e: 1 } - end - end - - ruby_version_is "2.5.1" do - it "prevents conflicts between new keys and old ones" do - @hash.transform_keys!(&:succ) - @hash.should == { b: 1, c: 2, d: 3, e: 4 } - end - end - - ruby_version_is ""..."2.5.1" do - it "partially modifies the contents if we broke from the block" do - @hash.transform_keys! do |v| - break if v == :c - v.succ - end - @hash.should == { c: 1, d: 4 } - end + it "prevents conflicts between new keys and old ones" do + @hash.transform_keys!(&:succ) + @hash.should == { b: 1, c: 2, d: 3, e: 4 } end - ruby_version_is "2.5.1"..."3.0.2" do # https://bugs.ruby-lang.org/issues/17735 + ruby_version_is ""..."3.0.2" do # https://bugs.ruby-lang.org/issues/17735 it "returns the processed keys if we broke from the block" do @hash.transform_keys! do |v| break if v == :c |