Sha256: 48694480f8ceebdb51e82016664c4955ae7ca360e3b694244d1d93d086765d51

Contents?: true

Size: 1.8 KB

Versions: 1

Compression:

Stored size: 1.8 KB

Contents

# encoding: utf-8

require 'spec_helper'

describe Evaluator::Context, '#add' do
  let(:attribute) { Attribute::Integer.new(:id)         }
  let(:header)    { Relation::Header.new([ attribute ]) }

  context 'when an aggregate is provided' do
    subject { described_class.new(header) { |object| object.add(:aggregate, aggregate) } }

    let(:aggregate) { attribute.sum }

    its(:functions) { should eql(Attribute::Integer.new(:aggregate) => aggregate) }

    it 'returns self' do
      subject.yield.equal?(subject).should be(true)
    end
  end

  context 'when a function is provided' do
    subject { described_class.new(header) { |object| object.add(:function, function) } }

    let(:function) { attribute.add(attribute) }

    its(:functions) { should eql(Attribute::Integer.new(:function) => function) }

    it 'returns self' do
      subject.yield.equal?(subject).should be(true)
    end
  end

  context 'when a proc is provided' do
    subject { described_class.new(header) { |object| object.add(:proc, proc) } }

    let(:proc) { Proc.new {} }

    its(:functions) { should eql(Attribute::Object.new(:proc) => proc) }

    it 'returns self' do
      subject.yield.equal?(subject).should be(true)
    end
  end

  context 'when a block is provided' do
    subject { described_class.new(header) { |object| object.add(:block, &block) } }

    let(:block) { proc {} }

    its(:functions) { should eql(Attribute::Object.new(:block) => block) }

    it 'returns self' do
      subject.yield.equal?(subject).should be(true)
    end
  end

  context 'when a literal is provided' do
    subject { described_class.new(header) { |object| object.add(:literal, 1) } }

    its(:functions) { should eql(Attribute::Integer.new(:literal) => 1) }

    it 'returns self' do
      subject.yield.equal?(subject).should be(true)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
axiom-0.1.0 spec/unit/axiom/evaluator/context/add_spec.rb