-
Type:
Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
-
None
-
None
-
None
-
None
-
None
-
None
-
None
-
None
Example spec (https://github.com/matsimitsu/mongoid/blob/master/spec/mongoid/extensions/hash_spec.rb#L220)
ruby describe "#__nested__" do context "when the hash key is a string" do let(:hash) do { '100' => { 'name' => 'hundred' } } end let(:nested) do hash.__nested__('100.name') end it "should retrieve a nested value under the provided key" do nested.should eq 'hundred' end end context "when the hash key is an integer" do let(:hash) do { 100 => { 'name' => 'hundred' } } end let(:nested) do hash.__nested__('100.name') end it "should retrieve a nested value under the provided key" do nested.should eq 'hundred' end end end
result:
ruby
Mongoid::Extensions::Hash
#__nested__
when the hash key is a string
should retrieve a nested value under the provided key
when the hash key is an integer
should retrieve a nested value under the provided key (FAILED - 1)
Failures:
1) Mongoid::Extensions::Hash#__nested__ when the hash key is an integer should retrieve a nested value under the provided key
Failure/Error: hash.__nested__('100.name')
NoMethodError:
undefined method `[]' for nil:NilClass
# ./lib/mongoid/extensions/hash.rb:104:in `block in __nested__'
# ./lib/mongoid/extensions/hash.rb:103:in `each'
# ./lib/mongoid/extensions/hash.rb:103:in `__nested__'
# ./spec/mongoid/extensions/hash_spec.rb:245:in `block (4 levels) in <top (required)>'
# ./spec/mongoid/extensions/hash_spec.rb:249:in `block (4 levels) in <top (required)>'
Finished in 0.00824 seconds
2 examples, 1 failure