Sha256: 7727eeeece5b40d43e2a6d88bbe005f4b27e7dbb701c65586dbe2282dae8feed

Contents?: true

Size: 934 Bytes

Versions: 17

Compression:

Stored size: 934 Bytes

Contents

# frozen_string_literal: true

describe 'Array#__nanoc_symbolize_keys_recursively' do
  it 'should convert keys to symbols' do
    array_old = [:abc, 'xyz', { 'foo' => 'bar', :baz => :qux }]
    array_new = [:abc, 'xyz', { foo: 'bar', baz: :qux }]
    expect(array_old.__nanoc_symbolize_keys_recursively).to eql(array_new)
  end
end

describe 'Array#__nanoc_freeze_recursively' do
  it 'should prevent first-level elements from being modified' do
    array = [:a, %i[b c], :d]
    array.__nanoc_freeze_recursively

    expect { array[0] = 123 }.to raise_frozen_error
  end

  it 'should prevent second-level elements from being modified' do
    array = [:a, %i[b c], :d]
    array.__nanoc_freeze_recursively

    expect { array[1][0] = 123 }.to raise_frozen_error
  end

  it 'should not freeze infinitely' do
    a = []
    a << a

    a.__nanoc_freeze_recursively

    expect(a).to be_frozen
    expect(a[0]).to be_frozen
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
nanoc-4.8.12 spec/nanoc/base/core_ext/array_spec.rb
nanoc-4.8.11 spec/nanoc/base/core_ext/array_spec.rb
nanoc-4.8.10 spec/nanoc/base/core_ext/array_spec.rb
nanoc-4.8.9 spec/nanoc/base/core_ext/array_spec.rb
nanoc-4.8.8 spec/nanoc/base/core_ext/array_spec.rb
nanoc-4.8.7 spec/nanoc/base/core_ext/array_spec.rb
nanoc-4.8.6 spec/nanoc/base/core_ext/array_spec.rb
nanoc-4.8.5 spec/nanoc/base/core_ext/array_spec.rb
nanoc-4.8.4 spec/nanoc/base/core_ext/array_spec.rb
nanoc-4.8.3 spec/nanoc/base/core_ext/array_spec.rb
nanoc-4.8.2 spec/nanoc/base/core_ext/array_spec.rb
nanoc-4.8.1 spec/nanoc/base/core_ext/array_spec.rb
nanoc-4.8.0 spec/nanoc/base/core_ext/array_spec.rb
nanoc-4.7.14 spec/nanoc/base/core_ext/array_spec.rb
nanoc-4.7.13 spec/nanoc/base/core_ext/array_spec.rb
nanoc-4.7.12 spec/nanoc/base/core_ext/array_spec.rb
nanoc-4.7.11 spec/nanoc/base/core_ext/array_spec.rb