Sha256: 09d751af6c465e257203e5332c29f63b1f6661f7a67c8048cd14405c5b41ba8a

Contents?: true

Size: 1.12 KB

Versions: 7

Compression:

Stored size: 1.12 KB

Contents

require 'spec_helper'
require 'gorillib/array/extract_options'

class HashSubclass < Hash
end

class ExtractableHashSubclass < Hash
  def extractable_options?
    true
  end
end

describe Array, :simple_spec => true 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

7 entries across 7 versions & 1 rubygems

Version Path
gorillib-0.6.0 spec/gorillib/array/extract_options_spec.rb
gorillib-0.5.2 spec/gorillib/array/extract_options_spec.rb
gorillib-0.5.0 spec/gorillib/array/extract_options_spec.rb
gorillib-0.4.2 spec/gorillib/array/extract_options_spec.rb
gorillib-0.4.2pre spec/gorillib/array/extract_options_spec.rb
gorillib-0.4.0pre spec/gorillib/array/extract_options_spec.rb
gorillib-0.4.1pre spec/gorillib/array/extract_options_spec.rb