Sha256: faec03adb40419f00c3e9d627e8033f36787f1d415c630a098196174cbcc9f84

Contents?: true

Size: 1.06 KB

Versions: 2

Compression:

Stored size: 1.06 KB

Contents

require "spec_helper"
require "hamster/hash"

describe Hamster::Hash do
  describe "#to_proc" do
    context "on Hash without default proc" do
      let(:hash) { H.new("A" => "aye") }

      it "returns a Proc instance" do
        hash.to_proc.should be_kind_of(Proc)
      end

      it "returns a Proc that returns the value of an existing key" do
        hash.to_proc.call("A").should == "aye"
      end

      it "returns a Proc that returns nil for a missing key" do
        hash.to_proc.call("B").should be_nil
      end
    end

    context "on Hash with a default proc" do
      let(:hash) { H.new("A" => "aye") { |key| "#{key}-VAL" } }

      it "returns a Proc instance" do
        hash.to_proc.should be_kind_of(Proc)
      end

      it "returns a Proc that returns the value of an existing key" do
        hash.to_proc.call("A").should == "aye"
      end

      it "returns a Proc that returns the result of the hash's default proc for a missing key" do
        hash.to_proc.call("B").should == "B-VAL"
        hash.should == H.new("A" => "aye")
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
files.com-1.0.55 docs/vendor/bundle/ruby/2.5.0/gems/hamster-3.0.0/spec/lib/hamster/hash/to_proc_spec.rb
hamster-3.0.0 spec/lib/hamster/hash/to_proc_spec.rb