Sha256: 76ee9518888e87217fb7449779ad8781a14495a762e5afe6818adc78e8552f76
Contents?: true
Size: 999 Bytes
Versions: 2
Compression:
Stored size: 999 Bytes
Contents
# frozen_string_literal: true describe Darthjee::CoreExt::Hash::ChainFetcher do let(:hash) do { a: { b: { c: 1, d: 2 } } } end context 'when not giving a block' do subject(:fetcher) do described_class.new(hash, *keys) end context 'when keys are found' do let(:keys) { %i[a b c] } it 'returns the value found' do expect(fetcher.fetch).to eq(1) end end context 'when key is not found' do let(:keys) { %i[a c d] } it do expect { fetcher.fetch }.to raise_error(KeyError) end end end context 'when giving a block' do subject(:fetcher) do described_class.new(hash, *keys) { |*args| args } end context 'when keys are not found' do let(:keys) { %i[a c d] } it do expect { fetcher.fetch }.not_to raise_error end it 'returns the result of the block' do expect(fetcher.fetch).to eq([:c, [:d]]) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
darthjee-core_ext-2.0.0 | spec/integration/yard/darthjee/core_ext/hash/chain_fetcher_spec.rb |
darthjee-core_ext-1.7.4 | spec/integration/yard/darthjee/core_ext/hash/chain_fetcher_spec.rb |