Sha256: e560e0ca3def73ad183a6a6462a038e8980e7a0514d348921718a8e9daa45dbd

Contents?: true

Size: 1.34 KB

Versions: 1

Compression:

Stored size: 1.34 KB

Contents

# encoding: utf-8

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

describe Adamantium, '#freeze' do
  subject { object.freeze }

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

  before do
    described_class.memoize(:test)
  end

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

    it_should_behave_like 'a command method'

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

    it 'sets a memoization instance variable' do
      expect(object).to_not be_instance_variable_defined(:@__memory)
      subject
      expect(object.instance_variable_get(:@__memory)).to be_instance_of(Adamantium::Memory)
    end
  end

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

    it_should_behave_like 'a command method'

    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 'does not set an instance variable for memoization' do
      expect(object.instance_variable_get(:@__memory)).to be_instance_of(Adamantium::Memory)
      subject
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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