Sha256: e933a53fa63020a981015408fbed609139284120d59120a2220879e4fb79f972
Contents?: true
Size: 1.4 KB
Versions: 3
Compression:
Stored size: 1.4 KB
Contents
require 'spec_helper' require 'gorillib/array/compact_blank' describe Array, :simple_spec do let(:blankish){ mock('blankish', :blank? => true) } let(:nonblank){ mock('nonblank', :blank? => false) } describe '#compact_blank' do it 'omits nils, like #compact' do arr = [nil] arr.compact_blank.should == [] arr.length.should == 1 end it "also omits false, {}, '' and anything else #blank\?" do arr = [nil, false, {}, "", blankish] arr.compact_blank.should == [] arr.length.should == 5 end it 'preserves non-blank elements' do arr = [nil, 1, nil, 2] arr.compact_blank.should == [1, 2] arr.length.should == 4 arr = [nil, 1, false, 2, {}, ""] arr.compact_blank.should == [1, 2] arr.length.should == 6 end end describe '#compact_blank!' do it 'removes nils in-place, like #compact!' do arr = [nil] arr.compact_blank!.should == [] arr.length.should == 0 end it "removes false, {}, '' and anything else #blank\?" do arr = [nil, false, {}, "", blankish] arr.compact_blank!.should == [] arr.length.should == 0 end it 'preserves non-blank elements' do arr = [nil, 1, nil, 2] arr.compact_blank!.should == [1, 2] arr.length.should == 2 arr = [nil, 1, false, 2, {}, ""] arr.compact_blank!.should == [1, 2] arr.length.should == 2 end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
gorillib-0.5.0 | spec/gorillib/array/compact_blank_spec.rb |
gorillib-0.4.2 | spec/gorillib/array/compact_blank_spec.rb |
gorillib-0.4.2pre | spec/gorillib/array/compact_blank_spec.rb |