Skip to content

Commit

Permalink
Enumerable#exactly? - more examples, more specs
Browse files Browse the repository at this point in the history
  • Loading branch information
pvdb committed Sep 6, 2013
1 parent 142be7d commit 7c4d780
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/powerpack/enumerable/exactly.rb
Expand Up @@ -14,7 +14,9 @@ module Enumerable
# This means that nil and false elements will be ignored.
#
# @example
# [1, false, nil].exactly? #=> false
# [1, false, nil].exactly?(3) #=> false
# [1, false, nil].exactly?(1) #=> true
# [false, nil].exactly?(0) #=> true
# [1, 2, 3].exactly?(3) #=>true
def exactly?(n)
found_count = 0
Expand Down
16 changes: 14 additions & 2 deletions spec/powerpack/enumerable/exactly_spec.rb
Expand Up @@ -16,11 +16,23 @@
end

context 'without block' do
it 'returns true for exact number of non nil/false elements' 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_true
end

it 'returns false if there are less non nil/false elements' do
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_true
end

it 'returns true for exact number of nil/false elements' do
expect([nil, false].exactly?(0)).to be_true
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_false
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_false
end
end
Expand Down

0 comments on commit 7c4d780

Please sign in to comment.