Sha256: 4f64f601f775ec9be72511eb8718f08aeeb3714004937ad7de2f710d3af75f88

Contents?: true

Size: 1.44 KB

Versions: 4

Compression:

Stored size: 1.44 KB

Contents

# encoding: utf-8

require 'spec_helper'

describe Optimizer, '.chain' do
  let(:operation)       { mock('Operation')    }
  let(:object)          { Optimizer            }
  let(:noop)            { object::Noop         }
  let(:optimizer_class) { Class.new(Optimizer) }

  context 'with no optimizers' do
    subject { object.chain }

    it { should equal(noop) }

    it 'returns a block that returns the operation' do
      subject.call(operation).should equal(operation)
    end
  end

  context 'with an optimizer that can optimize the operation' do
    subject { object.chain(optimizer_class) }

    let(:optimized) { mock('Optimized') }

    before do
      optimized = self.optimized
      optimizer_class.send(:define_method, :optimizable?) { true      }
      optimizer_class.send(:define_method, :optimize)     { optimized }
    end

    it { should_not equal(noop) }

    it { should be_kind_of(Proc) }

    it 'returns a block that optimizes the operation' do
      subject.call(operation).should equal(optimized)
    end
  end

  context 'with an optimizer that cannot optimize the operation' do
    subject { object.chain(optimizer_class) }

    before do
      optimizer_class.send(:define_method, :optimizable?) { false }
    end

    it { should_not equal(noop) }

    it { should be_kind_of(Proc) }

    it 'returns a block that calls the successor (Noop) with the operation' do
      subject.call(operation).should equal(operation)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
veritas-optimizer-0.0.7 spec/unit/veritas/optimizer/class_methods/chain_spec.rb
veritas-optimizer-0.0.6 spec/unit/veritas/optimizer/class_methods/chain_spec.rb
veritas-optimizer-0.0.5 spec/unit/veritas/optimizer/class_methods/chain_spec.rb
veritas-optimizer-0.0.4 spec/unit/veritas/optimizer/class_methods/chain_spec.rb