Sha256: 1eceab86a77aa471aef145dc174a2ba3672e0fb92db7a3141101004dd4299b04

Contents?: true

Size: 1007 Bytes

Versions: 8

Compression:

Stored size: 1007 Bytes

Contents

require "spec_helper"
require "tagen/core/extend_hash"

class ExtendHash
  class << self
    public :deep_convert
  end
end

describe ExtendHash do
  describe ".deep_convert" do 
    it "convert string key to symbol key" do
      ExtendHash.deep_convert({"a" => 1, "b" => {"c" => 2}}).should == {a: 1, b: {c: 2}}
    end
  end

  describe ".[]" do
    it "convert Hash to ExtendHash with string key" do
      ret = ExtendHash[a: 1, "b" => 2]
      ret.should == {a: 1, b: 2}
    end
  end

  describe "#[]" do
    it "convert string-key to symbol-key" do
      h = ExtendHash.new
      h.store(:ok, 1)
      h["ok"].should == 1
    end
  end

  describe "#[]=" do
    it "convert string-key to symbol-key" do
      h = ExtendHash.new
      h["ok"] = 1
      h[:ok] = 1
    end
  end

  describe "#method_missing" do
    it "#key" do
      h = ExtendHash.new
      h[:ok] = 1
      h.ok.should == 1
    end

    it "#key=" do
      h = ExtendHash.new
      h.ok = 1
      h.ok.should == 1
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
tagen-1.1.7 spec/tagen/core/extend_hash_spec.rb
tagen-1.1.6 spec/tagen/core/extend_hash_spec.rb
tagen-1.1.5 spec/tagen/core/extend_hash_spec.rb
tagen-1.1.4 spec/tagen/core/extend_hash_spec.rb
tagen-1.1.3 spec/tagen/core/extend_hash_spec.rb
tagen-1.1.2 spec/tagen/core/extend_hash_spec.rb
tagen-1.1.1 spec/tagen/core/extend_hash_spec.rb
tagen-1.1.0 spec/tagen/core/extend_hash_spec.rb