File: key_spec.rb

package info (click to toggle)
ruby-immutable-ruby 0.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,852 kB
  • sloc: ruby: 16,556; makefile: 4
file content (27 lines) | stat: -rw-r--r-- 749 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
require 'spec_helper'

describe Immutable::Hash do
  describe '#key' do
    let(:hash) { H[a: 1, b: 1, c: 2, d: 3] }

    it 'returns a key associated with the given value, if there is one' do
      [:a, :b].include?(hash.key(1)).should == true
      hash.key(2).should be(:c)
      hash.key(3).should be(:d)
    end

    it 'returns nil if there is no key associated with the given value' do
      hash.key(5).should be_nil
      hash.key(0).should be_nil
    end

    it 'uses #== to compare values for equality' do
      hash.key(EqualNotEql.new).should_not be_nil
      hash.key(EqlNotEqual.new).should be_nil
    end

    it "doesn't use default block if value is not found" do
      H.new(a: 1) { fail }.key(2).should be_nil
    end
  end
end