Sha256: 3a2d16236480c7326604856471916b0d88fd52f8403f5741c34be2e8c3e1f031

Contents?: true

Size: 918 Bytes

Versions: 3

Compression:

Stored size: 918 Bytes

Contents

require "spec_helper"
require "hamster/hash"

describe Hamster::Hash do
  [:key?, :has_key?, :include?, :member?].each do |method|
    describe "##{method}" do
      let(:hash) { H["A" => "aye", "B" => "bee", "C" => "see", nil => "NIL", 2.0 => "two"] }

      ["A", "B", "C", nil, 2.0].each do |key|
        it "returns true for an existing key (#{key.inspect})" do
          hash.send(method, key).should == true
        end
      end

      it "returns false for a non-existing key" do
        hash.send(method, "D").should == false
      end

      it "uses #eql? for equality" do
        hash.send(method, 2).should == false
      end

      it "returns true if the key is found and maps to nil" do
        H["A" => nil].send(method, "A").should == true
      end

      it "returns true if the key is found and maps to false" do
        H["A" => false].send(method, "A").should == true
      end
    end
  end
end

Version data entries

3 entries across 3 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/has_key_spec.rb
hamster-3.0.0 spec/lib/hamster/hash/has_key_spec.rb
hamster-2.0.0 spec/lib/hamster/hash/has_key_spec.rb