summaryrefslogtreecommitdiff
path: root/spec/ruby/core/hash/shift_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/core/hash/shift_spec.rb')
-rw-r--r--spec/ruby/core/hash/shift_spec.rb42
1 files changed, 32 insertions, 10 deletions
diff --git a/spec/ruby/core/hash/shift_spec.rb b/spec/ruby/core/hash/shift_spec.rb
index 9d43e640f5..ea36488a04 100644
--- a/spec/ruby/core/hash/shift_spec.rb
+++ b/spec/ruby/core/hash/shift_spec.rb
@@ -30,23 +30,45 @@ describe "Hash#shift" do
h.should == {}
end
- it "calls #default with nil if the Hash is empty" do
- h = {}
- def h.default(key)
- key.should == nil
- :foo
+ ruby_version_is '3.2' do
+ it "returns nil if the Hash is empty" do
+ h = {}
+ def h.default(key)
+ raise
+ end
+ h.shift.should == nil
+ end
+ end
+
+ ruby_version_is ''...'3.2' do
+ it "calls #default with nil if the Hash is empty" do
+ h = {}
+ def h.default(key)
+ key.should == nil
+ :foo
+ end
+ h.shift.should == :foo
end
- h.shift.should == :foo
end
it "returns nil from an empty hash" do
{}.shift.should == nil
end
- it "returns (computed) default for empty hashes" do
- Hash.new(5).shift.should == 5
- h = Hash.new { |*args| args }
- h.shift.should == [h, nil]
+ ruby_version_is '3.2' do
+ it "returns nil for empty hashes with defaults and default procs" do
+ Hash.new(5).shift.should == nil
+ h = Hash.new { |*args| args }
+ h.shift.should == nil
+ end
+ end
+
+ ruby_version_is ''...'3.2' do
+ it "returns (computed) default for empty hashes" do
+ Hash.new(5).shift.should == 5
+ h = Hash.new { |*args| args }
+ h.shift.should == [h, nil]
+ end
end
it "preserves Hash invariants when removing the last item" do