File: delete_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,030 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'

describe Immutable::Hash do
  describe '#delete' do
    let(:hash) { H['A' => 'aye', 'B' => 'bee', 'C' => 'see'] }

    context 'with an existing key' do
      let(:result) { hash.delete('B') }

      it 'preserves the original' do
        hash.should eql(H['A' => 'aye', 'B' => 'bee', 'C' => 'see'])
      end

      it 'returns a copy with the remaining key/value pairs' do
        result.should eql(H['A' => 'aye', 'C' => 'see'])
      end
    end

    context 'with a non-existing key' do
      let(:result) { hash.delete('D') }

      it 'preserves the original values' do
        hash.should eql(H['A' => 'aye', 'B' => 'bee', 'C' => 'see'])
      end

      it 'returns self' do
        result.should equal(hash)
      end
    end

    context 'when removing the last key' do
      context 'from a Hash with no default block' do
        it 'returns the canonical empty Hash' do
          hash.delete('A').delete('B').delete('C').should be(Immutable::EmptyHash)
        end
      end
    end
  end
end