We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 5f4adfd commit 93ddb64Copy full SHA for 93ddb64
core/hash/dig_spec.rb
@@ -29,14 +29,19 @@ def obj.dig(*args); [ 42 ] end
29
30
h.dig(:foo, 0, :bar).should == [ 1 ]
31
h.dig(:foo, 0, :bar, 0).should == 1
32
- lambda { h.dig(:foo, 0, :bar, 0, 0) }.should raise_error(TypeError)
33
h.dig(:foo, 1, 1).should == 'str'
34
- lambda { h.dig(:foo, 1, 1, 0) }.should raise_error(TypeError)
35
# MRI does not recurse values returned from `obj.dig`
36
h.dig(:foo, 1, 0, 0).should == [ 42 ]
37
h.dig(:foo, 1, 0, 0, 10).should == [ 42 ]
38
end
39
+ it "raises TypeError if an intermediate element does not respond to #dig" do
+ 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
+
45
it "calls #dig on the result of #[] with the remaining arguments" do
46
h = { foo: { bar: { baz: 42 } } }
47
h[:foo].should_receive(:dig).with(:bar, :baz).and_return(42)
0 commit comments