Sha256: 2a1262fe65a025dca05121b02d9e53404333919e634a9643167ffec74a8aca7c

Contents?: true

Size: 1.08 KB

Versions: 4

Compression:

Stored size: 1.08 KB

Contents

# encoding: utf-8

require 'spec_helper'

describe Optimizer::Optimizable, '#optimize' do
  subject { object.optimize }

  let(:described_class) { Class.new { include Optimizer::Optimizable, Immutable } }
  let(:object)          { described_class.new                                     }

  context 'when there is no optimizer for the class' do
    it { should equal(object) }

    it_should_behave_like 'an optimize method'
  end

  context 'when there is an optimizer for the class' do
    let(:optimized) { mock('Optimized', :frozen? => true)   }
    let(:optimizer) { mock('Optimizer', :call => optimized) }

    before do
      described_class.optimizer = optimizer
      optimized.stub!(:optimize).and_return(optimized)
    end

    it { should equal(optimized) }

    it 'calls the optimizer with the object' do
      optimizer.should_receive(:call).with(object).and_return(optimized)
      should equal(optimized)
    end

    it '#optimize the optimized object' do
      optimized.should_receive(:optimize).with(no_args).and_return(optimized)
      should equal(optimized)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
veritas-optimizer-0.0.7 spec/unit/veritas/optimizer/optimizable/optimize_spec.rb
veritas-optimizer-0.0.6 spec/unit/veritas/optimizer/optimizable/optimize_spec.rb
veritas-optimizer-0.0.5 spec/unit/veritas/optimizer/optimizable/optimize_spec.rb
veritas-optimizer-0.0.4 spec/unit/veritas/optimizer/optimizable/optimize_spec.rb