Sha256: af7ee5698f7b5af8a6faae83efc3f50dd021095c4818d1c5c480c4940752efa5

Contents?: true

Size: 1.86 KB

Versions: 1

Compression:

Stored size: 1.86 KB

Contents

# -*- coding: utf-8 -*-
require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')

require 'active_support'
require "tengine/support/core_ext/hash/deep_dup"

describe "tengine/support/core_ext/hash/deep_dup" do

  original = {
    :a => {
      :b => {
        :c => :d
      }.freeze,
      :e => [
        :f,
        {:g => :h}.freeze,
        [:i, :j].freeze
      ].freeze
    }.freeze
  }.freeze

  context "Array#deep_dupがある場合" do
    before do
      load("tengine/support/core_ext/array/deep_dup.rb")
    end

    subject{ original.deep_dup }
    it { subject.should == original }
    it { subject.object_id.should_not == original.object_id }
    it { subject[:a].object_id.should_not == original[:a].object_id }
    it { subject[:a][:b].object_id.should_not == original[:a][:b].object_id }
    it { subject[:a][:e].object_id.should_not == original[:a][:e].object_id }
    it { subject[:a][:e][1].object_id.should_not == original[:a][:e][1].object_id }
    it { subject[:a][:e][2].object_id.should_not == original[:a][:e][2].object_id }
  end

  context "Array#deep_dupがない場合" do
    before do
      if Array.instance_methods.include?(:deep_dup)
        Array.class_eval do
          remove_method(:deep_dup)
        end
      end
    end
    after do
      load("tengine/support/core_ext/array/deep_dup.rb")
    end

    subject{ original.deep_dup }
    it { subject.should == original }
    it { subject.object_id.should_not == original.object_id }
    it { subject[:a].object_id.should_not == original[:a].object_id }
    it { subject[:a][:b].object_id.should_not == original[:a][:b].object_id }
    it { subject[:a][:e].object_id.should     == original[:a][:e].object_id }
    it { subject[:a][:e][1].object_id.should     == original[:a][:e][1].object_id }
    it { subject[:a][:e][2].object_id.should     == original[:a][:e][2].object_id }
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tengine_support-0.3.15 spec/tengine_support/core_ext/hash/deep_dup_spec.rb