File: reverse_each_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-- 689 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['A' => 'aye', 'B' => 'bee', 'C' => 'see'] }

  describe '#reverse_each' do
    context 'with a block' do
      it 'returns self' do
        hash.reverse_each {}.should be(hash)
      end

      it 'yields all key/value pairs in the opposite order as #each' do
        result = []
        hash.reverse_each { |entry| result << entry }
        result.should eql(hash.to_a.reverse)
      end
    end

    context 'with no block' do
      it 'returns an Enumerator' do
        result = hash.reverse_each
        result.class.should be(Enumerator)
        result.to_a.should eql(hash.to_a.reverse)
      end
    end
  end
end