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
|
require 'spec_helper'
describe Immutable::List do
[
[:sort, ->(left, right) { left.length <=> right.length }],
[:sort_by, ->(item) { item.length }],
].each do |method, comparator|
describe "##{method}" do
it 'is lazy' do
-> { Immutable.stream { fail }.send(method, &comparator) }.should_not raise_error
end
[
[[], []],
[['A'], ['A']],
[%w[Ichi Ni San], %w[Ni San Ichi]],
].each do |values, expected|
context "on #{values.inspect}" do
let(:list) { L[*values] }
context 'with a block' do
it 'preserves the original' do
list.send(method, &comparator)
list.should == L[*values]
end
it "returns #{expected.inspect}" do
list.send(method, &comparator).should == L[*expected]
end
end
context 'without a block' do
it 'preserves the original' do
list.send(method)
list.should eql(L[*values])
end
it "returns #{expected.sort.inspect}" do
list.send(method).should == L[*expected.sort]
end
end
end
end
end
end
end
|