Sha256: cd9c23d3e8bb978a5a1fdb0aa25917caefe635418d641e374368fb4a4277fbe9

Contents?: true

Size: 1010 Bytes

Versions: 18

Compression:

Stored size: 1010 Bytes

Contents

require 'spec_helper'

describe "Cistern::Hash" do
  describe "#slice" do
    let(:input) do
      { one: "one", two: "two", three: "three" }
    end

    it "returns a new hash with only the specified keys" do
      expect(Cistern::Hash.slice(input, :one, :two)).to eq({ one: "one", two: "two" })
    end

    it "skips keys that aren't in the original hash" do
      expect(Cistern::Hash.slice(input, :four)).to eq({})
    end
  end

  describe "#stringify_keys" do
    let(:input) do
      { one: "one", two: "two" }
    end

    it "returns a new hash with stringed keys" do
      expect(Cistern::Hash.stringify_keys(input)).to eq({ "one" => "one", "two" => "two" })
    end

    context "with nested hashes or arrays" do
      let(:input) do
        { hash: { one: "one" }, array: [{ two: "two" }] }
      end

      it "stringifies all of the keys" do
        expect(Cistern::Hash.stringify_keys(input)).to eq({ "hash" => { "one" => "one" }, "array" => [{ "two" => "two" }]})
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
cistern-0.12.3 spec/hash_spec.rb
cistern-0.12.2 spec/hash_spec.rb
cistern-0.12.1 spec/hash_spec.rb
cistern-0.11.3 spec/hash_spec.rb
cistern-1.0.1.pre6 spec/hash_spec.rb
cistern-1.0.1.pre5 spec/hash_spec.rb
cistern-1.0.1.pre4 spec/hash_spec.rb
cistern-1.0.1.pre3 spec/hash_spec.rb
cistern-1.0.1.pre2 spec/hash_spec.rb
cistern-0.11.2 spec/hash_spec.rb
cistern-1.0.1.pre1 spec/hash_spec.rb
cistern-1.0.0.pre spec/hash_spec.rb
cistern-0.11.2.pre2 spec/hash_spec.rb
cistern-0.11.1 spec/hash_spec.rb
cistern-0.11.0 spec/hash_spec.rb
cistern-0.10.2 spec/hash_spec.rb
cistern-0.9.2 spec/hash_spec.rb
cistern-0.9.1 spec/hash_spec.rb