Sha256: f33d4c0cacb4a3efdbe5e9fa5e8d22e93915d794ada0d9f93a64e3ec7532322e
Contents?: true
Size: 978 Bytes
Versions: 1
Compression:
Stored size: 978 Bytes
Contents
# frozen_string_literal: true require 'spec_helper' describe Hash do describe 'yard' do describe '#chain_fetch' do subject(:hash) do { a: { b: { c: 1, d: 2 } } } end context 'when requesting keys that exist' do it 'returns the value found' do expect(hash.chain_fetch(:a, :b, :c)).to eq(1) end end context 'when key is not found' do context 'when no block is given' do it do expect { hash.chain_fetch(:a, :c, :d) }.to raise_error(KeyError) end end context 'when a block is given' do it do expect { hash.chain_fetch(:a, :c, :d) { 10 } }.not_to raise_error end it 'returns the result of the block' do result = hash.chain_fetch(:a, :c, :d) { |*args| args } expect(result).to eq([:c, [:d]]) end end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
darthjee-core_ext-1.7.4 | spec/integration/yard/darthjee/core_ext/hash_spec.rb |