From 826f44834fe11f3f9c52343443a15b6c83466889 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Sat, 8 Feb 2020 19:43:27 +0900 Subject: Drop support for ruby 2.4 from ruby/spec --- spec/ruby/core/hash/slice_spec.rb | 82 ++++++------ spec/ruby/core/hash/transform_keys_spec.rb | 194 ++++++++++++++--------------- 2 files changed, 136 insertions(+), 140 deletions(-) (limited to 'spec/ruby/core/hash') diff --git a/spec/ruby/core/hash/slice_spec.rb b/spec/ruby/core/hash/slice_spec.rb index f7717c9404..e3046d83d7 100644 --- a/spec/ruby/core/hash/slice_spec.rb +++ b/spec/ruby/core/hash/slice_spec.rb @@ -1,55 +1,53 @@ require_relative '../../spec_helper' -ruby_version_is "2.5" do - describe "Hash#slice" do - before :each do - @hash = { a: 1, b: 2, c: 3 } - end +describe "Hash#slice" do + before :each do + @hash = { a: 1, b: 2, c: 3 } + end - it "returns a new empty hash without arguments" do - ret = @hash.slice - ret.should_not equal(@hash) - ret.should be_an_instance_of(Hash) - ret.should == {} - end + it "returns a new empty hash without arguments" do + ret = @hash.slice + ret.should_not equal(@hash) + ret.should be_an_instance_of(Hash) + ret.should == {} + end - it "returns the requested subset" do - @hash.slice(:c, :a).should == { c: 3, a: 1 } - end + it "returns the requested subset" do + @hash.slice(:c, :a).should == { c: 3, a: 1 } + end - it "returns a hash ordered in the order of the requested keys" do - @hash.slice(:c, :a).keys.should == [:c, :a] - end + it "returns a hash ordered in the order of the requested keys" do + @hash.slice(:c, :a).keys.should == [:c, :a] + end - it "returns only the keys of the original hash" do - @hash.slice(:a, :chunky_bacon).should == { a: 1 } - end + it "returns only the keys of the original hash" do + @hash.slice(:a, :chunky_bacon).should == { a: 1 } + end - it "returns a Hash instance, even on subclasses" do - klass = Class.new(Hash) - h = klass.new - h[:bar] = 12 - h[:foo] = 42 - r = h.slice(:foo) - r.should == {foo: 42} - r.class.should == Hash - end + it "returns a Hash instance, even on subclasses" do + klass = Class.new(Hash) + h = klass.new + h[:bar] = 12 + h[:foo] = 42 + r = h.slice(:foo) + r.should == {foo: 42} + r.class.should == Hash + end - it "uses the regular Hash#[] method, even on subclasses that override it" do - ScratchPad.record [] - klass = Class.new(Hash) do - def [](value) - ScratchPad << :used_subclassed_operator - super - end + it "uses the regular Hash#[] method, even on subclasses that override it" do + ScratchPad.record [] + klass = Class.new(Hash) do + def [](value) + ScratchPad << :used_subclassed_operator + super end + end - h = klass.new - h[:bar] = 12 - h[:foo] = 42 - h.slice(:foo) + h = klass.new + h[:bar] = 12 + h[:foo] = 42 + h.slice(:foo) - ScratchPad.recorded.should == [] - end + ScratchPad.recorded.should == [] end end diff --git a/spec/ruby/core/hash/transform_keys_spec.rb b/spec/ruby/core/hash/transform_keys_spec.rb index 956fd73a47..2c5d4124e0 100644 --- a/spec/ruby/core/hash/transform_keys_spec.rb +++ b/spec/ruby/core/hash/transform_keys_spec.rb @@ -1,131 +1,129 @@ require_relative '../../spec_helper' -ruby_version_is "2.5" do - describe "Hash#transform_keys" do - before :each do - @hash = { a: 1, b: 2, c: 3 } - end +describe "Hash#transform_keys" do + before :each do + @hash = { a: 1, b: 2, c: 3 } + end - it "returns new hash" do - ret = @hash.transform_keys(&:succ) - ret.should_not equal(@hash) - ret.should be_an_instance_of(Hash) - end + it "returns new hash" do + ret = @hash.transform_keys(&:succ) + ret.should_not equal(@hash) + ret.should be_an_instance_of(Hash) + end - it "sets the result as transformed keys with the given block" do - @hash.transform_keys(&:succ).should == { b: 1, c: 2, d: 3 } - end + it "sets the result as transformed keys with the given block" do + @hash.transform_keys(&:succ).should == { b: 1, c: 2, d: 3 } + end - it "keeps last pair if new keys conflict" do - @hash.transform_keys { |_| :a }.should == { a: 3 } - end + it "keeps last pair if new keys conflict" do + @hash.transform_keys { |_| :a }.should == { a: 3 } + end - it "makes both hashes to share values" do - value = [1, 2, 3] - new_hash = { a: value }.transform_keys(&:upcase) - new_hash[:A].should equal(value) - end + it "makes both hashes to share values" do + value = [1, 2, 3] + new_hash = { a: value }.transform_keys(&:upcase) + new_hash[:A].should equal(value) + end - context "when no block is given" do - it "returns a sized Enumerator" do - enumerator = @hash.transform_keys - enumerator.should be_an_instance_of(Enumerator) - enumerator.size.should == @hash.size - enumerator.each(&:succ).should == { b: 1, c: 2, d: 3 } - end + context "when no block is given" do + it "returns a sized Enumerator" do + enumerator = @hash.transform_keys + enumerator.should be_an_instance_of(Enumerator) + enumerator.size.should == @hash.size + enumerator.each(&:succ).should == { b: 1, c: 2, d: 3 } end + end - it "returns a Hash instance, even on subclasses" do - klass = Class.new(Hash) - h = klass.new - h[:foo] = 42 - r = h.transform_keys{|v| :"x#{v}"} - r.keys.should == [:xfoo] - r.class.should == Hash - end + it "returns a Hash instance, even on subclasses" do + klass = Class.new(Hash) + h = klass.new + h[:foo] = 42 + r = h.transform_keys{|v| :"x#{v}"} + r.keys.should == [:xfoo] + r.class.should == Hash end +end - describe "Hash#transform_keys!" do - before :each do - @hash = { a: 1, b: 2, c: 3, d: 4 } - @initial_pairs = @hash.dup - end +describe "Hash#transform_keys!" do + before :each do + @hash = { a: 1, b: 2, c: 3, d: 4 } + @initial_pairs = @hash.dup + end - it "returns self" do - @hash.transform_keys!(&:succ).should equal(@hash) - end + it "returns self" do + @hash.transform_keys!(&:succ).should equal(@hash) + end - it "updates self as transformed values with the given block" do - @hash.transform_keys!(&:to_s) - @hash.should == { 'a' => 1, 'b' => 2, 'c' => 3, 'd' => 4 } - end + it "updates self as transformed values with the given block" do + @hash.transform_keys!(&:to_s) + @hash.should == { 'a' => 1, 'b' => 2, 'c' => 3, 'd' => 4 } + 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 + # 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 + 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 } + 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 + end - ruby_version_is "2.5.1" do - it "returns the processed keys if we broke from the block" do - @hash.transform_keys! do |v| - break if v == :c - v.succ - end - @hash.should == { b: 1, c: 2 } + ruby_version_is "2.5.1" do + it "returns the processed keys if we broke from the block" do + @hash.transform_keys! do |v| + break if v == :c + v.succ end + @hash.should == { b: 1, c: 2 } end + end - it "keeps later pair if new keys conflict" do - @hash.transform_keys! { |_| :a }.should == { a: 4 } - end + it "keeps later pair if new keys conflict" do + @hash.transform_keys! { |_| :a }.should == { a: 4 } + end - context "when no block is given" do - it "returns a sized Enumerator" do - enumerator = @hash.transform_keys! - enumerator.should be_an_instance_of(Enumerator) - enumerator.size.should == @hash.size - enumerator.each(&:upcase).should == { A: 1, B: 2, C: 3, D: 4 } - end + context "when no block is given" do + it "returns a sized Enumerator" do + enumerator = @hash.transform_keys! + enumerator.should be_an_instance_of(Enumerator) + enumerator.size.should == @hash.size + enumerator.each(&:upcase).should == { A: 1, B: 2, C: 3, D: 4 } end + end - describe "on frozen instance" do - before :each do - @hash.freeze - end + describe "on frozen instance" do + before :each do + @hash.freeze + end - it "raises a FrozenError on an empty hash" do - ->{ {}.freeze.transform_keys!(&:upcase) }.should raise_error(FrozenError) - end + it "raises a FrozenError on an empty hash" do + ->{ {}.freeze.transform_keys!(&:upcase) }.should raise_error(FrozenError) + end - it "keeps pairs and raises a FrozenError" do - ->{ @hash.transform_keys!(&:upcase) }.should raise_error(FrozenError) - @hash.should == @initial_pairs - end + it "keeps pairs and raises a FrozenError" do + ->{ @hash.transform_keys!(&:upcase) }.should raise_error(FrozenError) + @hash.should == @initial_pairs + end - context "when no block is given" do - it "does not raise an exception" do - @hash.transform_keys!.should be_an_instance_of(Enumerator) - end + context "when no block is given" do + it "does not raise an exception" do + @hash.transform_keys!.should be_an_instance_of(Enumerator) end end end -- cgit v1.2.3