Sha256: 00b1e654b20b7eb24793d3bcb8fa68dfea61c9f22c9ba0d2e285fae57eec11f0

Contents?: true

Size: 1.19 KB

Versions: 2

Compression:

Stored size: 1.19 KB

Contents

# encoding: utf-8

describe 'Array#symbolize_keys' 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.must_equal array_new
  end

end

describe 'Array#stringify_keys' 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.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 /, 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 /, e.message
    end
    assert raised
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
nanoc3-3.2.0b2 test/base/core_ext/array_spec.rb
nanoc3-3.2.0b1 test/base/core_ext/array_spec.rb