Sha256: c4ae74cf59361ad6ab0f98eca48a50d6852a2aad92f148078c5a8654ce162274

Contents?: true

Size: 865 Bytes

Versions: 5

Compression:

Stored size: 865 Bytes

Contents

require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

describe Hash do
  describe '#deep_merge' do
    it 'should not modify original hash' do
      h1 = {:a => 1, :b => 2}
      h2 = h1.deep_merge(:c => 3)
      h2.should_not == h1
      h2.should include(:c)
      h1.should_not include(:c)
    end

    it 'should merge non deep hash regularly' do
      h = {:a => 1, :b => 2}.deep_merge({:a => 3, :c => 4})
      h.should include(:a)
      h.should include(:c)
      h[:c].should == 4
      h[:a].should == 3
    end

    it 'should merge recursively' do
      h = {:a => 1, :b =>2, :c => {:c1 => 1, :c2 => 2}, :d => 4}.deep_merge(:b => 'bb', :c => {:c2 => 'cc'})
      h[:a].should == 1
      h[:b].should == 'bb'
      h[:c][:c1].should == 1
      h[:c][:c2].should == 'cc'
      h[:d].should == 4
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rego-ruby-ext-0.0.6 spec/hash_spec.rb
rego-ruby-ext-0.0.5 spec/hash_spec.rb
rego-ruby-ext-0.0.4 spec/hash_spec.rb
rego-ruby-ext-0.0.3 spec/hash_spec.rb
rego-ruby-ext-0.0.2 spec/hash_spec.rb