Sha256: c87205c241257259dfebcf3fb386fba3471c7d3ae303667d33941f24ec2f994b
Contents?: true
Size: 1.18 KB
Versions: 4
Compression:
Stored size: 1.18 KB
Contents
require 'spec_helper' require 'sugar-high/hash' describe "SugarHigh" do describe "Hash packet" do describe '#rewrite' do it 'should rewrite keys of the hash' do mapping = {:a => :new_a, :b => :new_b} {:a => 'hello', :b => 'hi', :c => 'hi'}.rewrite(mapping).should == {:new_a => 'hello', :new_b => 'hi', :c => 'hi'} end end describe '#hash_revert' do # The way 1.8.7 orders Hashes is really strange. It is hard to write straight expectation here it "should revert hash" do reverted_hash = {:a => 'hello', :b => 'hi', :c => 'hi'}.hash_revert reverted_hash['hello'].should == [:a] reverted_hash['hi'].should include :b, :c reverted_hash['hi'].size.should == 2 end it "should try keys in hash until triggered" do {:a => 'hello', :b => 'hi'}.try_keys([:x, :a, :b]).should == 'hello' end it "should return nil if no key triggered" do {:a => 'hello', :b => 'hi'}.try_keys([:x, :y, :z]).should == nil end it "should return nil if no key triggered" do {:a => 'hello', :b => 'hi'}.try_keys([:x, :y, :z], :default => 'none').should == 'none' end end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
sugar-high-0.7.3 | spec/sugar-high/hash_spec.rb |
sugar-high-0.7.2 | spec/sugar-high/hash_spec.rb |
sugar-high-0.7.1 | spec/sugar-high/hash_spec.rb |
sugar-high-0.7.0 | spec/sugar-high/hash_spec.rb |