Sha256: 554490226232a2d16e2cf4d5f333ba473c3bd9c23c5cc1c68b8ff54138dd39b2

Contents?: true

Size: 1010 Bytes

Versions: 3

Compression:

Stored size: 1010 Bytes

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    
      it "should revert hash" do
        {:a => 'hello', :b => 'hi', :c => 'hi'}.hash_revert.should == {'hello' => [:a], 'hi' => [:b, :c]}
      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

3 entries across 3 versions & 1 rubygems

Version Path
sugar-high-0.6.3 spec/sugar-high/hash_spec.rb
sugar-high-0.6.2.1 spec/sugar-high/hash_spec.rb
sugar-high-0.6.1 spec/sugar-high/hash_spec.rb