Sha256: c10e1ae5d06e62ed784da6c067abd2693eb0c1633e37e3a13d4415aadfe146f2

Contents?: true

Size: 1.23 KB

Versions: 5

Compression:

Stored size: 1.23 KB

Contents

require 'spec_helper'
require 'gorillib/hash/deep_compact'
require 'gorillib/array/deep_compact'

describe Hash, :hashlike_spec do
  describe 'array/deep_compact and hash/deep_compact' do
    it "should respond to the method deep_compact!" do
      { }.should respond_to :deep_compact!
    end

    it "should return nil if all values evaluate as blank" do
      { :a => nil, :b => "", :c => [], :d => {} }.deep_compact!.should == {}
    end

    it "should return a hash with all blank values removed recursively" do
      @test_hash = {:e => ["", nil, [], {}, "foo", { :a => [nil, {}, { :c => ["","",[]] } ], :b => nil }]}
      @test_hash.deep_compact!.should == {:e=>["foo"]}
    end
  end
end

describe Array, :hashlike_spec do
  describe 'array/deep_compact and hash/deep_compact' do
    it "should respond to the method deep_compact!" do
      [ ].should respond_to :deep_compact!
    end

    it "should return nil if all values evaluate as blank" do
      [nil, '', { }, []].deep_compact!.should == []
    end

    it "should return a hash with all blank values removed recursively" do
      @test_arr = ["", nil, [], {}, "foo", { :a=> [nil, {}, { :c=> ["","",[]] } ], :b => nil }]
      @test_arr.deep_compact!.should == ["foo"]
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
gorillib-0.6.0 spec/gorillib/hash/deep_compact_spec.rb
gorillib-0.5.2 spec/gorillib/hash/deep_compact_spec.rb
gorillib-0.5.0 spec/gorillib/hash/deep_compact_spec.rb
gorillib-0.4.2 spec/gorillib/hash/deep_compact_spec.rb
gorillib-0.4.2pre spec/gorillib/hash/deep_compact_spec.rb