1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
require 'spec_helper'
describe Immutable::List do
[:each_chunk, :each_slice].each do |method|
describe "##{method}" do
context 'on a really big list' do
it "doesn't run out of stack" do
-> { BigList.send(method, 1) { |item| } }.should_not raise_error
end
end
[
[[], []],
[['A'], [L['A']]],
[%w[A B C], [L['A', 'B'], L['C']]],
].each do |values, expected|
context "on #{values.inspect}" do
let(:list) { L[*values] }
context 'with a block' do
it 'preserves the original' do
list.should eql(L[*values])
end
it 'iterates over the items in order' do
yielded = []
list.send(method, 2) { |item| yielded << item }
yielded.should eql(expected)
end
it 'returns self' do
list.send(method, 2) { |item| item }.should be(list)
end
end
context 'without a block' do
it 'preserves the original' do
list.send(method, 2)
list.should eql(L[*values])
end
it 'returns an Enumerator' do
list.send(method, 2).class.should be(Enumerator)
list.send(method, 2).to_a.should eql(expected)
end
end
end
end
end
end
end
|