Sha256: 259de70d5e7cc3acc698c0744141837cf07784d9f800d113d40cad74e85e9961
Contents?: true
Size: 1.98 KB
Versions: 11
Compression:
Stored size: 1.98 KB
Contents
# frozen_string_literal: true require 'spec_helper' describe Arstotzka::Crawler do describe 'yard' do subject(:crawler) do described_class.new(full_path: full_path, **options) end let(:options) { {} } let(:keys) { %w[person information first_name] } let(:full_path) { keys.join('.') } let(:hash) do { person: { 'information' => { 'firstName' => 'John' } } } end it 'crawls to find the value' do expect(crawler.value(hash)).to eq('John') end describe '#value' do context 'when hash contains the keys' do it 'crawls to find the value' do expect(crawler.value(hash)).to eq('John') end end context 'when we have an array of arrays' do let(:keys) { %w[companies games hero_name] } let(:options) { { compact: true, case: :snake } } let(:hash) do { 'companies' => [{ name: 'Lucas Pope', games: [{ 'name' => 'papers, please' }, { 'name' => 'TheNextBigThing', hero_name: 'Rakhar' }] }, { name: 'Old Company' }] } end it 'crawls to find the value' do expect(crawler.value(hash)).to eq([['Rakhar']]) end context 'with default value' do let(:options) { { compact: true, case: :snake, default: 'NO HERO' } } it 'return default value for missed keys' do expect(crawler.value(hash)).to eq([['NO HERO', 'Rakhar'], 'NO HERO']) end end context 'when block is given' do subject(:crawler) do described_class.new(full_path: full_path, **options) { |value| value&.to_sym } end it 'returns the post processed values' do expect(crawler.value(hash)).to eq([[:Rakhar]]) end end end end end end
Version data entries
11 entries across 11 versions & 1 rubygems