1describe :hash_key_p, shared: true do
2  it "returns true if argument is a key" do
3    h = { a: 1, b: 2, c: 3, 4 => 0 }
4    h.send(@method, :a).should == true
5    h.send(@method, :b).should == true
6    h.send(@method, 2).should == false
7    h.send(@method, 4).should == true
8
9    not_supported_on :opal do
10      h.send(@method, 'b').should == false
11      h.send(@method, 4.0).should == false
12    end
13  end
14
15  it "returns true if the key's matching value was nil" do
16    { xyz: nil }.send(@method, :xyz).should == true
17  end
18
19  it "returns true if the key's matching value was false" do
20    { xyz: false }.send(@method, :xyz).should == true
21  end
22
23  it "returns true if the key is nil" do
24    { nil => 'b' }.send(@method, nil).should == true
25    { nil => nil }.send(@method, nil).should == true
26  end
27
28  it "compares keys with the same #hash value via #eql?" do
29    x = mock('x')
30    x.stub!(:hash).and_return(42)
31
32    y = mock('y')
33    y.stub!(:hash).and_return(42)
34    y.should_receive(:eql?).and_return(false)
35
36    { x => nil }.send(@method, y).should == false
37  end
38end
39