Sha256: c4755fa63d81a02688866a9e619e4768669e1c06968d0dbb51039054a3350ec5

Contents?: true

Size: 1006 Bytes

Versions: 1

Compression:

Stored size: 1006 Bytes

Contents

require 'action_tree'


EXTRA_FAMILY_INFO = {
  :brother => 'Smerdyakov',
  :father => 'Fyodor'
  }

describe ActionTree::CaptureHash do

  describe '#add' do
    it 'once adds item as itself' do
      subject.add :canoe_color, 'green'
      subject[:canoe_color].should == 'green'
    end

    it 'more than once becomes an Array' do
      subject.add :sister, 'Arleta'
      subject.add :sister, 'Maud'
      subject[:sister].should == ['Arleta', 'Maud']
    end
  end

  describe '#merge' do

    before do
      subject.add :brother, 'Dmitry'
      subject.add :brother, 'Ivan'
      subject.add :brother, 'Alexey'
    end

    it 'merges with array, accumulating on equal keys' do
      family = subject.merge(EXTRA_FAMILY_INFO)
      family[:brother].should ==
        %w{Dmitry Ivan Alexey Smerdyakov}
      family[:father].should == 'Fyodor'
    end

    it 'is non-destructive' do
      family = subject.dup
      family.merge(EXTRA_FAMILY_INFO)
      family.should == subject
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
action_tree-0.2.0 spec/00_foundations/capture_hash_spec.rb