Sha256: f13cba3ee7948449e7bec85204800518de3aff42c9ba7b3339f2c8b25d77277c
Contents?: true
Size: 1.71 KB
Versions: 16
Compression:
Stored size: 1.71 KB
Contents
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') require 'rid/core_ext/hash' describe "Hash" do describe "flatten" do it "should untouch flat hash" do hash = { "a" => 1, "b" => 2 } hash.flatten.should == hash end it "should flaten simple nested hash" do hash = { "a" => { "b" => 1 } } hash.flatten.should == { "a/b" => 1 } end it "should flaten deep nested hash" do hash = { "a" => { "b" => { "c" => 1 } } } hash.flatten.should == { "a/b/c" => 1 } end end describe "flatten!" do it "should change receiver" do hash = { "a" => { "b" => 1 } } hash.flatten! hash.should == { "a/b" => 1 } end end describe "at" do it "should retrieve value at top level" do hash = { "a" => 1 } hash.at("a").should == 1 end it "should retrieve value at nested level" do hash = { "a" => { "b" => 1 } } hash.at("a/b").should == 1 end it "should retrieve value at deep nested level" do hash = { "a" => { "b" => { "c" => 1 } } } hash.at("a/b/c").should == 1 end it "should return nil if not present" do hash = { "a" => { "c" => { "c" => 1 } } } hash.at("a/b/c").should == nil end end describe "update_at" do it "should insert value at top level" do hash = { } hash.update_at "a", 1 hash.should == { "a" => 1 } end it "should insert value at nested level" do hash = { } hash.update_at "a/b", 1 hash.should == { "a" => { "b" => 1 } } end it "should insert value at deep nested level" do hash = { } hash.update_at "a/b/c", 1 hash.should == { "a" => { "b" => { "c" => 1 } } } end end end
Version data entries
16 entries across 16 versions & 2 rubygems