File: all_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 (51 lines) | stat: -rw-r--r-- 1,348 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
40
41
42
43
44
45
46
47
48
49
50
51
require 'spec_helper'

describe Immutable::Set do
  describe '#all?' do
    context 'when empty' do
      it 'with a block returns true' do
        S.empty.all? {}.should == true
      end

      it 'with no block returns true' do
        S.empty.all?.should == true
      end
    end

    context 'when not empty' do
      context 'with a block' do
        let(:set) { S['A', 'B', 'C'] }

        it 'returns true if the block always returns true' do
          set.all? { |item| true }.should == true
        end

        it 'returns false if the block ever returns false' do
          set.all? { |item| item == 'D' }.should == false
        end

        it 'propagates an exception from the block' do
          -> { set.all? { |k,v| raise 'help' } }.should raise_error(RuntimeError)
        end

        it 'stops iterating as soon as the block returns false' do
          yielded = []
          set.all? { |k,v| yielded << k; false }
          yielded.size.should == 1
        end
      end

      describe 'with no block' do
        it 'returns true if all values are truthy' do
          S[true, 'A'].all?.should == true
        end

        [nil, false].each do |value|
          it "returns false if any value is #{value.inspect}" do
            S[value, true, 'A'].all?.should == false
          end
        end
      end
    end
  end
end