File: has_value_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-- 861 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
  let(:hash) { H[toast: 'buttered', jam: 'strawberry'] }

  [:value?, :has_value?].each do |method|
    describe "##{method}" do
      it 'returns true if any key/val pair in Hash has the same value' do
        hash.send(method, 'strawberry').should == true
      end

      it 'returns false if no key/val pair in Hash has the same value' do
        hash.send(method, 'marmalade').should == false
      end

      it 'uses #== to check equality' do
        H[a: EqualNotEql.new].send(method, EqualNotEql.new).should == true
        H[a: EqlNotEqual.new].send(method, EqlNotEqual.new).should == false
      end

      it 'works on a large hash' do
        large = H.new((1..1000).zip(2..1001))
        [2, 100, 200, 500, 900, 1000, 1001].each { |n| large.value?(n).should == true }
      end
    end
  end
end