Sha256: 92f24a3e58ff859fcc9999f1e51c961e4cec082d1f9e55d17cb33f122210310b

Contents?: true

Size: 1.16 KB

Versions: 50

Compression:

Stored size: 1.16 KB

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/paths_hash'

RSpec.describe ::EacRubyUtils::PathsHash do
  describe '#[]' do
    let(:source_hash) do
      {
        parent: {
          child1: {
            child1_1: 'v1_1',
            child1_2: 'v1_2'
          },
          child2: 'v2'
        }
      }
    end
    let(:instance) { described_class.new(source_hash) }

    {
      'parent.child1.child1_1' => 'v1_1',
      'parent.child1.child1_2' => 'v1_2',
      'parent.child2' => 'v2',
      'no_exist' => nil,
      'parent.child1' => {
        child1_1: 'v1_1',
        child1_2: 'v1_2'
      }
    }.each do |entry_key, expected_value|
      it { expect(instance[entry_key]).to eq(expected_value) }
    end

    ['.only_suffix', '', '.', 'only_prefx.', 'empty..part'].each do |entry_key|
      it "invalid entry key \"#{entry_key}\" raises EntryKeyError" do
        expect { instance[entry_key] }.to raise_error(::EacRubyUtils::PathsHash::EntryKeyError)
      end
    end
  end

  describe '#[]=' do
    let(:instance) { described_class.new }

    before do
      instance['a.b.c'] = '123'
    end

    it { expect(instance.to_h).to eq(a: { b: { c: '123' } }) }
  end
end

Version data entries

50 entries across 50 versions & 2 rubygems

Version Path
avm-tools-0.72.0 vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/paths_hash_spec.rb
avm-tools-0.71.0 vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/paths_hash_spec.rb
avm-tools-0.70.2 vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/paths_hash_spec.rb
ehbrs-tools-0.15.0 vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/paths_hash_spec.rb
ehbrs-tools-0.14.1 vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/paths_hash_spec.rb
avm-tools-0.70.1 vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/paths_hash_spec.rb
avm-tools-0.70.0 vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/paths_hash_spec.rb
avm-tools-0.69.3 vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/paths_hash_spec.rb
ehbrs-tools-0.14.0 vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/paths_hash_spec.rb
avm-tools-0.69.2 vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/paths_hash_spec.rb
avm-tools-0.69.1 vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/paths_hash_spec.rb
avm-tools-0.69.0 vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/paths_hash_spec.rb
ehbrs-tools-0.13.1 vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/paths_hash_spec.rb
avm-tools-0.68.0 vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/paths_hash_spec.rb
avm-tools-0.67.0 vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/paths_hash_spec.rb
avm-tools-0.66.0 vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/paths_hash_spec.rb
avm-tools-0.65.0 vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/paths_hash_spec.rb
avm-tools-0.64.2 vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/paths_hash_spec.rb
avm-tools-0.64.1 vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/paths_hash_spec.rb
avm-tools-0.64.0 vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/paths_hash_spec.rb