Sha256: 4df8fea93aaa8e547bebabc8d636a43990b835e492f82c996c3df76769593b44

Contents?: true

Size: 1.35 KB

Versions: 4

Compression:

Stored size: 1.35 KB

Contents

require 'spec_helper'

describe Miu::Utility do
  describe 'adapt' do
    X = Struct.new(:value)

    it 'adapted' do
      x = X.new(123)
      X.should_not_receive(:new)
      Miu::Utility.adapt(X, x)
    end

    it 'unadapted' do
      X.should_receive(:new).with(123)
      Miu::Utility.adapt(X, 123)
    end
  end

  describe 'extract_options!' do
    it 'with options' do
      args = [1, 2, 3, {:a => :b}]
      options = Miu::Utility.extract_options! args

      args.should == [1, 2, 3]
      options.should == {:a => :b}
    end

    it 'without options' do
      args = [1, 2, 3]
      options = Miu::Utility.extract_options! args

      args.should == [1, 2, 3]
      options.should == {}
    end
  end

  describe 'symbolize_keys' do
    it 'symbolize' do
      h1 = {'a' => 'b', :c => :d, 1 => 2}
      h2 = Miu::Utility.symbolize_keys h1
      h2.should == {:a => 'b', :c => :d, 1 => 2}
    end
  end

  describe 'underscorize_keys' do
    it 'underscorize' do
      h1 = {'a-b' => 1, 'a-b_c-d' => 2, :abc => 3}
      h2 = Miu::Utility.underscorize_keys h1
      h2.should == {'a_b' => 1, 'a_b_c_d' => 2, :abc => 3}
    end
  end

  describe 'optionify_keys' do
    it 'optionify' do
      h1 = {'a-b' => 1, 'a-b_c-d' => 2, :'a-b_c-d_e' => 3}
      h2 = Miu::Utility.optionify_keys h1
      h2.should == {:a_b => 1, :a_b_c_d => 2, :a_b_c_d_e => 3}
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
miu-0.2.3 spec/miu/utility_spec.rb
miu-0.2.2 spec/miu/utility_spec.rb
miu-0.2.1 spec/miu/utility_spec.rb
miu-0.2.0 spec/miu/utility_spec.rb