Sha256: f18f3f67bf642831e5e8318a8a4089714451e40146a52866c911fe1b3e910fbc

Contents?: true

Size: 1.44 KB

Versions: 124

Compression:

Stored size: 1.44 KB

Contents

# frozen_string_literal: true

RSpec.describe :merge do
  link :merge, from: :ree_hash

  context "deep" do
    it {
      first_hash = {:name => "John", :pets => { :dog => "Dog"}}
      other_hash = {:name => "Steven", :pets => { :cat => "Cat"}}
      merged_hash = {:name => "Steven", :pets => { :dog => "Dog", :cat => "Cat"}}
      result = merge(first_hash, other_hash)

      expect(result).to eq(merged_hash)
      expect(result.object_id).to_not eq(first_hash.object_id)
      expect(result.object_id).to_not eq(other_hash.object_id)
    }
  end

  context "deep = false" do
    it {
      first_hash = {:name => "John", :pets => { :dog => "Dog"}}
      other_hash = {:name => "Steven", :pets => { :cat => "Cat"}}
      merged_hash = {:name => "Steven", :pets => { :cat => "Cat"}}
      result =  merge(first_hash, other_hash, deep: false)

      expect(result).to eq(merged_hash)
      expect(result.object_id).to_not eq(first_hash.object_id)
      expect(result.object_id).to_not eq(other_hash.object_id)
    }
  end

  context "with block" do
    it {
      first_hash = {:name => "John", :pets => { :dog => "Dog"}}
      other_hash = {:name => "Steven", :pets => { :cat => "Cat"}}
      merged_hash = {:name => "John", :pets => { :dog => "Dog", :cat => "Cat"}}

      result =  merge(first_hash, other_hash) do |key, first_val, other_val|
        if first_val == "John"
          "John"
        end
      end

      expect(result).to eq(merged_hash)
    }
  end
end

Version data entries

124 entries across 124 versions & 1 rubygems

Version Path
ree_lib-1.0.124 lib/ree_lib/packages/ree_hash/spec/ree_hash/functions/merge_spec.rb
ree_lib-1.0.123 lib/ree_lib/packages/ree_hash/spec/ree_hash/functions/merge_spec.rb
ree_lib-1.0.122 lib/ree_lib/packages/ree_hash/spec/ree_hash/functions/merge_spec.rb
ree_lib-1.0.121 lib/ree_lib/packages/ree_hash/spec/ree_hash/functions/merge_spec.rb
ree_lib-1.0.120 lib/ree_lib/packages/ree_hash/spec/ree_hash/functions/merge_spec.rb
ree_lib-1.0.119 lib/ree_lib/packages/ree_hash/spec/ree_hash/functions/merge_spec.rb
ree_lib-1.0.118 lib/ree_lib/packages/ree_hash/spec/ree_hash/functions/merge_spec.rb
ree_lib-1.0.117 lib/ree_lib/packages/ree_hash/spec/ree_hash/functions/merge_spec.rb
ree_lib-1.0.116 lib/ree_lib/packages/ree_hash/spec/ree_hash/functions/merge_spec.rb
ree_lib-1.0.115 lib/ree_lib/packages/ree_hash/spec/ree_hash/functions/merge_spec.rb
ree_lib-1.0.114 lib/ree_lib/packages/ree_hash/spec/ree_hash/functions/merge_spec.rb
ree_lib-1.0.113 lib/ree_lib/packages/ree_hash/spec/ree_hash/functions/merge_spec.rb
ree_lib-1.0.112 lib/ree_lib/packages/ree_hash/spec/ree_hash/functions/merge_spec.rb
ree_lib-1.0.111 lib/ree_lib/packages/ree_hash/spec/ree_hash/functions/merge_spec.rb
ree_lib-1.0.110 lib/ree_lib/packages/ree_hash/spec/ree_hash/functions/merge_spec.rb
ree_lib-1.0.109 lib/ree_lib/packages/ree_hash/spec/ree_hash/functions/merge_spec.rb
ree_lib-1.0.108 lib/ree_lib/packages/ree_hash/spec/ree_hash/functions/merge_spec.rb
ree_lib-1.0.107 lib/ree_lib/packages/ree_hash/spec/ree_hash/functions/merge_spec.rb
ree_lib-1.0.106 lib/ree_lib/packages/ree_hash/spec/ree_hash/functions/merge_spec.rb
ree_lib-1.0.105 lib/ree_lib/packages/ree_hash/spec/ree_hash/functions/merge_spec.rb