Sha256: 1da36b0565b1dcf85e20b4df5e3c9f8357fafca2f67b58da036e3dc40d5726d4
Contents?: true
Size: 1.49 KB
Versions: 4
Compression:
Stored size: 1.49 KB
Contents
require 'rext/array' describe Array do describe "helpers" do before :each do @items = %w( some foo bar ) end describe "#from" do it "should return elements after the position specified" do @items.from(1).should == %w( foo bar ) end end describe "#to" do it "should return elements up to position" do @items.to(1).should == %w( some foo ) end end describe "#chunk" do it "should split an array into several containing the length of n" do (1..9).to_a.chunk(3).should == [[1,2,3], [4,5,6], [7,8,9]] end it "should accept a block, yielding each chunk" do chunks = [] (1..9).to_a.in_groups_of(3) do |chunk| chunks << chunk end chunks.should == [[1,2,3], [4,5,6], [7,8,9]] end it "should pad with nil by default" do (1..5).to_a.in_groups_of(4).should == [[1,2,3,4], [5,nil,nil,nil]] end it "should not padd when pad_with is false" do (1..6).to_a.in_groups_of(4, false).should == [[1,2,3,4], [5,6]] end end describe "#pad" do it "should pad with nil by default" do [1,2].pad(4).should == [1, 2, nil, nil] end it "should pad an with an object" do [1,2].pad(3 ,'x').should == [1, 2, 'x'] end it "should do nothing when the array is of expected length" do [1,2].pad(2).should == [1,2] end end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
visionmedia-rext-0.0.8 | spec/array_spec.rb |
visionmedia-rext-0.1.0 | spec/array_spec.rb |
visionmedia-rext-0.2.1 | spec/array_spec.rb |
visionmedia-rext-0.2.2 | spec/array_spec.rb |