Skip to content

separate TypeError cases on dig #172

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 12, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions core/hash/dig_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,19 @@ def obj.dig(*args); [ 42 ] end

h.dig(:foo, 0, :bar).should == [ 1 ]
h.dig(:foo, 0, :bar, 0).should == 1
lambda { h.dig(:foo, 0, :bar, 0, 0) }.should raise_error(TypeError)
h.dig(:foo, 1, 1).should == 'str'
lambda { h.dig(:foo, 1, 1, 0) }.should raise_error(TypeError)
# MRI does not recurse values returned from `obj.dig`
h.dig(:foo, 1, 0, 0).should == [ 42 ]
h.dig(:foo, 1, 0, 0, 10).should == [ 42 ]
end

it "raises TypeError if an intermediate element does not respond to #dig" do
h = {}
h[:foo] = [ { :bar => [ 1 ] }, [ nil, 'str' ] ]
lambda { h.dig(:foo, 0, :bar, 0, 0) }.should raise_error(TypeError)
lambda { h.dig(:foo, 1, 1, 0) }.should raise_error(TypeError)
end

it "calls #dig on the result of #[] with the remaining arguments" do
h = { foo: { bar: { baz: 42 } } }
h[:foo].should_receive(:dig).with(:bar, :baz).and_return(42)
Expand Down