Sha256: 405111971081859d7ed6b0de258926837e5c80af39493331dbe64ef3ffc16d40

Contents?: true

Size: 1.24 KB

Versions: 1

Compression:

Stored size: 1.24 KB

Contents

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

describe 'Veritas::Immutable::MemoizeMethods#freeze' do
  subject { object.freeze }

  let(:klass) { Class.new(ImmutableSpecs::Object) }

  before do
    klass.memoize(:test)
  end

  context 'with an unfrozen object' do
    let(:object) { klass.allocate }

    it { should equal(object) }

    it 'freezes the object' do
      expect { subject }.to change(object, :frozen?).
        from(false).
        to(true)
    end

    it 'sets a memoization instance variable' do
      object.should_not be_instance_variable_defined(:@__memory)
      subject
      object.instance_variable_get(:@__memory).should be_kind_of(Immutable::Memory)
    end
  end

  context 'with a frozen object' do
    let(:object) { klass.new }

    it { should equal(object) }

    it 'does not change the frozen state of the object' do
      expect { subject }.to_not change(object, :frozen?)
    end

    it 'does not change the memoization instance variable' do
      expect { subject }.to_not change { object.instance_variable_get(:@__memory) }
    end

    it 'sets an instance variable for memoization' do
      subject.instance_variable_get(:@__memory).should be_kind_of(Immutable::Memory)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
veritas-0.0.2 spec/unit/veritas/immutable/memoize_methods/freeze_spec.rb