Sha256: 31d0186cfefd22046150308b43b708681fa18be30530bdc703dba1f34d5ac370

Contents?: true

Size: 1.14 KB

Versions: 3

Compression:

Stored size: 1.14 KB

Contents

require File.expand_path('../spec_helper', File.dirname(__FILE__))
require 'gorillib/array/extract_options'

class HashSubclass < Hash
end

class ExtractableHashSubclass < Hash
  def extractable_options?
    true
  end
end

describe Array do
  describe '#extract_options!' do
    it 'pulls empty hash from empty array' do
      [].extract_options!.should == {}
    end
    it 'pulls empty hash from array with no hash' do
      [1].extract_options!.should == {}
    end
    it 'pulls hash from array with only that hash' do
      [{:a=>:b}].extract_options!.should    == {:a=>:b}
    end
    it 'pulls hash from end of array' do
      [1, {:a=>:b}].extract_options!.should == {:a=>:b}
    end

    it 'does not extract hash subclasses' do
      hash = HashSubclass.new
      hash[:foo] = 1
      array = [hash]
      options = array.extract_options!
      options.should == {}
      array.should   == [hash]
    end

    it 'does extract extractable subclass' do
      hash = ExtractableHashSubclass.new
      hash[:foo] = 1
      array = [hash]
      options = array.extract_options!
      options.should == {:foo => 1}
      array.should   == []
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
gorillib-0.1.11 spec/array/extract_options_spec.rb
gorillib-0.1.9 spec/array/extract_options_spec.rb
gorillib-0.1.8 spec/array/extract_options_spec.rb