Sha256: e69dd56110a2a863a8a59eef8bb19cb890182967c814467fc0902140da40bea4
Contents?: true
Size: 1.34 KB
Versions: 5
Compression:
Stored size: 1.34 KB
Contents
require 'spec_helper' describe 'Cistern::Hash' do describe '#slice' do let(:input) do { one: 'one', two: 'two', three: 'three' } end it 'returns a new hash with only the specified keys' do expect(Cistern::Hash.slice(input, :one, :two)).to eq(one: 'one', two: 'two') end it "skips keys that aren't in the original hash" do expect(Cistern::Hash.slice(input, :four)).to eq({}) end end describe '#except' do let(:input) do { one: 'one', two: 'two', three: 'three' } end it 'returns a new hash without the specified keys' do expect(Cistern::Hash.except(input, :one, :two)).to eq(three: 'three') end it "skips keys that aren't in the original hash" do expect(Cistern::Hash.except(input, :four)).to eq(input) end end describe '#stringify_keys' do let(:input) do { one: 'one', two: 'two' } end it 'returns a new hash with stringed keys' do expect(Cistern::Hash.stringify_keys(input)).to eq('one' => 'one', 'two' => 'two') end context 'with nested hashes or arrays' do let(:input) do { hash: { one: 'one' }, array: [{ two: 'two' }] } end it 'stringifies all of the keys' do expect(Cistern::Hash.stringify_keys(input)).to eq('hash' => { 'one' => 'one' }, 'array' => [{ 'two' => 'two' }]) end end end end
Version data entries
5 entries across 5 versions & 1 rubygems
Version | Path |
---|---|
cistern-2.3.0 | spec/hash_spec.rb |
cistern-2.2.7 | spec/hash_spec.rb |
cistern-2.2.6 | spec/hash_spec.rb |
cistern-2.2.5 | spec/hash_spec.rb |
cistern-2.2.4 | spec/hash_spec.rb |