Sha256: d13ad3580d4c46c98ca386109fe6296730005190b69f27c5f173f0fb959d7dc0

Contents?: true

Size: 1.49 KB

Versions: 10

Compression:

Stored size: 1.49 KB

Contents

require 'spec_helper'
require 'r10k/util/symbolize_keys'

describe R10K::Util::SymbolizeKeys do
  it "deletes all keys that are strings" do
    hash = {'foo' => 'bar', :baz => 'quux'}
    described_class.symbolize_keys!(hash)
    expect(hash).to_not have_key('foo')
  end

  it "replaces the deleted keys with interned strings" do
    hash = {'foo' => 'bar', :baz => 'quux'}

    described_class.symbolize_keys!(hash)
    expect(hash[:foo]).to eq 'bar'
  end

  it "raises an error if there is an existing symbol for a given string key" do
    hash = {'foo' => 'bar', :foo => 'quux'}

    expect {
      described_class.symbolize_keys!(hash)
    }.to raise_error(TypeError, /An existing interned key/)
  end

  it "does not modify existing symbol entries" do
    hash = {'foo' => 'bar', :baz => 'quux'}

    described_class.symbolize_keys!(hash)
    expect(hash[:baz]).to eq 'quux'
  end

  it "does not modify keys that are not strings or symbols" do
    key = %w[foo]
    hash = {key => 'bar', :baz => 'quux'}
    described_class.symbolize_keys!(hash)
    expect(hash[key]).to eq 'bar'
  end

  it "can recursively symbolize keys in nested hash values" do
    hash = {'foo' => {'bar' => 'baz'}}
    described_class.symbolize_keys!(hash, true)
    expect(hash).to eq({:foo => {:bar => 'baz'}})
  end

  it "recurses into hash values that had symbol keys" do
    hash = {:foo => {'bar' => {'baz' => 'quux'}}}
    described_class.symbolize_keys!(hash, true)
    expect(hash).to eq({:foo => {:bar => {:baz => 'quux'}}})
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
r10k-2.2.2 spec/unit/util/symbolize_keys_spec.rb
r10k-2.2.1 spec/unit/util/symbolize_keys_spec.rb
r10k-2.2.0 spec/unit/util/symbolize_keys_spec.rb
r10k-2.1.1 spec/unit/util/symbolize_keys_spec.rb
r10k-2.1.0 spec/unit/util/symbolize_keys_spec.rb
r10k-2.0.3 spec/unit/util/symbolize_keys_spec.rb
r10k-2.0.2 spec/unit/util/symbolize_keys_spec.rb
r10k-2.0.1 spec/unit/util/symbolize_keys_spec.rb
r10k-2.0.0 spec/unit/util/symbolize_keys_spec.rb
r10k-1.5.1 spec/unit/util/symbolize_keys_spec.rb