Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Enumerable#exactly? - more examples, more specs

  • Loading branch information...
commit 7c4d78000c68b0ec0a1f5a74519a070529999e6d 1 parent 142be7d
Peter Vandenberk pvdb authored
4 lib/powerpack/enumerable/exactly.rb
View
@@ -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
16 spec/powerpack/enumerable/exactly_spec.rb
View
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.