summaryrefslogtreecommitdiff
path: root/spec/ruby/core/hash/shared/each.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/core/hash/shared/each.rb')
-rw-r--r--spec/ruby/core/hash/shared/each.rb41
1 files changed, 11 insertions, 30 deletions
diff --git a/spec/ruby/core/hash/shared/each.rb b/spec/ruby/core/hash/shared/each.rb
index b2483c8116..657c5d2c52 100644
--- a/spec/ruby/core/hash/shared/each.rb
+++ b/spec/ruby/core/hash/shared/each.rb
@@ -10,7 +10,7 @@ describe :hash_each, shared: true do
it "yields the key and value of each pair to a block expecting |key, value|" do
r = {}
h = { a: 1, b: 2, c: 3, d: 5 }
- h.send(@method) { |k,v| r[k.to_s] = v.to_s }.should equal(h)
+ h.send(@method) { |k,v| r[k.to_s] = v.to_s }.should.equal?(h)
r.should == { "a" => "1", "b" => "2", "c" => "3", "d" => "5" }
end
@@ -21,37 +21,18 @@ describe :hash_each, shared: true do
ary.sort.should == ["a", "b", "c"]
end
- ruby_version_is ""..."3.0" do
- it "yields 2 values and not an Array of 2 elements when given a callable of arity 2" do
- obj = Object.new
- def obj.foo(key, value)
- ScratchPad << key << value
- end
-
- ScratchPad.record([])
- { "a" => 1 }.send(@method, &obj.method(:foo))
- ScratchPad.recorded.should == ["a", 1]
-
- ScratchPad.record([])
- { "a" => 1 }.send(@method, &-> key, value { ScratchPad << key << value })
- ScratchPad.recorded.should == ["a", 1]
+ it "always yields an Array of 2 elements, even when given a callable of arity 2" do
+ obj = Object.new
+ def obj.foo(key, value)
end
- end
- ruby_version_is "3.0" do
- it "always yields an Array of 2 elements, even when given a callable of arity 2" do
- obj = Object.new
- def obj.foo(key, value)
- end
-
- -> {
- { "a" => 1 }.send(@method, &obj.method(:foo))
- }.should raise_error(ArgumentError)
+ -> {
+ { "a" => 1 }.send(@method, &obj.method(:foo))
+ }.should.raise(ArgumentError)
- -> {
- { "a" => 1 }.send(@method, &-> key, value { })
- }.should raise_error(ArgumentError)
- end
+ -> {
+ { "a" => 1 }.send(@method, &-> key, value { })
+ }.should.raise(ArgumentError)
end
it "yields an Array of 2 elements when given a callable of arity 1" do
@@ -72,7 +53,7 @@ describe :hash_each, shared: true do
-> {
{ "a" => 1 }.send(@method, &obj.method(:foo))
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
end
it "uses the same order as keys() and values()" do