Sha256: ec6d41f47ad175e0102a22e82287dfb4e3c6917513c6998449414f723f0efb74

Contents?: true

Size: 1.35 KB

Versions: 5

Compression:

Stored size: 1.35 KB

Contents

# encoding: utf-8
#
# This file is part of the lazier gem. Copyright (C) 2013 and above Shogun <shogun_panda@me.com>.
# Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
#

require "spec_helper"

describe Lazier::Hash do
  let(:reference) {
    rv = {a: 1, "b" => {c: 2, d: {"e" => 3}}}
    rv.default = 0
    rv
  }

  before(:each) do
    ::Lazier.load!
  end

  describe "allows access to keys using dotted notation" do
    it "should allow method reference for symbol key" do
      reference.b.f = 4

      expect(reference.a).to eq(1)
      expect(reference.b.c).to eq(2)
      expect(reference["b"]["f"]).to eq(4)
    end
  end

  describe "#ensure_access" do
    it "should make sure that the requested access is granted" do
      expect({"a" => "b"}.ensure_access(:strings)).to eq({"a" => "b"})
      expect({"a" => "b"}.ensure_access(:symbols)).to eq({a: "b"})
      expect({"a" => "b"}.ensure_access(:indifferent)).to be_a(::HashWithIndifferentAccess)
      expect({"a" => "b"}.ensure_access(:other)).to eq({"a" => "b"})
      expect({a: "b"}.ensure_access(:strings)).to eq({"a" => "b"})
      expect({a: "b"}.ensure_access(:symbols)).to eq({a: "b"})
      expect({a: "b"}.ensure_access(:indifferent)).to be_a(::HashWithIndifferentAccess)
      expect({a: "b"}.ensure_access(:other)).to eq({a: "b"})
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
lazier-3.3.5 spec/lazier/hash_spec.rb
lazier-3.3.3 spec/lazier/hash_spec.rb
lazier-3.3.2 spec/lazier/hash_spec.rb
lazier-3.3.1 spec/lazier/hash_spec.rb
lazier-3.3.0 spec/lazier/hash_spec.rb