Sha256: c42137a541954e332fbb90b7e54ef5d117b10a4af5173bba9e7c0abfd568a461

Contents?: true

Size: 954 Bytes

Versions: 4

Compression:

Stored size: 954 Bytes

Contents

require 'spec_helper'
module Alf
  describe AttrList, "split_tuple" do 

    let(:key){ AttrList.new [:a, :b] }
    let(:tuple){ {:a => 1, :b => 2, :c => 3} }

    describe "when used without allbut" do
      subject{ key.split_tuple(tuple) }
      it{ should eq([{:a => 1, :b => 2}, {:c => 3}]) }
    end

    describe "when used with allbut set to true" do
      subject{ key.split_tuple(tuple, true) }
      it{ should eq([{:c => 3}, {:a => 1, :b => 2}]) }
    end

    describe "when used with allbut set to false" do
      subject{ key.split_tuple(tuple, false) }
      it{ should eq([{:a => 1, :b => 2}, {:c => 3}]) }
    end

    specify "the documentation example" do
      list = AttrList.new([:name])
      tuple = {:name => "Jones", :city => "London"}
      list.split_tuple(tuple).should eq([{:name => "Jones"}, {:city => "London"}])
      list.split_tuple(tuple, true).should eq([{:city => "London"}, {:name => "Jones"}])
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
alf-core-0.15.0 spec/unit/alf-types/attr_list/test_split_tuple.rb
alf-core-0.14.0 spec/unit/alf-types/attr_list/test_split_tuple.rb
alf-core-0.13.1 spec/unit/alf-types/attr_list/test_split_tuple.rb
alf-core-0.13.0 spec/unit/alf-types/attr_list/test_split_tuple.rb