Sha256: 459f0b2b1e56e913f831b740fd0c3f88580283533dcbf68bd63ef3ab9ba12ba0
Contents?: true
Size: 1.29 KB
Versions: 6
Compression:
Stored size: 1.29 KB
Contents
# frozen_string_literal: true require 'spec_helper' require 'overrides_tracker/hash_decorator' describe Hash do describe '#deep_merge' do let(:hash) { { a: 1, b: { c: 2 } } } let(:other_hash) { { a: 3, b: { d: 4 } } } it 'returns a new hash with the contents of both hashes merged' do expect(hash.deep_merge(other_hash)).to eq(a: 3, b: { c: 2, d: 4 }) end it 'does not modify the original hash' do expect { hash.deep_merge(other_hash) }.not_to change { hash } end end describe '#deep_merge!' do let(:hash) { { a: 1, b: { c: 2 } } } let(:other_hash) { { a: 3, b: { d: 4 } } } it 'modifies the original hash with the contents of the other hash merged' do expect { hash.deep_merge!(other_hash) }.to change { hash }.to(a: 3, b: { c: 2, d: 4 }) end end describe '#deep_stringify_keys!' do it 'converts all keys in a hash to strings' do hash = { a: 1, b: { c: 2, d: 3 } } hash.deep_stringify_keys! expect(hash).to eq({ 'a' => 1, 'b' => { 'c' => 2, 'd' => 3 } }) end it 'converts all keys in an array of hashes to strings' do array = { a: [{ a: 1, b: 2 }, { c: 3, d: 4 }] } array.deep_stringify_keys! expect(array).to eq({ 'a' => [{ 'a' => 1, 'b' => 2 }, { 'c' => 3, 'd' => 4 }] }) end end end
Version data entries
6 entries across 6 versions & 1 rubygems