File: array_spec.rb

package info (click to toggle)
ruby-hashie 5.0.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 884 kB
  • sloc: ruby: 7,049; sh: 8; makefile: 6
file content (29 lines) | stat: -rw-r--r-- 728 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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