Sha256: d90a48f41496e749fec3ddca4734cdec676294133c68b6391fb35859540f37a9

Contents?: true

Size: 1.41 KB

Versions: 11

Compression:

Stored size: 1.41 KB

Contents

# encoding: utf-8

require 'spec_helper'
require 'ice_nine'

describe IceNine::Freezer::Hash, '.deep_freeze' do
  subject { object.deep_freeze(value) }

  let(:object) { described_class }

  context 'with a Hash object having a default proc' do
    let(:value) do
      Hash.new {}.update(Object.new => Object.new)
    end

    it_behaves_like 'IceNine::Freezer::Hash.deep_freeze'

    it 'freezes the default proc' do
      expect(subject.default_proc).to be_frozen
    end
  end

  context 'with a Hash object having a default value' do
    let(:value) do
      Hash.new('').update(Object.new => Object.new)
    end

    it_behaves_like 'IceNine::Freezer::Hash.deep_freeze'

    it 'freezes the default value' do
      expect(subject.default).to be_frozen
    end

    context 'that is a circular reference' do
      before { value.default = value }

      it_behaves_like 'IceNine::Freezer::Hash.deep_freeze'

      it 'freezes the default value' do
        expect(subject.default).to be_frozen
      end
    end
  end

  context 'with a Hash object containing itself as a key' do
    let(:value) do
      value = {}
      value[value] = '1'
      value
    end

    it_behaves_like 'IceNine::Freezer::Hash.deep_freeze'
  end

  context 'with a Hash object containing itself as a value' do
    let(:value) do
      value = {}
      value['a'] = value
      value
    end

    it_behaves_like 'IceNine::Freezer::Hash.deep_freeze'
  end
end

Version data entries

11 entries across 9 versions & 4 rubygems

Version Path
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/ice_nine-0.11.2/spec/unit/ice_nine/freezer/hash/class_methods/deep_freeze_spec.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/ice_nine-0.11.2/spec/unit/ice_nine/freezer/hash/class_methods/deep_freeze_spec.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/ice_nine-0.11.2/spec/unit/ice_nine/freezer/hash/class_methods/deep_freeze_spec.rb
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/ice_nine-0.11.2/spec/unit/ice_nine/freezer/hash/class_methods/deep_freeze_spec.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/ice_nine-0.11.2/spec/unit/ice_nine/freezer/hash/class_methods/deep_freeze_spec.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/ice_nine-0.11.2/spec/unit/ice_nine/freezer/hash/class_methods/deep_freeze_spec.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/ice_nine-0.11.2/spec/unit/ice_nine/freezer/hash/class_methods/deep_freeze_spec.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/ice_nine-0.11.2/spec/unit/ice_nine/freezer/hash/class_methods/deep_freeze_spec.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/ice_nine-0.11.2/spec/unit/ice_nine/freezer/hash/class_methods/deep_freeze_spec.rb
ice_nine-0.11.2 spec/unit/ice_nine/freezer/hash/class_methods/deep_freeze_spec.rb
ice_nine-0.11.1 spec/unit/ice_nine/freezer/hash/class_methods/deep_freeze_spec.rb