Sha256: 5af451f3288e187b045f3f853909d5edb95f6430f348e9b75b20b88c070fa4c6

Contents?: true

Size: 1.21 KB

Versions: 14

Compression:

Stored size: 1.21 KB

Contents

describe "hash" do
  before do
    @hash_1 = { :a => "a", :b => "b", :c => { :c1 => "c1", :c2 => "c2", :c3 => { :d1 => "d1" } } }
    @hash_2 = { :a => 1, :c => { :c1 => 2, :c3 => { :d2 => "d2" } } }
  end
  
  describe "deep_merge" do
    it "should deep merge" do
      expected = { :a => 1, :b => "b", :c => { :c1 => 2, :c2 => "c2", :c3 => { :d1 => "d1", :d2 => "d2" } } }
      @hash_1.deep_merge(@hash_2).should == expected
    end
    
    it "should deep merge with block" do
      expected = { :a => [:a, "a", 1], :b => "b", :c => { :c1 => [:c1, "c1", 2], :c2 => "c2", :c3 => { :d1 => "d1", :d2 => "d2" } } }
      (@hash_1.deep_merge(@hash_2) { |k,o,n| [k, o, n] }).should == expected
    end
  end
  
  describe "deep_merge!" do
    it "should deep merge" do
      expected = { :a => 1, :b => "b", :c => { :c1 => 2, :c2 => "c2", :c3 => { :d1 => "d1", :d2 => "d2" } } }
      @hash_1.deep_merge!(@hash_2)
      @hash_1.should == expected
    end
    
    it "should deep merge with block" do
      expected = { :a => [:a, "a", 1], :b => "b", :c => { :c1 => [:c1, "c1", 2], :c2 => "c2", :c3 => { :d1 => "d1", :d2 => "d2" } } }
      @hash_1.deep_merge!(@hash_2) { |k,o,n| [k, o, n] }
      @hash_1.should == expected
    end
  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
motion-support-1.2.1 spec/motion-support/core_ext/hash/deep_merge_spec.rb
motion-support-1.1.1 spec/motion-support/core_ext/hash/deep_merge_spec.rb
motion-support-1.2.0 spec/motion-support/core_ext/hash/deep_merge_spec.rb
motion-support-1.1.0 spec/motion-support/core_ext/hash/deep_merge_spec.rb
motion-support-1.0.0 spec/motion-support/core_ext/hash/deep_merge_spec.rb
motion-support-0.3.0 spec/motion-support/core_ext/hash/deep_merge_spec.rb
motion_blender-support-0.2.8 spec/motion-support/core_ext/hash/deep_merge_spec.rb
motion_blender-support-0.2.7 spec/motion-support/core_ext/hash/deep_merge_spec.rb
motion-support-0.2.6 spec/motion-support/core_ext/hash/deep_merge_spec.rb
motion-support-0.2.5 spec/motion-support/core_ext/hash/deep_merge_spec.rb
motion-support-0.2.4 spec/motion-support/core_ext/hash/deep_merge_spec.rb
motion-support-0.2.3 spec/motion-support/core_ext/hash/deep_merge_spec.rb
motion-support-0.2.2 spec/motion-support/core_ext/hash/deep_merge_spec.rb
motion-support-0.2.0 spec/motion-support/core_ext/hash/deep_merge_spec.rb