Sha256: 1c2c7d2d14abe23c260e1f1f1fd21168d060119bc7557359e1eff237d5e6ae69

Contents?: true

Size: 876 Bytes

Versions: 4

Compression:

Stored size: 876 Bytes

Contents

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

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

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

    describe "when used with allbut set to true" do
      subject{ key.project_tuple(tuple, true) }
      it{ should eq({:c => 3}) }
    end

    describe "when used without allbut set to false" do
      subject{ key.project_tuple(tuple, false) }
      it{ should eq({:a => 1, :b => 2}) }
    end

    specify "the documentation example" do
      list = AttrList.new([:name])
      tuple = {:name => "Jones", :city => "London"}
      list.project_tuple(tuple).should eq({:name => "Jones"})
      list.project_tuple(tuple, true).should eq({:city => "London"})
    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_project_tuple.rb
alf-core-0.14.0 spec/unit/alf-types/attr_list/test_project_tuple.rb
alf-core-0.13.1 spec/unit/alf-types/attr_list/test_project_tuple.rb
alf-core-0.13.0 spec/unit/alf-types/attr_list/test_project_tuple.rb