Sha256: 43de73ae1d25a1ad9ffdf17724bd71d7c290f54f05e75f48e2de28e0c749f791
Contents?: true
Size: 1.87 KB
Versions: 4
Compression:
Stored size: 1.87 KB
Contents
# frozen_string_literal: true require 'spec_helper' describe Darthjee::CoreExt::Hash::KeyChanger do let(:subject) { described_class.new(hash) } describe '#remap_keys!' do it_behaves_like 'a method that remaps the keys', :remap do it 'changes the original hash' do expect { result }.to(change { hash }) end end end describe '#underscore_keys' do let(:hash) { { keyUnderscore: 1 } } it 'underscore all the keys' do expect(subject.underscore_keys).to eq(key_underscore: 1) end context 'when hash is a many level hash' do let(:hash) { { keyUnderscore: { anotherKey: 1 } } } it 'underscore all the keys' do result = subject.underscore_keys expect(result).to eq(key_underscore: { another_key: 1 }) end end context 'when hash has an array' do let(:hash) { { keyUnderscore: [{ anotherKey: 1 }] } } it 'underscore all the keys' do result = { key_underscore: [{ another_key: 1 }] } expect(subject.underscore_keys).to eq(result) end end context 'changes the hash' do it 'underscore all the keys' do expect do subject.underscore_keys end.to(change { hash }) end end context 'when giving non recursive options' do context 'when hash is a many level hash' do let(:hash) { { keyUnderscore: { anotherKey: 1 } } } it 'underscore all the keys' do result = subject.underscore_keys(recursive: false) expect(result).to eq(key_underscore: { anotherKey: 1 }) end end context 'when hash has an array' do let(:hash) { { keyUnderscore: [{ anotherKey: 1 }] } } it 'underscore all the keys' do result = subject.underscore_keys(recursive: false) expect(result).to eq(key_underscore: [{ anotherKey: 1 }]) end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems