File: several_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 (29 lines) | stat: -rw-r--r-- 871 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
require 'spec_helper'

unless Enumerable.method_defined? :several
  describe 'Enumerable#several' do
    context 'with block' do
      it 'returns true if more than 1 element matches the predicate' do
        expect([1, 2, 3, 4].several?(&:even?)).to be_truthy
      end

      it 'returns false if just 1 element matches the predicate' do
        expect([1, 3, 4].several?(&:even?)).to be_falsey
      end

      it 'returns false if no elements match the predicate' do
        expect([1, 3, 4].several?(&:even?)).to be_falsey
      end
    end

    context 'without block' do
      it 'returns true if there are 2 or more non nil/false elements' do
        expect([1, 2, 3, 4].several?).to be_truthy
      end

      it 'returns false if there are less than 2 non nil/false elements' do
        expect([1, nil, false].several?).to be_falsey
      end
    end
  end
end