Skip to content

Commit 93ddb64

Browse files
committed
separate TypeError cases on dig
1 parent 5f4adfd commit 93ddb64

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

core/hash/dig_spec.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,19 @@ def obj.dig(*args); [ 42 ] end
2929

3030
h.dig(:foo, 0, :bar).should == [ 1 ]
3131
h.dig(:foo, 0, :bar, 0).should == 1
32-
lambda { h.dig(:foo, 0, :bar, 0, 0) }.should raise_error(TypeError)
3332
h.dig(:foo, 1, 1).should == 'str'
34-
lambda { h.dig(:foo, 1, 1, 0) }.should raise_error(TypeError)
3533
# MRI does not recurse values returned from `obj.dig`
3634
h.dig(:foo, 1, 0, 0).should == [ 42 ]
3735
h.dig(:foo, 1, 0, 0, 10).should == [ 42 ]
3836
end
3937

38+
it "raises TypeError if an intermediate element does not respond to #dig" do
39+
h = {}
40+
h[:foo] = [ { :bar => [ 1 ] }, [ nil, 'str' ] ]
41+
lambda { h.dig(:foo, 0, :bar, 0, 0) }.should raise_error(TypeError)
42+
lambda { h.dig(:foo, 1, 1, 0) }.should raise_error(TypeError)
43+
end
44+
4045
it "calls #dig on the result of #[] with the remaining arguments" do
4146
h = { foo: { bar: { baz: 42 } } }
4247
h[:foo].should_receive(:dig).with(:bar, :baz).and_return(42)

0 commit comments

Comments
 (0)