Sha256: 26bd506a66fd8811381d2b7630c5639634872b4b1355b9e0437f69545e398168

Contents?: true

Size: 1.59 KB

Versions: 6

Compression:

Stored size: 1.59 KB

Contents

require File.dirname(__FILE__) + '/../spec_helper'

describe "Ordered Hash" do
  before(:each) do
    @oh = OrderedHash.new
    @oh["var1"] = 10
    @oh["var2"] = 2
    @oh[:var3] = 3
    @oh["var4"] = 4
  end
  it "should stay in order in enumeration (keys)" do
    @oh.collect {|k,v| k }.should == ["var1", "var2", :var3, "var4"]
  end
  it "should stay in order in enumeration (values)" do
    @oh.collect {|k,v| v }.should == [10,2,3,4]
  end
  it "should be able to be pulled out with the hash convention" do
    @oh['var1'].should == 10
    @oh['var2'].should == 2
    @oh[:var3].should == 3
    @oh["var4"].should == 4
  end
  it "should retain order in a merge" do
    @oh.merge!(:var5 => 5)
    @oh.collect {|k,v| v }.should == [10,2,3,4,5]
  end
  it "should retain order in a non-descructive merge" do
    @oh = @oh.merge(:var5 => 5)
    @oh.collect {|k,v| v }.should == [10,2,3,4,5]
  end
  it "should keep the keys in order too!" do
    @oh.keys.should == ["var1", "var2", :var3, "var4"]
  end
  it "should have values method" do
    @oh.values.should === [10,2,3,4]
  end
  it "should to_json" do
    @oh[:arr] = [1,2,3]
    @oh.to_json.should == "{\"var1\":10,\"var2\":2,\"var3\":3,\"var4\":4,\"arr\":[1,2,3]}"
  end
  it "PoolParty Key" do
      @oh[:keyy] = [Key.new, Key.new('path/to/nowhere')]
      expected=<<JSO
 {\"var1\":10,\"var2\":2,\"var3\":3,\"var4\":4,\"keyy\":[{\"basename\":\"id_rsa\",\n       \"full_filepath\": \"/etc/poolparty/id_rsa\"},{\"basename\":\"path/to/nowhere\",\n       \"full_filepath\": \"/etc/poolparty/path/to/nowhere\"}]}
JSO
      @oh.to_json.should == expected.strip
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
auser-poolparty-1.1.1 spec/poolparty/core/ordered_hash_spec.rb
auser-poolparty-1.1.3 spec/poolparty/core/ordered_hash_spec.rb
auser-poolparty-1.1.4 spec/poolparty/core/ordered_hash_spec.rb
auser-poolparty-1.1.5 spec/poolparty/core/ordered_hash_spec.rb
fairchild-poolparty-1.1.3 spec/poolparty/core/ordered_hash_spec.rb
fairchild-poolparty-1.1.4 spec/poolparty/core/ordered_hash_spec.rb