limit_detectors 0.1.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.github/workflows/ruby.yml +32 -0
- data/.gitignore +2 -1
- data/.rspec +1 -0
- data/.rubocop.yml +8 -0
- data/Gemfile +2 -9
- data/README.md +60 -32
- data/Rakefile +3 -1
- data/example/example.rb +18 -0
- data/lib/limit_detectors/version.rb +3 -1
- data/lib/limit_detectors.rb +7 -7
- data/limit_detectors.gemspec +13 -9
- data/spec/limit_detectors_spec.rb +47 -51
- data/spec/spec_helper.rb +5 -3
- metadata +25 -23
- data/.travis.yml +0 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f4e23840f749e25f3a9a56bc29c20b4b6f2a6f2a633e7b966e79de77d7f7bb5c
|
4
|
+
data.tar.gz: c44f8e6ba2e29afcd9380fcb386a9b4fe221628b75ef07dba340e3b115883467
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 20ae2e520b58d17b2c56a0499988c3b6548a652866bc666c5096119a10741136783010bb18fde7ecf12840199d1c854e86949a3b252f5139c9169cb097477d30
|
7
|
+
data.tar.gz: ade449cf503a0cf86ca8696a309765485db269575608d3efcd339a32a55bf762f3deb0e208090a8b4a91c7f3ecee1d04b5279cf027de01768e45e400a4ba8d86
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
2
|
+
# They are provided by a third-party and are governed by
|
3
|
+
# separate terms of service, privacy policy, and support
|
4
|
+
# documentation.
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
7
|
+
|
8
|
+
name: Ruby
|
9
|
+
|
10
|
+
on:
|
11
|
+
push:
|
12
|
+
branches: [ main ]
|
13
|
+
pull_request:
|
14
|
+
branches: [ main ]
|
15
|
+
|
16
|
+
jobs:
|
17
|
+
test:
|
18
|
+
|
19
|
+
runs-on: ubuntu-latest
|
20
|
+
strategy:
|
21
|
+
matrix:
|
22
|
+
ruby-version: ['2.7', '3.0', '3.1', 'jruby', 'truffleruby']
|
23
|
+
|
24
|
+
steps:
|
25
|
+
- uses: actions/checkout@v2
|
26
|
+
- name: Set up Ruby
|
27
|
+
uses: ruby/setup-ruby@v1
|
28
|
+
with:
|
29
|
+
ruby-version: ${{ matrix.ruby-version }}
|
30
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
31
|
+
- name: Run tests
|
32
|
+
run: bundle exec rake
|
data/.gitignore
CHANGED
data/.rspec
CHANGED
data/.rubocop.yml
ADDED
data/Gemfile
CHANGED
@@ -1,13 +1,6 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
source 'https://rubygems.org'
|
2
4
|
|
3
5
|
# Specify your gem's dependencies in limit_detectors.gemspec
|
4
6
|
gemspec
|
5
|
-
|
6
|
-
|
7
|
-
# To support Rubinius on Travis-CI
|
8
|
-
platforms :rbx do
|
9
|
-
gem 'racc'
|
10
|
-
gem 'minitest'
|
11
|
-
gem 'rubysl'#, '~> 2.0'
|
12
|
-
gem 'psych'
|
13
|
-
end
|
data/README.md
CHANGED
@@ -4,12 +4,13 @@ Some methods to detect whether an Enumberable object contains a constrained numb
|
|
4
4
|
|
5
5
|
A second reason to create this gem is to explore various other services -- see the status list below.
|
6
6
|
|
7
|
-
|
7
|
+
|
8
|
+
## Status & Links
|
8
9
|
|
9
10
|
* Version: [](http://badge.fury.io/rb/limit_detectors)
|
10
|
-
*
|
11
|
-
*
|
12
|
-
*
|
11
|
+
* GitHub Actions: [](https://github.com/s2k/limit_detectors/actions)
|
12
|
+
* Travis CI: [](https://travis-ci.com/s2k/limit_detectors)
|
13
|
+
* Code Climate: [](https://codeclimate.com/github/s2k/limit_detectors/maintainability)
|
13
14
|
|
14
15
|
|
15
16
|
## Installation
|
@@ -26,57 +27,84 @@ Or install it yourself as:
|
|
26
27
|
|
27
28
|
$ gem install limit_detectors
|
28
29
|
|
30
|
+
|
29
31
|
## Usage
|
30
32
|
|
31
|
-
In your code you can `require 'limit_detectors'` then define
|
32
|
-
or other enumerable objects), extend these objects with LimitDetectors (or include the module in your class) and
|
33
|
-
then call `at_most?` (or àt_least?') on your object.
|
33
|
+
In your code, you can `require 'limit_detectors'` then define your classes and `include` module `LimitDetectors` in your class, or create enumerable objects and `extend` these objects with `LimitDetectors`. Then call `at_most?` (or `t_least?`) on your object.
|
34
34
|
|
35
|
-
For example:
|
35
|
+
For example using `pry`(you can use `irb` as well) you can do this:
|
36
36
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
[3] pry(main)> a.at_most?(4){|e| e.odd?}
|
43
|
-
=> true # There are indeed no more than 4 odd numbers in the array
|
44
|
-
[4] pry(main)> a.at_most?(1){|e| e.even?}
|
45
|
-
=> false # In fact there are two even numbers in the array
|
37
|
+
```ruby
|
38
|
+
[3] pry(main)> a.at_most?(4){|e| e.odd?}
|
39
|
+
=> true # There are indeed no more than 4 odd numbers in the array
|
40
|
+
[4] pry(main)> a.at_most?(1){|e| e.even?}
|
41
|
+
=> false # In fact there are two even numbers in the array
|
46
42
|
|
47
|
-
|
43
|
+
$ pry -I lib -r limit_detectors
|
44
|
+
[1] pry(main)> a = [1, 2, 3, 4, 5]
|
45
|
+
=> [1, 2, 3, 4, 5]
|
46
|
+
[2] pry(main)> a.extend LimitDetectors
|
47
|
+
=> [1, 2, 3, 4, 5]
|
48
|
+
[3] pry(main)> a.at_most?(4){|e| e.odd?}
|
49
|
+
=> true # There are indeed no more than 4 odd numbers in the array
|
50
|
+
[4] pry(main)> a.at_most?(4, &:odd?)
|
51
|
+
=> true # The same behaviour using a different notation
|
52
|
+
[5] pry(main)> a.at_most?(1){|e| e.even?}
|
53
|
+
=> false # In fact there are two even numbers in the array
|
54
|
+
```
|
55
|
+
|
56
|
+
In code the usage may look like this (see example/example.rb for the file):
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
require 'limit_detectors'
|
60
|
+
|
61
|
+
class Example
|
62
|
+
include Enumerable
|
63
|
+
def each
|
64
|
+
('a'..'d').each { |c| yield c }
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
e = Example.new
|
69
|
+
e.extend LimitDetectors
|
48
70
|
|
49
|
-
|
50
|
-
|
71
|
+
|
72
|
+
puts e.at_least?(1) { |c| 'f' == c }
|
73
|
+
puts e.at_least?(1) { |c| 'b' == c }
|
74
|
+
puts e.at_most?(0) { |c| 'b' == c }
|
75
|
+
puts e.at_most?(42) { |c| 'b' == c }
|
76
|
+
```
|
77
|
+
|
78
|
+
|
79
|
+
## Compatibility
|
51
80
|
|
52
81
|
This gem is tested with these Ruby versions (MRI, unless JRuby):
|
53
82
|
|
54
|
-
- 2.
|
55
|
-
-
|
56
|
-
-
|
57
|
-
- 2.3.0
|
58
|
-
- 2.3.1
|
59
|
-
- 2.4.0-preview1
|
60
|
-
- jruby
|
83
|
+
- 2.7
|
84
|
+
- 3.0
|
85
|
+
- 3.1
|
61
86
|
|
62
|
-
as well as a current version of JRuby
|
87
|
+
as well as a current version of JRuby and TruffleRuby
|
63
88
|
|
64
89
|
## Contributing
|
65
90
|
|
66
|
-
1. Fork it ( https://github.com/[my-github-username]/limit_detectors/fork
|
91
|
+
1. Fork it ( https://github.com/[my-github-username]/limit_detectors/fork)
|
67
92
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
68
93
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
69
94
|
4. Push to the branch (`git push origin my-new-feature`)
|
70
95
|
5. Create a new Pull Request
|
71
96
|
|
97
|
+
A more detailed description is at https://opensource.com/article/19/7/create-pull-request-github
|
98
|
+
|
99
|
+
|
72
100
|
### Reporting a bug
|
73
101
|
|
74
102
|
Please, provide answers to the following questions, when submitting a bug report:
|
75
103
|
|
76
|
-
1. What's
|
77
|
-
2. What's the
|
104
|
+
1. What's _actually_ happening? What is the observed behaviour?
|
105
|
+
2. What's the _expectation_, i.e. what should have happened?
|
78
106
|
3. Why did you expect this behaviour?
|
79
107
|
|
80
|
-
If you provide an RSpec check that demonstrates the bug, would give extra good karma,
|
108
|
+
If you provide an `RSpec` check that demonstrates the bug, would give extra good karma,
|
81
109
|
especially in case of a minimal check, something that just demonstrates the bug without
|
82
110
|
any (or much) overhead.
|
data/Rakefile
CHANGED
data/example/example.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'limit_detectors'
|
4
|
+
|
5
|
+
class Example
|
6
|
+
include Enumerable
|
7
|
+
def each(&block)
|
8
|
+
('a'..'d').each(&block)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
e = Example.new
|
13
|
+
e.extend LimitDetectors
|
14
|
+
|
15
|
+
puts e.at_least?(1) { |c| c == 'f' }
|
16
|
+
puts e.at_least?(1) { |c| c == 'b' }
|
17
|
+
puts e.at_most?(0) { |c| c == 'b' }
|
18
|
+
puts e.at_most?(42) { |c| c == 'b' }
|
data/lib/limit_detectors.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'limit_detectors/version'
|
2
4
|
|
3
5
|
module LimitDetectors
|
4
|
-
|
5
6
|
# Deprecated, use at_most? instead
|
6
7
|
def at_most(limit, &block)
|
7
8
|
Kernel.warn "'at_most' is deprecated, use 'at_most?' instead"
|
@@ -17,22 +18,21 @@ module LimitDetectors
|
|
17
18
|
# Check whether the condition given in the block
|
18
19
|
# occurs at most limit times in the collection
|
19
20
|
def at_most?(limit, &block)
|
20
|
-
|
21
|
+
occurrences_of(&block) <= limit
|
21
22
|
end
|
22
23
|
|
23
24
|
# Check whether the condition given in the block
|
24
25
|
# occurs at least limit times in the collection
|
25
26
|
def at_least?(limit, &block)
|
26
|
-
|
27
|
+
occurrences_of(&block) >= limit
|
27
28
|
end
|
28
29
|
|
29
30
|
# Count how often the condition given in the block
|
30
31
|
# is met for the collection
|
31
|
-
def
|
32
|
-
inject(0)
|
32
|
+
def occurrences_of
|
33
|
+
inject(0) do |res, el|
|
33
34
|
res += 1 if yield el
|
34
35
|
res
|
35
|
-
|
36
|
+
end
|
36
37
|
end
|
37
|
-
|
38
38
|
end
|
data/limit_detectors.gemspec
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
5
|
require 'limit_detectors/version'
|
5
6
|
|
@@ -8,19 +9,22 @@ Gem::Specification.new do |spec|
|
|
8
9
|
spec.version = LimitDetectors::VERSION
|
9
10
|
spec.authors = ['Stephan Kämper']
|
10
11
|
spec.email = ['the.tester@seasidetesting.com']
|
11
|
-
spec.summary =
|
12
|
-
spec.description =
|
12
|
+
spec.summary = 'Detect certain conditions of elements of an Enumerable object'
|
13
|
+
spec.description = 'Some methods to detect whether an Enumerable object contains a constrained number of elements that match a given condition.'
|
13
14
|
spec.homepage = ''
|
14
15
|
spec.license = 'MIT'
|
15
16
|
|
16
17
|
spec.files = `git ls-files -z`.split("\x0")
|
17
18
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
19
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = [
|
20
|
+
spec.require_paths = ['lib']
|
20
21
|
|
21
22
|
spec.add_development_dependency 'bundler'
|
22
|
-
spec.add_development_dependency '
|
23
|
-
spec.add_development_dependency '
|
24
|
-
spec.add_development_dependency '
|
25
|
-
spec.add_development_dependency '
|
23
|
+
spec.add_development_dependency 'pry', '~> 0.14.1'
|
24
|
+
spec.add_development_dependency 'pry-doc', '~> 1.2.0'
|
25
|
+
spec.add_development_dependency 'rake', '~> 13.0.6'
|
26
|
+
spec.add_development_dependency 'rspec', '~> 3.10'
|
27
|
+
spec.metadata = {
|
28
|
+
'rubygems_mfa_required' => 'true'
|
29
|
+
}
|
26
30
|
end
|
@@ -1,141 +1,137 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'set'
|
3
4
|
|
4
|
-
Array.
|
5
|
+
Array.include LimitDetectors
|
5
6
|
|
6
7
|
describe '#at_most' do
|
7
|
-
|
8
8
|
it 'is true for an empty Array' do
|
9
9
|
expect(Kernel).to_not receive(:warn)
|
10
|
-
expect([].at_most?(5){ true }).to be_truthy
|
11
|
-
expect([].at_most?(0){ true }).to be_truthy
|
12
|
-
expect([].at_most?(1){ true }).to be_truthy
|
13
|
-
expect([].at_most?(5){ :foo }).to be_truthy
|
10
|
+
expect([].at_most?(5) { true }).to be_truthy
|
11
|
+
expect([].at_most?(0) { true }).to be_truthy
|
12
|
+
expect([].at_most?(1) { true }).to be_truthy
|
13
|
+
expect([].at_most?(5) { :foo }).to be_truthy
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'is true if the criterion is met once' do
|
17
|
-
expect(["it's there"].at_most?(1){ |el| el == "it's there"}).to be_truthy
|
17
|
+
expect(["it's there"].at_most?(1) { |el| el == "it's there" }).to be_truthy
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'is true if all elements meet the criterion and the size is the given maximum number' do
|
21
|
-
expect([1,1,1].at_most?(3){|e| e == 1})
|
21
|
+
expect([1, 1, 1].at_most?(3) { |e| e == 1 })
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'is false if not enough elements meet the criterion' do
|
25
|
-
expect([1, 2, 4].at_most?(1
|
25
|
+
expect([1, 2, 4].at_most?(1, &:even?)).to be_falsey
|
26
26
|
end
|
27
27
|
|
28
28
|
it 'is true if 0 elements are expected to match' do
|
29
|
-
r = Array.new(10){rand}
|
30
|
-
expect(r.at_most?(0){ |i| i > 2 }).to be_truthy
|
29
|
+
r = Array.new(10) { rand }
|
30
|
+
expect(r.at_most?(0) { |i| i > 2 }).to be_truthy
|
31
31
|
end
|
32
32
|
|
33
33
|
describe 'Hash#at_most' do
|
34
|
-
Hash.
|
34
|
+
Hash.include LimitDetectors
|
35
35
|
it 'detects a condition based on key as well as value properties' do
|
36
|
-
h = { 'foo' => 1, 'bar' => 4, 'baz' => 5, 'bum' => 1, 'fum' => 0}
|
37
|
-
expect(
|
36
|
+
h = { 'foo' => 1, 'bar' => 4, 'baz' => 5, 'bum' => 1, 'fum' => 0 }
|
37
|
+
expect(h.at_most?(3) { |ky, vl| ky.match(/^b/) || vl > 1 }).to be_truthy
|
38
38
|
end
|
39
39
|
end
|
40
|
-
|
41
40
|
end
|
42
41
|
|
43
42
|
describe '#at_least' do
|
44
|
-
|
45
43
|
it 'is false for an empty Array, if at least one is expected' do
|
46
44
|
expect(Kernel).to_not receive(:warn)
|
47
|
-
expect([].at_least?(1){ true }).to be_falsey
|
45
|
+
expect([].at_least?(1) { true }).to be_falsey
|
48
46
|
end
|
49
47
|
|
50
48
|
it 'is true if the expected number is 0 and Array is empty' do
|
51
|
-
expect([].at_least?(0){ true }).to be_truthy
|
52
|
-
expect({}.at_least?(0){ false }).to be_truthy
|
49
|
+
expect([].at_least?(0) { true }).to be_truthy
|
50
|
+
expect({}.at_least?(0) { false }).to be_truthy
|
53
51
|
end
|
54
52
|
|
55
53
|
it 'is false if the container ist smaller than the expected number' do
|
56
54
|
size = 10
|
57
|
-
expect(Array.new(10).at_least?(size + 1){true}).to be_falsey
|
55
|
+
expect(Array.new(10).at_least?(size + 1) { true }).to be_falsey
|
58
56
|
end
|
59
57
|
|
60
58
|
it 'is true if the criterion is met and expected once' do
|
61
|
-
expect(["it's there"].at_least?(1){ |el| el == "it's there"}).to be_truthy
|
59
|
+
expect(["it's there"].at_least?(1) { |el| el == "it's there" }).to be_truthy
|
62
60
|
end
|
63
61
|
|
64
|
-
it 'is false for an empty Array if you expect at
|
65
|
-
expect([].at_least?(1){ true }).to be_falsey
|
62
|
+
it 'is false for an empty Array if you expect at least 1' do
|
63
|
+
expect([].at_least?(1) { true }).to be_falsey
|
66
64
|
end
|
67
65
|
|
68
|
-
it 'is true for an empty Array if you expect at
|
69
|
-
expect([].at_least?(0){
|
66
|
+
it 'is true for an empty Array if you expect at least 0' do
|
67
|
+
expect([].at_least?(0) {}).to be_truthy
|
70
68
|
end
|
71
69
|
|
72
70
|
it 'is true if the criterion is met once' do
|
73
|
-
expect(["it's there"].at_least?(1){ |el| el == "it's there"}).to be_truthy
|
71
|
+
expect(["it's there"].at_least?(1) { |el| el == "it's there" }).to be_truthy
|
74
72
|
end
|
75
73
|
|
76
74
|
it 'is true if all elements meet the criterion and the size is the given minimum number' do
|
77
|
-
expect([1,1,1].at_least?(3){|e| e == 1}).to be_truthy
|
75
|
+
expect([1, 1, 1].at_least?(3) { |e| e == 1 }).to be_truthy
|
78
76
|
end
|
79
77
|
|
80
78
|
it 'is true if enough elements meet the criterion' do
|
81
|
-
expect([1, 2, 4, 8].at_least?(2
|
79
|
+
expect([1, 2, 4, 8].at_least?(2, &:even?)).to be_truthy
|
82
80
|
end
|
83
81
|
|
84
82
|
it 'is true if there are enough elements to match' do
|
85
|
-
r = Array.new(10){|i|i}
|
86
|
-
expect(r.at_least?(7){ |i| i > 2 }).to be_truthy
|
87
|
-
expect(r.at_least?(8){ |i| i > 2 }).to be_falsey
|
83
|
+
r = Array.new(10) { |i| i }
|
84
|
+
expect(r.at_least?(7) { |i| i > 2 }).to be_truthy
|
85
|
+
expect(r.at_least?(8) { |i| i > 2 }).to be_falsey
|
88
86
|
end
|
89
|
-
|
90
87
|
end
|
91
88
|
|
92
89
|
describe '#ocurrences_of' do
|
93
90
|
context 'collection with content' do
|
94
|
-
Set.
|
95
|
-
subject{ Set.new(
|
91
|
+
Set.include LimitDetectors
|
92
|
+
subject { Set.new([1, 2, 3, 4, 5, 6, 7]) }
|
96
93
|
|
97
|
-
it('counts 3 even numbers') { expect(
|
98
|
-
it('counts 4 odd numbers') { expect(
|
99
|
-
it('counts no number < 0') { expect(
|
100
|
-
it('counts 7 positive numbers') { expect(
|
94
|
+
it('counts 3 even numbers') { expect(subject.occurrences_of(&:even?)).to be 3 }
|
95
|
+
it('counts 4 odd numbers') { expect(subject.occurrences_of(&:odd?)).to be 4 }
|
96
|
+
it('counts no number < 0') { expect(subject.occurrences_of { |e| e < 0 }).to be 0 }
|
97
|
+
it('counts 7 positive numbers') { expect(subject.occurrences_of { |e| e > 0 }).to be 7 }
|
101
98
|
end
|
102
99
|
|
103
100
|
context 'empty collection' do
|
104
101
|
it 'counts 0 for any empty collection' do
|
105
|
-
[[], Set.new, {}].each do |
|
106
|
-
expect(obj.
|
102
|
+
[[], Set.new, {}].each do |obj|
|
103
|
+
expect(obj.occurrences_of { true }).to be(0), "Expected to count 0, for an empty #{obj.class}"
|
107
104
|
end
|
108
105
|
end
|
109
106
|
end
|
110
107
|
|
111
|
-
it('
|
108
|
+
it("doesn't return nil") { expect([1].occurrences_of {}).not_to be_nil }
|
112
109
|
end
|
113
110
|
|
114
|
-
|
115
|
-
describe 'Using an object that doesn\'t respond to #inject' do
|
111
|
+
describe "Using an object that doesn't respond to #inject" do
|
116
112
|
object = Object.new
|
117
113
|
object.extend LimitDetectors
|
118
114
|
it 'will raise an exception, if it\'s sent #at_most' do
|
119
|
-
expect{ object.at_most?(1
|
115
|
+
expect { object.at_most?(1, &:condition?) }.to raise_exception(NoMethodError, /undefined method .inject./)
|
120
116
|
end
|
121
117
|
end
|
122
118
|
|
123
119
|
describe 'Give a warning, if non-predicate versions are used' do
|
124
120
|
it 'yields a warning for old-style at_most' do
|
125
121
|
expect(Kernel).to receive(:warn).with(/'at_most'.+deprecated.+'at_most\?'/)
|
126
|
-
[1,2,4,8].at_most(2
|
122
|
+
[1, 2, 4, 8].at_most(2, &:even?)
|
127
123
|
end
|
128
124
|
|
129
125
|
it 'yields a warning for old-style at_least' do
|
130
126
|
expect(Kernel).to receive(:warn).with(/'at_least'.+deprecated.+'at_least\?'/)
|
131
|
-
[1,2,4,8].at_least(2
|
132
|
-
end
|
127
|
+
[1, 2, 4, 8].at_least(2, &:even?)
|
133
128
|
end
|
129
|
+
end
|
134
130
|
|
135
131
|
describe 'When the provided block raises an exception' do
|
136
|
-
subject{ [1] }
|
132
|
+
subject { [1] }
|
137
133
|
it 'passes up the stack unchanged' do
|
138
|
-
expect{ subject.at_most?(1) { raise ArgumentError, 'BoomError' } }.to raise_error(ArgumentError, 'BoomError')
|
139
|
-
expect{ subject.
|
134
|
+
expect { subject.at_most?(1) { raise ArgumentError, 'BoomError' } }.to raise_error(ArgumentError, 'BoomError')
|
135
|
+
expect { subject.occurrences_of { raise ArgumentError, 'BoomError' } }.to raise_error(ArgumentError, 'BoomError')
|
140
136
|
end
|
141
137
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'limit_detectors'
|
2
4
|
|
3
5
|
# This file was generated by the `rspec --init` command. Conventionally, all
|
@@ -7,9 +9,9 @@ require 'limit_detectors'
|
|
7
9
|
#
|
8
10
|
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
9
11
|
RSpec.configure do |config|
|
10
|
-
#config.treat_symbols_as_metadata_keys_with_true_values = true
|
11
|
-
#config.run_all_when_everything_filtered = true
|
12
|
-
#config.filter_run :focus
|
12
|
+
# config.treat_symbols_as_metadata_keys_with_true_values = true
|
13
|
+
# config.run_all_when_everything_filtered = true
|
14
|
+
# config.filter_run :focus
|
13
15
|
|
14
16
|
# Run specs in random order to surface order dependencies. If you find an
|
15
17
|
# order dependency and want to debug it, you can fix the order by providing
|
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.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephan Kämper
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-12-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -25,61 +25,61 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: pry
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 0.14.1
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 0.14.1
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: pry-doc
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 1.2.0
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 1.2.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 13.0.6
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 13.0.6
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '3.10'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '3.10'
|
83
83
|
description: Some methods to detect whether an Enumerable object contains a constrained
|
84
84
|
number of elements that match a given condition.
|
85
85
|
email:
|
@@ -88,13 +88,15 @@ executables: []
|
|
88
88
|
extensions: []
|
89
89
|
extra_rdoc_files: []
|
90
90
|
files:
|
91
|
+
- ".github/workflows/ruby.yml"
|
91
92
|
- ".gitignore"
|
92
93
|
- ".rspec"
|
93
|
-
- ".
|
94
|
+
- ".rubocop.yml"
|
94
95
|
- Gemfile
|
95
96
|
- LICENSE.txt
|
96
97
|
- README.md
|
97
98
|
- Rakefile
|
99
|
+
- example/example.rb
|
98
100
|
- lib/limit_detectors.rb
|
99
101
|
- lib/limit_detectors/version.rb
|
100
102
|
- limit_detectors.gemspec
|
@@ -103,8 +105,9 @@ files:
|
|
103
105
|
homepage: ''
|
104
106
|
licenses:
|
105
107
|
- MIT
|
106
|
-
metadata:
|
107
|
-
|
108
|
+
metadata:
|
109
|
+
rubygems_mfa_required: 'true'
|
110
|
+
post_install_message:
|
108
111
|
rdoc_options: []
|
109
112
|
require_paths:
|
110
113
|
- lib
|
@@ -119,9 +122,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
119
122
|
- !ruby/object:Gem::Version
|
120
123
|
version: '0'
|
121
124
|
requirements: []
|
122
|
-
|
123
|
-
|
124
|
-
signing_key:
|
125
|
+
rubygems_version: 3.3.4
|
126
|
+
signing_key:
|
125
127
|
specification_version: 4
|
126
128
|
summary: Detect certain conditions of elements of an Enumerable object
|
127
129
|
test_files:
|