Sha256: 502467bf3bbff67136e3e96790ec613ba3a1cad42ecc85cbff3ef0f7415a8eb6

Contents?: true

Size: 1.51 KB

Versions: 1

Compression:

Stored size: 1.51 KB

Contents

# encoding: utf-8

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

describe Adamantium, '#memoize' do
  subject { object.memoize(method, value) }

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

  before do
    described_class.memoize(method)
  end

  context 'when the value is frozen' do
    let(:value) { String.new.freeze }

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

    it 'creates a method that returns a frozen value' do
      subject
      expect(object.send(method)).to be_frozen
    end

    it_should_behave_like 'a command method'
  end

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

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

    it 'creates a method that returns a frozen value' do
      subject
      expect(object.send(method)).to be_frozen
    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 'does not change the value' do
      expect { subject }.to_not change { object.send(method) }
    end

    it_should_behave_like 'a command method'
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
adamantium-0.1.0 spec/unit/adamantium/memoize_spec.rb