Sha256: e33991ea0ce7f66d9571787da9eb2a079a1ff2160265ee5ab5912988610aec9e

Contents?: true

Size: 1.32 KB

Versions: 1

Compression:

Stored size: 1.32 KB

Contents

require 'spec_helper'

describe "Hash" do
  describe "#inner_merge" do
    it "should do a deep merge for new keys and deep override for existing keys" do
      hash1 = {
        'key1' => 'value1',
        'key2' => {
          'inner_key1' =>'inner_value1',
          'inner_key2' =>'inner_value2'
        }
      }
      hash2 = {
        'key_to_merge' => 'value_to_merge',
        'key2' => {
          'inner_key_to_be_merged' =>'inner_value_to_be_merged',
          'inner_key2' =>'inner_value_to_override'
        }
      }
      hash1.inner_merge(hash2).should == {
        "key1"=>"value1",
        "key2"=>{
          "inner_key1"=>"inner_value1",
          "inner_key2"=>"inner_value_to_override",
          "inner_key_to_be_merged"=>"inner_value_to_be_merged"
        },
        "key_to_merge"=>"value_to_merge"
      }
    end
  end
  describe "#delete_nil" do
    it "should delete keys which have nil values recursively" do
      hash = {
        'key1' => 'value1',
        'key2' => {
          'inner_key1' =>'inner_value1',
          'inner_key2' =>nil
        },
        'key3' => nil,
        'key4' => {
          'key5' => nil
        }
      }
      hash.delete_nil.should == {
        'key1' => 'value1',
        'key2' => {
          'inner_key1' =>'inner_value1'
        },
        'key4' => {}
      }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cloudster-2.20.0 spec/hash_additions.rb