Sha256: 94364494d89d0339cf4407137e2debd4a3506e9392145abcc0e41631348588ba

Contents?: true

Size: 1.12 KB

Versions: 9

Compression:

Stored size: 1.12 KB

Contents

require File.dirname(__FILE__)+'/../spec_helper'
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

9 entries across 9 versions & 1 rubygems

Version Path
gorillib-0.1.7 spec/array/extract_options_spec.rb
gorillib-0.1.6 spec/array/extract_options_spec.rb
gorillib-0.1.5 spec/array/extract_options_spec.rb
gorillib-0.1.4 spec/array/extract_options_spec.rb
gorillib-0.1.3 spec/array/extract_options_spec.rb
gorillib-0.1.2 spec/array/extract_options_spec.rb
gorillib-0.1.1 spec/array/extract_options_spec.rb
gorillib-0.1.0 spec/array/extract_options_spec.rb
gorillib-0.0.8 spec/array/extract_options_spec.rb