Sha256: 95c18acefa5886d9dc578c7990b4255db93da4c07ad8b93c17ca4758633b6846

Contents?: true

Size: 816 Bytes

Versions: 1

Compression:

Stored size: 816 Bytes

Contents

require "spec_helper"

describe Mashed::StringyHash do
  let(:hash) {{ a: 1, b: 2, c: { three: 3 }, d: [:e, { f: 4 }]}}

  def stringify
    Mashed::StringyHash.stringify(hash)
  end

  describe ".stringify" do
    it {
      expect(stringify).to eq({
        "a" => 1,
        "b" => 2,
        "c" => { "three" => 3 },
        "d" => [:e, { "f" => 4 }]
      })
    }
  end

  describe "get and set" do
    let(:s) { stringify }
    before { s[:a] = "A" }
    it { expect(s[:a]).to eq("A") }
    it { expect(s["a"]).to eq("A") }
    it { expect(s.key?(:a)).to be_true }
    it { expect(s.key?("a")).to be_true }
  end

  describe "calls to_s on objects" do
    let(:s) { stringify }
    let(:klass) {
      Class.new do
        def to_s; "a"; end
      end
    }
    it { expect(s[klass.new]).to eq(1) }
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mashed-1.0.1 spec/mashed/stringy_hash_spec.rb