Sha256: acc0c4c54c7f55c397b915ad897cdf18f125bcf9fd12f953ff5da2f6496274ae

Contents?: true

Size: 981 Bytes

Versions: 1

Compression:

Stored size: 981 Bytes

Contents

require 'spec_helper'

describe 'key_conversion' do

  it 'should convert keys to lowercase by default' do
    { 'HELLO' => 'world' }.convert_keys.should eq 'hello' => 'world'
  end

  it 'should convert the key to a string if it is a symbol' do
    { hello: "world" }.convert_keys.should eq 'hello' => 'world'
  end

  it 'should accept any method you can call on a string to convert the key' do
    { hello: "world" }.convert_keys(:upcase).should eq 'HELLO' => 'world'
  end

  it 'should convert nested hashes with the same logic' do
    { 'HELLO' => { 'MR' => 'world' } }.convert_keys.should eq 'hello' => {'mr' => 'world'}
  end

  it 'should be both an instance and class method' do
    Hash.new.should respond_to(:convert_keys)
    Hash.should respond_to(:convert_keys)
  end

  it 'should convert an array of hashes with the same logic' do
    Hash.convert_keys([{ 'HELLO' => 'world' }, { 'FOO' => 'bar' }]).should eq [{ 'hello' => 'world' }, { 'foo' => 'bar' }]
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hash-pipe-0.0.1 spec/hash-pipe/key_conversion_spec.rb