Sha256: ea86451bc7d3cf240ee32c4f42fcf0b9e48e29474db85ffa1373c37559ee05ed

Contents?: true

Size: 1.82 KB

Versions: 4

Compression:

Stored size: 1.82 KB

Contents

# encoding: utf-8

require 'spec_helper'
require 'ice_nine/freezer'
require 'ice_nine/freezer/object'
require 'ice_nine/freezer/array'
require 'ice_nine/freezer/struct'

describe IceNine::Freezer, '.[]' do
  subject { object[mod] }

  let(:object)  { described_class }
  let(:freezer) { object::Object  }

  describe 'when the module matches a descendant' do
    let(:freezer) { Class.new(object) }
    let(:mod)     { Class             }

    before do
      object.const_set(mod.name, freezer)
    end

    after do
      object.send(:remove_const, mod.name)
    end

    it 'returns the freezer' do
      should be(freezer)
    end
  end

  describe 'when the module matches a descendant inside a namespace' do
    let(:namespace) { Class.new(object) }
    let(:freezer)   { Class.new(object) }
    let(:mod)       { Application::User }

    before :all do
      module ::Application
        class User; end
      end
    end

    after :all do
      ::Application.send(:remove_const, :User)
      Object.send(:remove_const, :Application)
    end

    before do
      namespace.const_set(:User, freezer)
      object.const_set(:Application, namespace)
    end

    after do
      namespace.send(:remove_const, :User)
      object.send(:remove_const, :Application)
    end

    it 'returns the freezer' do
      should be(freezer)
    end
  end

  describe 'when the module is a struct' do
    let(:mod)     { Struct.new(:a)           }
    let(:freezer) { IceNine::Freezer::Struct }

    it 'returns the freezer' do
      should be(freezer)
    end
  end

  describe 'when the module does not match a descendant' do
    let(:mod) { Object }

    it 'returns the freezer' do
      should be(freezer)
    end
  end

  describe 'when the module is anonymous' do
    let(:mod) { Class.new }

    it 'returns the freezer' do
      should be(freezer)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ice_nine-0.8.0 spec/unit/ice_nine/freezer/class_methods/element_reference_spec.rb
ice_nine-0.7.0 spec/unit/ice_nine/freezer/class_methods/element_reference_spec.rb
ice_nine-0.6.0 spec/unit/ice_nine/freezer/class_methods/element_reference_spec.rb
ice_nine-0.5.0 spec/unit/ice_nine/freezer/class_methods/element_reference_spec.rb