limit_detectors 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 19b534365562333e42bee1656992c44a58935616
4
- data.tar.gz: 4e4eedd3a948fdbdd494d8b9ad4be99741822b84
3
+ metadata.gz: 7644179e8d3eebef16e330ab12f116dd998bd296
4
+ data.tar.gz: dfa8b5e932662cfacb2ae1544a8fc45e02efba88
5
5
  SHA512:
6
- metadata.gz: 551125436affcdaf9720eadeec53ee228b9d217ab298e6553bd6c498f8aa5b642179c50c32ac26a3b1c67cebf1feeeed26acf7ae3ac0f74a95862d1aaa877e10
7
- data.tar.gz: 21eed54f9b88dcfec2b964b17c8afe80c086e37e4a41c7a36f2cb0d10cbce57f377460a5c4281736f718779b6c0022266aec27004625fbea8c527db3eea44a4c
6
+ metadata.gz: 524180318768013866c5b7fa49adf446cbd2dc0062f596676cdd83ceac77a19bcf1c71b47a4b9c81014566609890965204bd6a69a091d4d3d3e912d63ac7368f
7
+ data.tar.gz: 6a4d3d272d93b6220e7194904e949d48da916169bf7cc7260137a6bad65df98ec8f604cc44a6322f2a97fed5917b79543dcd699b2947035e074c9e09b4123acc
data/.travis.yml CHANGED
@@ -5,3 +5,5 @@ rvm:
5
5
  - "2.0"
6
6
  - "2.1"
7
7
  - "2.1.1"
8
+ - jruby
9
+ - rbx
data/Gemfile CHANGED
@@ -2,3 +2,11 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in limit_detectors.gemspec
4
4
  gemspec
5
+
6
+
7
+ # To support Rubinius on Travis-CI
8
+ platforms :rbx do
9
+ gem 'racc'
10
+ gem 'rubysl', '~> 2.0'
11
+ gem 'psych'
12
+ end
data/README.md CHANGED
@@ -48,13 +48,13 @@ may not be compatible with the current version.
48
48
 
49
49
  This gem is tested with these (MRI) Ruby versions:
50
50
 
51
- * 1.8.7
52
- * 1.9.3
53
- * 2.0
54
- * 2.1
55
- * 2.1.1
56
-
51
+ * 1.8.7,
52
+ * 1.9.3,
53
+ * 2.0,
54
+ * 2.1,
55
+ * 2.1.1,
57
56
 
57
+ as well as current version of Jruby and Rubinius.
58
58
 
59
59
  ## Contributing
60
60
 
@@ -2,15 +2,27 @@ require 'limit_detectors/version'
2
2
 
3
3
  module LimitDetectors
4
4
 
5
+ # Deprecated, use at_mmost? instead
6
+ def at_most(limit, &block)
7
+ Kernel.warn "'at_most' is deprecated, use 'at_most?' instead"
8
+ at_most? limit, &block
9
+ end
10
+
11
+ # Deprecated, use at_mmost? instead
12
+ def at_least(limit, &block)
13
+ Kernel.warn "'at_least' is deprecated, use 'at_least?' instead"
14
+ at_least? limit, &block
15
+ end
16
+
5
17
  # Check whether the condition given in the block
6
18
  # occurs at most limit times in the collection
7
- def at_most(limit, &block)
19
+ def at_most?(limit, &block)
8
20
  ocurrences_of(&block) <= limit
9
21
  end
10
22
 
11
23
  # Check whether the condition given in the block
12
24
  # occurs at least limit times in the collection
13
- def at_least(limit, &block)
25
+ def at_least?(limit, &block)
14
26
  ocurrences_of(&block) >= limit
15
27
  end
16
28
 
@@ -1,3 +1,3 @@
1
1
  module LimitDetectors
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
@@ -5,57 +5,70 @@ Array.send :include, LimitDetectors
5
5
  describe '#at_most' do
6
6
 
7
7
  it 'is true for an empty Array' do
8
- expect([].at_most(5){ true }).to be_true
8
+ expect(Kernel).to_not receive(:warn)
9
+ expect([].at_most?(5){ true }).to be_true
9
10
  end
10
11
 
11
12
  it 'is true if the criterion is met once' do
12
- expect(["it's there"].at_most(1){ |el| el == "it's there"}).to be_true
13
+ expect(["it's there"].at_most?(1){ |el| el == "it's there"}).to be_true
13
14
  end
14
15
 
15
16
  it 'is true if all elements meet the criterion and the size is the given maximum number' do
16
- expect([1,1,1].at_most(3){|e| e == 1})
17
+ expect([1,1,1].at_most?(3){|e| e == 1})
17
18
  end
18
19
 
19
20
  it 'is false if not enough elements meet the criterion' do
20
- expect([1, 2, 4].at_most(1){|e| e.even?}).to be_false
21
+ expect([1, 2, 4].at_most?(1){|e| e.even?}).to be_false
21
22
  end
22
23
 
23
24
  it 'is true if 0 elements are expected to match' do
24
25
  r = Array.new(10){rand}
25
- expect(r.at_most(0){ |i| i > 2 }).to be_true
26
+ expect(r.at_most?(0){ |i| i > 2 }).to be_true
26
27
  end
27
28
 
28
29
  describe 'Hash#at_most' do
29
30
  Hash.send :include, LimitDetectors
30
31
  it 'detects a condition based on key as well as value properties' do
31
32
  h = { 'foo' => 1, 'bar' => 4, 'baz' => 5, 'bum' => 1, 'fum' => 0}
32
- expect( h.at_most(3){|ky,vl| ky.match(/^b/) || vl > 1 }).to be_true
33
+ expect( h.at_most?(3){|ky,vl| ky.match(/^b/) || vl > 1 }).to be_true
33
34
  end
34
35
  end
35
36
 
36
37
  end
37
38
 
38
39
  describe '#at_least' do
39
- it 'is true for an empty Array' do
40
- expect([].at_least(1){ true }).to be_false
40
+ it 'is false for an empty Array' do
41
+ expect(Kernel).to_not receive(:warn)
42
+ expect([].at_least?(1){ true }).to be_false
43
+ expect([].at_least?(1){ false }).to be_false
41
44
  end
42
45
 
43
- it 'is true if the criterion is met once' do
44
- expect(["it's there"].at_least(1){ |el| el == "it's there"}).to be_true
46
+ it 'is true if the expected number is 0 and Array is empty' do
47
+ expect([].at_least?(0){ true }).to be_true
48
+ expect([].at_least?(0){ false }).to be_true
45
49
  end
46
50
 
47
- it 'is true if all elements meet the criterion and the size is the given maximum number' do
48
- expect([1,1,1].at_least(3){|e| e == 1})
51
+ it 'is false if the container ist smaller than the expected number' do
52
+ size = 10
53
+ expect(Array.new(10).at_least?(size + 1){true}).to be_false
49
54
  end
50
55
 
51
- it 'is false if not enough elements meet the criterion' do
52
- expect([1, 2, 4].at_least(1){|e| e.even?}).to be_true
56
+ it 'is true if the criterion is met and expected once' do
57
+ expect(["it's there"].at_least?(1){ |el| el == "it's there"}).to be_true
53
58
  end
54
59
 
55
- it 'is true if 0 elements are expected to match' do
60
+ it 'is true if all elements meet the criterion and the size is the given minimum number' do
61
+ expect([1,1,1].at_least?(3){|e| e == 1}).to be_true
62
+ end
63
+
64
+ it 'is true if enough elements meet the criterion' do
65
+ expect([1, 2, 4, 8].at_least?(2){|e| e.even?}).to be_true
66
+ end
67
+
68
+ it 'is true if there are enough elements to match' do
56
69
  r = Array.new(10){|i|i}
57
- expect(r.at_least(7){ |i| i > 2 }).to be_true
58
- expect(r.at_least(8){ |i| i > 2 }).to be_false
70
+ expect(r.at_least?(7){ |i| i > 2 }).to be_true
71
+ expect(r.at_least?(8){ |i| i > 2 }).to be_false
59
72
  end
60
73
 
61
74
  end
@@ -64,6 +77,18 @@ describe 'Using an object that doesn\'t respond to #inject will raise an excepti
64
77
  object = Object.new
65
78
  object.extend LimitDetectors
66
79
  it 'will raise an exception, if it\'s sent #atmost' do
67
- expect{ object.at_most(1){ |el| el.condition? } }.to raise_exception(NoMethodError, /undefined method .inject./)
80
+ expect{ object.at_most?(1){ |el| el.condition? } }.to raise_exception(NoMethodError, /undefined method .inject./)
68
81
  end
69
82
  end
83
+
84
+ describe 'Give a warning, if non-predicate versions are used' do
85
+ it 'sends message Kernel.warn, if old-style method is used for at_most' do
86
+ expect(Kernel).to receive(:warn).with(/'at_most'.+deprecated.+'at_most\?'/)
87
+ [1,2,4,8].at_most(2) {|e| e.even?}
88
+ end
89
+
90
+ it 'sends message Kernel.warn, if old-style method is used for at_least' do
91
+ expect(Kernel).to receive(:warn).with(/'at_least'.+deprecated.+'at_least\?'/)
92
+ [1,2,4,8].at_least(2) {|e| e.even?}
93
+ end
94
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: limit_detectors
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephan Kämper
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-21 00:00:00.000000000 Z
11
+ date: 2014-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler