Sha256: e6679275d388af6e3d395d91382220dd73bb0e1a922ff5a501005a3b9d59cd7c

Contents?: true

Size: 1.63 KB

Versions: 32

Compression:

Stored size: 1.63 KB

Contents

require 'spec_helper'

describe Hash do
    let( :with_symbols ) do
        {
            stuff: 'blah',
            more: {
                stuff: {
                    blah: 'stuff'
                }
            }
        }
    end

    let( :with_strings ) do
        {
            'stuff' => 'blah',
            'more'  => {
                'stuff' => {
                    'blah' => 'stuff'
                }
            }
        }
    end

    describe '#my_stringify_keys' do
        it 'recursively converts keys to strings' do
            expect(with_symbols.my_stringify_keys).to eq(with_strings)
        end

        context 'when the recursive is set to false' do
            it 'only converts the keys at depth 1' do
                expect(with_symbols.my_stringify_keys( false )).to eq({
                    'stuff' => 'blah',
                    'more'  => {
                        stuff: {
                            blah: 'stuff'
                        }
                    }
                })
            end
        end
    end

    describe '#my_symbolize_keys' do
        it 'recursively converts keys to symbols' do
            expect(with_strings.my_symbolize_keys).to eq(with_symbols)
        end

        context 'when the recursive is set to false' do
            it 'only converts the keys at depth 1' do
                expect(with_strings.my_symbolize_keys( false )).to eq({
                    stuff: 'blah',
                    more:  {
                        'stuff' => {
                            'blah' => 'stuff'
                        }
                    }
                })
            end
        end
    end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
cuboid-0.2.11 spec/cuboid/ruby/hash_spec.rb
cuboid-0.2.10 spec/cuboid/ruby/hash_spec.rb
cuboid-0.2.9 spec/cuboid/ruby/hash_spec.rb
cuboid-0.2.8 spec/cuboid/ruby/hash_spec.rb
cuboid-0.2.7 spec/cuboid/ruby/hash_spec.rb
cuboid-0.2.6 spec/cuboid/ruby/hash_spec.rb
cuboid-0.2.5 spec/cuboid/ruby/hash_spec.rb
cuboid-0.2.4.2 spec/cuboid/ruby/hash_spec.rb
cuboid-0.2.4.1 spec/cuboid/ruby/hash_spec.rb
cuboid-0.2.4 spec/cuboid/ruby/hash_spec.rb
cuboid-0.2.3 spec/cuboid/ruby/hash_spec.rb
cuboid-0.2.2 spec/cuboid/ruby/hash_spec.rb
cuboid-0.2.1 spec/cuboid/ruby/hash_spec.rb
cuboid-0.2 spec/cuboid/ruby/hash_spec.rb
cuboid-0.1.9.1 spec/cuboid/ruby/hash_spec.rb
cuboid-0.1.9 spec/cuboid/ruby/hash_spec.rb
cuboid-0.1.8 spec/cuboid/ruby/hash_spec.rb
cuboid-0.1.7 spec/cuboid/ruby/hash_spec.rb
cuboid-0.1.6.1 spec/cuboid/ruby/hash_spec.rb
cuboid-0.1.6 spec/cuboid/ruby/hash_spec.rb