File: exactly_spec.rb

package info (click to toggle)
ruby-powerpack 0.1.1-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 492 kB
  • sloc: ruby: 819; makefile: 3
file content (41 lines) | stat: -rw-r--r-- 1,361 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
require 'spec_helper'

unless Enumerable.method_defined? :exactly
  describe 'Enumerable#exactly' do
    context 'with block' do
      it 'returns true for exact number of matches' do
        expect([1, 2, 3, 4].exactly?(2, &:even?)).to be_truthy
      end

      it 'returns false for less matches' do
        expect([1, 3, 4].exactly?(2, &:even?)).to be_falsey
      end

      it 'returns false for more matches' do
        expect([1, 3, 4, 6, 8].exactly?(2, &:even?)).to be_falsey
      end
    end

    context 'without block' do
      it 'returns true for exact number of non nil/false elements in absence of nil/false elements' do
        expect([1, 2, 3, 4].exactly?(4)).to be_truthy
      end

      it 'returns true for exact number of non nil/false elements in presence of nil/false elements' do
        expect([1, 2, nil, false].exactly?(2)).to be_truthy
      end

      it 'returns true for exact number of nil/false elements' do
        expect([nil, false].exactly?(0)).to be_truthy
      end

      it 'returns false if there are less non nil/false elements in absence of nil/false elements' do
        expect([1, 2, 3].exactly?(4)).to be_falsey
      end

      it 'returns false if there are less non nil/false elements in presence of nil/false elements' do
        expect([1, nil, false].exactly?(4)).to be_falsey
      end
    end
  end
end