Sha256: 9a98ef2c1bdff35de42f023c2407e23a17feccc4a654686ce9dd1d07afcb6dcc

Contents?: true

Size: 1.64 KB

Versions: 3

Compression:

Stored size: 1.64 KB

Contents

# encoding: utf-8

describe 'Array#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 } ]
    array_old.symbolize_keys_recursively.must_equal array_new
  end

end

describe 'Array#stringify_keys_recursively' do

  it 'should convert keys to strings' do
    array_old = [ :abc, 'xyz', { :foo  => 'bar', 'baz' => :qux } ]
    array_new = [ :abc, 'xyz', { 'foo' => 'bar', 'baz' => :qux } ]
    array_old.stringify_keys_recursively.must_equal array_new
  end

end

describe 'Array#freeze_recursively' do

  it 'should prevent first-level elements from being modified' do
    array = [ :a, [ :b, :c ], :d ]
    array.freeze_recursively

    raised = false
    begin
      array[0] = 123
    rescue => e
      raised = true
      assert_match(/(^can't modify frozen |^unable to modify frozen object$)/, e.message)
    end
    assert raised
  end

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

    raised = false
    begin
      array[1][0] = 123
    rescue => e
      raised = true
      assert_match(/(^can't modify frozen |^unable to modify frozen object$)/, e.message)
    end
    assert raised
  end

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

    a.freeze_recursively

    assert a.frozen?
    assert a[0].frozen?
    assert_equal a, a[0]
  end

end

describe 'Array#checksum' do

  it 'should work' do
    expectation = '78468f950645150238a26f5b8f2dde39a75a7028'
    [ [ :foo, 123 ]].checksum.must_equal expectation
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
nanoc-3.5.0 test/base/core_ext/array_spec.rb
nanoc-3.5.0b2 test/base/core_ext/array_spec.rb
nanoc-3.5.0b1 test/base/core_ext/array_spec.rb