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.64 lib/ree_lib/packages/ree_hash/spec/ree_hash/functions/merge_spec.rb
ree_lib-1.0.63 lib/ree_lib/packages/ree_hash/spec/ree_hash/functions/merge_spec.rb
ree_lib-1.0.62 lib/ree_lib/packages/ree_hash/spec/ree_hash/functions/merge_spec.rb
ree_lib-1.0.61 lib/ree_lib/packages/ree_hash/spec/ree_hash/functions/merge_spec.rb
ree_lib-1.0.60 lib/ree_lib/packages/ree_hash/spec/ree_hash/functions/merge_spec.rb
ree_lib-1.0.59 lib/ree_lib/packages/ree_hash/spec/ree_hash/functions/merge_spec.rb
ree_lib-1.0.58 lib/ree_lib/packages/ree_hash/spec/ree_hash/functions/merge_spec.rb
ree_lib-1.0.57 lib/ree_lib/packages/ree_hash/spec/ree_hash/functions/merge_spec.rb
ree_lib-1.0.56 lib/ree_lib/packages/ree_hash/spec/ree_hash/functions/merge_spec.rb
ree_lib-1.0.55 lib/ree_lib/packages/ree_hash/spec/ree_hash/functions/merge_spec.rb
ree_lib-1.0.54 lib/ree_lib/packages/ree_hash/spec/ree_hash/functions/merge_spec.rb
ree_lib-1.0.53 lib/ree_lib/packages/ree_hash/spec/ree_hash/functions/merge_spec.rb
ree_lib-1.0.52 lib/ree_lib/packages/ree_hash/spec/ree_hash/functions/merge_spec.rb
ree_lib-1.0.51 lib/ree_lib/packages/ree_hash/spec/ree_hash/functions/merge_spec.rb
ree_lib-1.0.50 lib/ree_lib/packages/ree_hash/spec/ree_hash/functions/merge_spec.rb
ree_lib-1.0.49 lib/ree_lib/packages/ree_hash/spec/ree_hash/functions/merge_spec.rb
ree_lib-1.0.48 lib/ree_lib/packages/ree_hash/spec/ree_hash/functions/merge_spec.rb
ree_lib-1.0.47 lib/ree_lib/packages/ree_hash/spec/ree_hash/functions/merge_spec.rb
ree_lib-1.0.46 lib/ree_lib/packages/ree_hash/spec/ree_hash/functions/merge_spec.rb
ree_lib-1.0.45 lib/ree_lib/packages/ree_hash/spec/ree_hash/functions/merge_spec.rb