Sha256: a82db03974703a8edf357a1f4876aff4204917eeeb4cf3eaac20c6925b76de7c
Contents?: true
Size: 1.85 KB
Versions: 3
Compression:
Stored size: 1.85 KB
Contents
# frozen_string_literal: true require 'spec_helper' describe 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
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
darthjee-core_ext-1.6.2 | spec/lib/hash/key_changer_spec.rb |
darthjee-core_ext-1.6.1 | spec/lib/hash/key_changer_spec.rb |
darthjee-core_ext-1.6.0 | spec/lib/hash/key_changer_spec.rb |