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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
require 'spec_helper'
describe Immutable::Vector do
let(:vector) { V[*values] }
describe '#any?' do
let(:any?) { vector.any?(&block) }
context 'when created with no values' do
let(:values) { [] }
context 'with a block' do
let(:block) { ->(item) { item + 1 } }
it 'returns false' do
expect(any?).to be(false)
end
end
context 'with a block' do
let(:block) { nil }
it 'returns false' do
expect(any?).to be(false)
end
end
end
context 'when created with values' do
let(:values) { ['A', 'B', 3, nil] }
context 'with a block that returns true' do
let(:block) { ->(item) { item == 3 } }
it 'returns true' do
expect(any?).to be(true)
end
end
context "with a block that doesn't return true" do
let(:block) { ->(item) { item == 'D' } }
it 'returns false' do
expect(any?).to be(false)
end
end
context 'without a block' do
let(:block) { nil }
context 'with some values that are truthy' do
let(:values) { [nil, false, 'B'] }
it 'returns true' do
expect(any?).to be(true)
end
end
context 'with all values that are falsey' do
let(:values) { [nil, false] }
it 'returns false' do
expect(any?).to be(false)
end
end
end
end
end
end
|