Sha256: 65f1d1b58705a30d2eeb82274806d8902e7361024cc8d942e0174957b9ee2904
Contents?: true
Size: 1.59 KB
Versions: 2
Compression:
Stored size: 1.59 KB
Contents
require 'spec_helper' describe Hashie::Extensions::KeyConversion do subject do klass = Class.new(Hash) klass.send :include, Hashie::Extensions::KeyConversion klass end let(:instance){ subject.new } describe '#stringify_keys!' do it 'should convert keys to strings' do instance[:abc] = 'abc' instance[123] = '123' instance.stringify_keys! (instance.keys & %w(abc 123)).size.should == 2 end it 'should return itself' do instance.stringify_keys!.should == instance end end describe '#stringify_keys' do it 'should convert keys to strings' do instance[:abc] = 'def' copy = instance.stringify_keys copy['abc'].should == 'def' end it 'should not alter the original' do instance[:abc] = 'def' copy = instance.stringify_keys instance.keys.should == [:abc] copy.keys.should == %w(abc) end end describe '#symbolize_keys!' do it 'should convert keys to symbols' do instance['abc'] = 'abc' instance['def'] = 'def' instance.symbolize_keys! (instance.keys & [:abc, :def]).size.should == 2 end it 'should return itself' do instance.symbolize_keys!.should == instance end end describe '#stringify_keys' do it 'should convert keys to strings' do instance['abc'] = 'def' copy = instance.symbolize_keys copy[:abc].should == 'def' end it 'should not alter the original' do instance['abc'] = 'def' copy = instance.symbolize_keys instance.keys.should == ['abc'] copy.keys.should == [:abc] end end end
Version data entries
2 entries across 2 versions & 2 rubygems
Version | Path |
---|---|
cb_hashie-2.0.0.beta | spec/hashie/extensions/key_conversion_spec.rb |
hashie-pre-2.0.0.beta | spec/hashie/extensions/key_conversion_spec.rb |