Sha256: a0feaff4071e1091684f0796ea6f99f3a15f23e7b3a4895819ff85851dd6cbae

Contents?: true

Size: 728 Bytes

Versions: 3

Compression:

Stored size: 728 Bytes

Contents

require 'spec_helper'

describe Array do
  with_minimum_ruby('2.3.0') do
    describe '#dig' do
      let(:array) { Hashie::Array.new(%i[a b c]) }

      it 'works with a string index' do
        expect(array.dig('0')).to eq(:a)
      end

      it 'works with a numeric index' do
        expect(array.dig(1)).to eq(:b)
      end

      context 'when array is empty' do
        let(:array) { Hashie::Array.new([]) }

        it 'works with a first numeric and next string index' do
          expect(array.dig(0, 'hello')).to eq(nil)
        end

        it 'throws an error with first string and next numeric index' do
          expect { array.dig('hello', 0) }.to raise_error(TypeError)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
files.com-1.0.55 docs/vendor/bundle/ruby/2.5.0/gems/hashie-3.6.0/spec/hashie/array_spec.rb
hashie-4.0.0 spec/hashie/array_spec.rb
hashie-3.6.0 spec/hashie/array_spec.rb