Sha256: aea4c8acaffd0f814dd85c49ed9742775ac6de3e803c50e7df030afd945230b7

Contents?: true

Size: 1010 Bytes

Versions: 1

Compression:

Stored size: 1010 Bytes

Contents

# encoding: utf-8

require 'spec_helper'

describe Relation, '#one' do
  subject { object.one }

  let(:object) { described_class.new(header, body)             }
  let(:header) { Relation::Header.coerce([ [ :id, Integer ] ]) }

  context 'with a relation having no tuples' do
    let(:body) { LazyEnumerable.new }

    specify { expect { subject }.to raise_error(NoTuplesError, 'one tuple expected, but was an empty set') }

    specify { expect { subject }.to raise_error(SetSizeError) }
  end

  context 'with a relation having one tuple' do
    let(:body) { LazyEnumerable.new([ [ 1 ] ]) }

    it { should be_instance_of(Tuple) }

    it 'returns the expected tuple' do
      should == [ 1 ]
    end
  end

  context 'with a relation having many tuples' do
    let(:body) { LazyEnumerable.new([ [ 1 ], [ 2 ] ]) }

    specify { expect { subject }.to raise_error(ManyTuplesError, 'one tuple expected, but set contained 2 tuples') }

    specify { expect { subject }.to raise_error(SetSizeError) }
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
axiom-0.1.0 spec/unit/axiom/relation/one_spec.rb