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.1.5 spec/cuboid/ruby/hash_spec.rb
cuboid-0.1.4 spec/cuboid/ruby/hash_spec.rb
cuboid-0.1.3 spec/cuboid/ruby/hash_spec.rb
cuboid-0.1.2 spec/cuboid/ruby/hash_spec.rb
cuboid-0.1.1 spec/cuboid/ruby/hash_spec.rb
cuboid-0.1.0 spec/cuboid/ruby/hash_spec.rb
cuboid-0.0.5 spec/cuboid/ruby/hash_spec.rb
cuboid-0.0.4 spec/cuboid/ruby/hash_spec.rb
cuboid-0.0.3 spec/cuboid/ruby/hash_spec.rb
cuboid-0.0.3alpha spec/cuboid/ruby/hash_spec.rb
cuboid-0.0.2alpha spec/cuboid/ruby/hash_spec.rb
cuboid-0.0.1alpha spec/cuboid/ruby/hash_spec.rb