Sha256: 589854f3791a15a90a070c410131f37bcdef3a6230ed09c6847a829354170480

Contents?: true

Size: 1.15 KB

Versions: 10

Compression:

Stored size: 1.15 KB

Contents

require 'spec_helper'

describe Hashie::Extensions::DeepFind do
  subject { Class.new(Hash) { include Hashie::Extensions::DeepFind } }
  let(:hash) do
    {
      library: {
        books: [
          { title: 'Call of the Wild' },
          { title: 'Moby Dick' }
        ],
        shelves: nil,
        location: {
          address: '123 Library St.',
          title: 'Main Library'
        }
      }
    }
  end
  let(:instance) { subject.new.update(hash) }

  describe '#deep_find' do
    it 'detects a value from a nested hash' do
      expect(instance.deep_find(:address)).to eq('123 Library St.')
    end

    it 'detects a value from a nested array' do
      expect(instance.deep_find(:title)).to eq('Call of the Wild')
    end

    it 'returns nil if it does not find a match' do
      expect(instance.deep_find(:wahoo)).to be_nil
    end
  end

  describe '#deep_find_all' do
    it 'detects all values from a nested hash' do
      expect(instance.deep_find_all(:title)).to eq(['Call of the Wild', 'Moby Dick', 'Main Library'])
    end

    it 'returns nil if it does not find any matches' do
      expect(instance.deep_find_all(:wahoo)).to be_nil
    end
  end
end

Version data entries

10 entries across 8 versions & 3 rubygems

Version Path
tdiary-4.2.1 vendor/bundle/ruby/2.2.0/gems/hashie-3.4.3/spec/hashie/extensions/deep_find_spec.rb
tdiary-4.2.1 vendor/bundle/ruby/2.3.0/gems/hashie-3.4.3/spec/hashie/extensions/deep_find_spec.rb
hashie-3.4.3 spec/hashie/extensions/deep_find_spec.rb
hashie-3.4.2 spec/hashie/extensions/deep_find_spec.rb
hashie-3.4.1 spec/hashie/extensions/deep_find_spec.rb
hashie-3.4.0 spec/hashie/extensions/deep_find_spec.rb
hashie-3.3.2 spec/hashie/extensions/deep_find_spec.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/hashie-3.3.1/spec/hashie/extensions/deep_find_spec.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/2.1.0/gems/hashie-3.3.1/spec/hashie/extensions/deep_find_spec.rb
hashie-3.3.1 spec/hashie/extensions/deep_find_spec.rb