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
|
require 'spec_helper'
describe Immutable::Vector do
let(:vector) { V[*values] }
describe '#inspect' do
let(:inspect) { vector.inspect }
shared_examples 'checking output' do
it 'returns its contents as a programmer-readable string' do
expect(inspect).to eq(output)
end
it "returns a string which can be eval'd to get back an equivalent vector" do
expect(eval(inspect)).to eql(vector)
end
end
context 'with an empty array' do
let(:output) { 'Immutable::Vector[]' }
let(:values) { [] }
include_examples 'checking output'
end
context 'with a single item array' do
let(:output) { 'Immutable::Vector["A"]' }
let(:values) { %w[A] }
include_examples 'checking output'
end
context 'with a multi-item array' do
let(:output) { 'Immutable::Vector["A", "B"]' }
let(:values) { %w[A B] }
include_examples 'checking output'
end
context 'from a subclass' do
MyVector = Class.new(Immutable::Vector)
let(:vector) { MyVector.new(values) }
let(:output) { 'MyVector[1, 2]' }
let(:values) { [1, 2] }
include_examples 'checking output'
end
end
end
|