Sha256: e331f3d85e8c5ae277850a3a8cd2e3d0fc6a3d8c0bddf426027188839c6132e9

Contents?: true

Size: 878 Bytes

Versions: 2

Compression:

Stored size: 878 Bytes

Contents

require 'spec_helper'

require 'state_mate/adapters/defaults'

describe "StateMate::Adapters::Defaults.hash_deep_write!" do
  let(:defaults) {
    StateMate::Adapters::Defaults
  }

  it "does a basic set on an empty hash" do
    h = {}
    defaults.hash_deep_write! h, [:x], 1
    expect( h ).to eq({x: 1})
  end

  it "does a deep set on an empty hash" do
    h = {}
    defaults.hash_deep_write! h, [:x, :y], 1
    expect( h ).to eq({x: {y: 1}})
  end

  it "does a deep set on an non-empty hash" do
    h = {a: 1}
    defaults.hash_deep_write! h, [:x, :y], 1
    expect( h ).to eq({a: 1, x: {y: 1}})
  end

  it "clobbers values" do
    h = {x: [1, 2, 3]}
    defaults.hash_deep_write! h, [:x, :y], 1
    expect( h ).to eq({x: {y: 1}})
    
    h = {x: 'ex'}
    defaults.hash_deep_write! h, [:x, :y, :z], 1
    expect( h ).to eq({x: {y: {z: 1}}})
  end
end # hardware_uuid

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
state_mate-0.0.3 spec/state_mate/adapters/defaults/hash_deep_write_spec.rb
state_mate-0.0.2 spec/state_mate/adapters/defaults/hash_deep_write_spec.rb