Sha256: a157055057bf69cff1daf0dd86477fe4f8066e471331d16d36c1744496b626f9

Contents?: true

Size: 969 Bytes

Versions: 5

Compression:

Stored size: 969 Bytes

Contents

# encoding: utf-8

require 'spec_helper'
require File.expand_path('../../fixtures/classes', __FILE__)

describe Memoizable::InstanceMethods, '#memoize' do
  subject { object.memoize(method => value) }

  let(:described_class) { Class.new(Fixture::Object) }
  let(:object)          { described_class.new        }
  let(:method)          { :test                      }

  before do
    described_class.memoize(method)
  end

  context 'when the method is not memoized' do
    let(:value) { String.new }

    it 'sets the memoized value for the method to the value' do
      subject
      expect(object.send(method)).to be(value)
    end

    it_should_behave_like 'a command method'
  end

  context 'when the method is already memoized' do
    let(:value)    { double }
    let(:original) { nil    }

    before do
      object.memoize(method => original)
    end

    it 'raises an exception' do
      expect { subject }.to raise_error(ArgumentError)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
memoizable-0.4.2 spec/unit/memoizable/instance_methods/memoize_spec.rb
memoizable-0.4.1 spec/unit/memoizable/instance_methods/memoize_spec.rb
memoizable-0.4.0 spec/unit/memoizable/instance_methods/memoize_spec.rb
memoizable-0.3.1 spec/unit/memoizable/instance_methods/memoize_spec.rb
memoizable-0.3.0 spec/unit/memoizable/instance_methods/memoize_spec.rb