Sha256: 84c3dc6bf641f0b2ae8ab8d54ecd9c5a7b0efc7d9472ff033cab6973915f9ad9

Contents?: true

Size: 1.12 KB

Versions: 23

Compression:

Stored size: 1.12 KB

Contents

require 'spec_helper'

describe Hash do

  describe 'which is one level deep' do

    describe '#to_array' do

      it 'returns [] if key is not present in Hash' do
        {}.to_array(:a).should eql []
      end

      it 'returns [] if key is nil ' do
        { :a => nil }.to_array(:a).should eql []
      end

      it 'returns [value] if value is not an Array' do
        { :a => 1 }.to_array(:a).should eql [1]
      end

      it 'returns Array if value is an Array' do
        { :a => [1,2,3] }.to_array(:a).should eql [1,2,3]
      end

    end

  end

  describe 'which is two levels deep' do

    describe '#to_array' do

      it 'returns [] if key is not present in Hash' do
        { :a => {} }.to_array(:a, :b).should eql []
      end

      it 'returns [] if key is nil ' do
        { :a => { :b => nil } }.to_array(:a, :b).should eql []
      end

      it 'returns [value] if value is not an Array' do
        { :a => { :b => 1 } }.to_array(:a, :b).should eql [1]
      end

      it 'returns Array if value is an Array' do
        { :a => { :b => [1,2,3] } }.to_array(:a, :b).should eql [1,2,3]
      end

    end

  end

end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
ratis-3.4.3 spec/ratis/core_ext_spec.rb
ratis-3.4.2 spec/ratis/core_ext_spec.rb
ratis-3.4.1 spec/ratis/core_ext_spec.rb
ratis-3.4.0 spec/ratis/core_ext_spec.rb
ratis-3.3.7 spec/ratis/core_ext_spec.rb
ratis-3.3.6 spec/ratis/core_ext_spec.rb
ratis-3.3.5 spec/ratis/core_ext_spec.rb
ratis-3.3.4 spec/ratis/core_ext_spec.rb
ratis-3.3.3 spec/ratis/core_ext_spec.rb
ratis-3.3.2 spec/ratis/core_ext_spec.rb
ratis-3.3.1 spec/ratis/core_ext_spec.rb
ratis-3.3.0 spec/ratis/core_ext_spec.rb
ratis-3.2.1 spec/ratis/core_ext_spec.rb
ratis-3.2.0 spec/ratis/core_ext_spec.rb
ratis-3.1.8 spec/ratis/core_ext_spec.rb
ratis-3.1.7 spec/ratis/core_ext_spec.rb
ratis-3.1.6 spec/ratis/core_ext_spec.rb
ratis-3.1.5.1 spec/ratis/core_ext_spec.rb
ratis-3.1.5 spec/ratis/core_ext_spec.rb
ratis-3.1.4 spec/ratis/core_ext_spec.rb