File: to_proc_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 (39 lines) | stat: -rw-r--r-- 1,091 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
28
29
30
31
32
33
34
35
36
37
38
39
require 'spec_helper'
require 'immutable/hash'

describe Immutable::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