Sha256: 68bd4124a487c2c8db865c0ac9a27097035d93d2ecc7d9a81b4e33b631349114

Contents?: true

Size: 1.67 KB

Versions: 2

Compression:

Stored size: 1.67 KB

Contents

require 'spec_helper'

describe Hash do
  before(:each) do
    @hash = { 'first_name' => 'Kenny',
              'last_name' => 'Rogers',
              'date_of_birth' => {'day' => 17,
                                  'month' => 'April',
                                  'year' => 1939 },
              'interests' => [ {'movie' => 'Birds',
                                'book' => 'Catch 22'},
                               "guitar",
                               {'song' => 'Leaving On a Jetplane'} ],
              :already_a_symbol => 'dummy' }
  end

  it "should symbolize keys, returning new hash" do
    new_hash = @hash.recursive_symbolize_keys
    new_hash.keys.size.should eql 5
    new_hash.keys.each { |k| k.should be_a Symbol }
    new_hash[:first_name].should eql 'Kenny'
    new_hash[:date_of_birth].should be_a Hash
    new_hash[:date_of_birth].keys.each { |k| k.should be_a Symbol }
    new_hash[:date_of_birth][:month].should eql 'April'
    new_hash[:interests].should be_a Array
    new_hash[:interests][0].keys.each { |k| k.should be_a Symbol }
    new_hash[:interests][0][:movie].should eql 'Birds'
  end

  # it "should symbolize keys in place, returning self" do
  #   @hash = @hash.recursive_symbolize_keys
  #   @hash.keys.size.should eql 5
  #   @hash.keys.each { |k| k.should be_a Symbol }
  #   @hash[:first_name].should eql 'Kenny'
  #   @hash[:date_of_birth].should be_a Hash
  #   @hash[:date_of_birth].keys.each { |k| k.should be_a Symbol }
  #   @hash[:date_of_birth][:month].should eql 'April'
  #   @hash[:interests].should be_a Array
  #   @hash[:interests][0].keys.each { |k| k.should be_a Symbol }
  #   @hash[:interests][0][:movie].should eql 'Birds'
  # end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
amee-data-abstraction-2.3.1 spec/core-extensions/hash_spec.rb
amee-data-abstraction-2.3.0 spec/core-extensions/hash_spec.rb