Sha256: 4dc2294ae4448a44b8c155879810371199bab3b527da8460800e798365fc7f68
Contents?: true
Size: 1.48 KB
Versions: 3
Compression:
Stored size: 1.48 KB
Contents
require 'spec_helper' describe WithFilters::HashExtraction do describe '#extract_hash_value(hash, key)' do let(:params) {{ 'fizz' => 'buzz', foo: 'bar', one: {'two' => {'three' => 3}} }} subject { class TestHashExtraction include WithFilters::HashExtraction end TestHashExtraction.new } context 'where a regular hash key is used' do context 'where the value is a Symbol' do it 'returns the value from the hash' do subject.extract_hash_value(params, :foo).should == params[:foo] subject.extract_hash_value(params, :fizz).should == params['fizz'] end end context 'where the value is a String' do it 'returns the value from the hash' do subject.extract_hash_value(params, 'foo').should == params[:foo] subject.extract_hash_value(params, 'fizz').should == params['fizz'] end end context 'where the value is not found' do it 'returns nil' do subject.extract_hash_value(params, 'yo').should be nil end end end context 'where a nested hash key is used' do it 'returns the value from the hash' do subject.extract_hash_value(params, 'one[two][three]').should == params[:one]['two']['three'] end context 'where the value is not found' do it 'returns nil' do subject.extract_hash_value(params, 'yo[one]').should be nil end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
with_filters-0.1.2 | spec/hash_extraction_spec.rb |
with_filters-0.1.1 | spec/hash_extraction_spec.rb |
with_filters-0.1.0 | spec/hash_extraction_spec.rb |