invoca-utils 0.4.1 → 0.5.1
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 +4 -4
- data/.github/workflows/pipeline.yml +40 -0
- data/.gitignore +28 -17
- data/.rspec +3 -0
- data/.ruby-version +1 -1
- data/.tool-versions +1 -0
- data/Appraisals +13 -0
- data/CHANGELOG.md +12 -1
- data/Gemfile +9 -16
- data/Gemfile.lock +39 -48
- data/Rakefile +9 -6
- data/gemfiles/activesupport_5.gemfile +12 -0
- data/gemfiles/activesupport_6.gemfile +12 -0
- data/gemfiles/activesupport_7.gemfile +12 -0
- data/invoca-utils.gemspec +18 -6
- data/lib/invoca/utils/version.rb +1 -1
- data/{test → spec}/helpers/constant_overrides.rb +0 -0
- data/spec/spec_helper.rb +16 -0
- data/spec/unit/array_spec.rb +20 -0
- data/spec/unit/enumerable_spec.rb +80 -0
- data/{test/unit/exceptions_test.rb → spec/unit/exceptions_spec.rb} +17 -17
- data/spec/unit/guaranteed_utf8_string_spec.rb +260 -0
- data/spec/unit/hash_spec.rb +81 -0
- data/spec/unit/hash_with_indifferent_access_spec.rb +100 -0
- data/spec/unit/map_compact_spec.rb +25 -0
- data/{test/unit/module_test.rb → spec/unit/module_spec.rb} +4 -4
- data/spec/unit/multi_sender_spec.rb +54 -0
- data/{test/unit/stable_sort_test.rb → spec/unit/stable_sort_spec.rb} +14 -14
- data/spec/unit/time_calculations_spec.rb +39 -0
- data/{test/unit/utils_test.rb → spec/unit/utils_spec.rb} +14 -14
- metadata +56 -37
- data/.jenkins/Jenkinsfile +0 -50
- data/.jenkins/ruby_build_pod.yml +0 -19
- data/test/test_helper.rb +0 -14
- data/test/unit/array_test.rb +0 -20
- data/test/unit/enumerable_test.rb +0 -80
- data/test/unit/guaranteed_utf8_string_test.rb +0 -263
- data/test/unit/hash_test.rb +0 -81
- data/test/unit/hash_with_indifferent_access_test.rb +0 -100
- data/test/unit/map_compact_test.rb +0 -25
- data/test/unit/multi_sender_test.rb +0 -56
- data/test/unit/time_calculations_test.rb +0 -39
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c8684fc70ce068552001b1cd99cf11a8f60882e23d46b9a56f94276e5c5b6403
|
|
4
|
+
data.tar.gz: c429285201930b90be6ea32d043f9625fcd22b493b6c4871ea912d55800958d2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a8c825cfa1b59d065cd8ea81a56cbe1e1d5c1acd277b2d9d05b452392b027de3a07acd6537aef12732fe70b7994b3aa2a0b74c03355c053b3c4d0db6552ccf43
|
|
7
|
+
data.tar.gz: e641a1ef06cd907e48d5b6addec2bcb8ae27b125528ec645bd2366153938245c0a3de6635241aebe416a86a196509337c6ad9a88ee3685d97d84ceb60e11f3e1
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Pipeline
|
|
3
|
+
|
|
4
|
+
on: [push]
|
|
5
|
+
|
|
6
|
+
jobs:
|
|
7
|
+
tests:
|
|
8
|
+
runs-on: ubuntu-22.04
|
|
9
|
+
|
|
10
|
+
strategy:
|
|
11
|
+
fail-fast: false
|
|
12
|
+
matrix:
|
|
13
|
+
ruby: [2.5, 2.6, 2.7, '3.0', 3.1, 3.2]
|
|
14
|
+
gemfile:
|
|
15
|
+
- Gemfile
|
|
16
|
+
- gemfiles/activesupport_5.gemfile
|
|
17
|
+
- gemfiles/activesupport_6.gemfile
|
|
18
|
+
- gemfiles/activesupport_7.gemfile
|
|
19
|
+
exclude:
|
|
20
|
+
- ruby: 2.5
|
|
21
|
+
gemfile: gemfiles/activesupport_7.gemfile
|
|
22
|
+
- ruby: 2.6
|
|
23
|
+
gemfile: gemfiles/activesupport_7.gemfile
|
|
24
|
+
|
|
25
|
+
env:
|
|
26
|
+
BUNDLE_GEMFILE: ${{ matrix.gemfile }}
|
|
27
|
+
|
|
28
|
+
name: Unit Tests (${{ matrix.ruby }} - ${{ matrix.gemfile }})
|
|
29
|
+
|
|
30
|
+
steps:
|
|
31
|
+
- name: Check out
|
|
32
|
+
uses: actions/checkout@v2
|
|
33
|
+
- name: Set up Ruby ${{ matrix.ruby }}
|
|
34
|
+
uses: ruby/setup-ruby@v1
|
|
35
|
+
with:
|
|
36
|
+
ruby-version: ${{ matrix.ruby }}
|
|
37
|
+
bundler: 2.2.29
|
|
38
|
+
bundler-cache: true
|
|
39
|
+
- name: Run Tests
|
|
40
|
+
run: bundle exec rspec
|
data/.gitignore
CHANGED
|
@@ -1,26 +1,37 @@
|
|
|
1
|
+
# OS artifacts
|
|
1
2
|
.DS_Store
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
.
|
|
5
|
-
|
|
3
|
+
|
|
4
|
+
# IDEs
|
|
5
|
+
.idea/
|
|
6
|
+
|
|
7
|
+
# Documentation artifacts
|
|
6
8
|
.yardoc
|
|
7
|
-
InstalledFiles
|
|
8
9
|
_yardoc
|
|
9
|
-
coverage
|
|
10
10
|
doc/
|
|
11
|
-
lib/bundler/man
|
|
12
|
-
pkg
|
|
13
|
-
pkg/
|
|
14
11
|
rdoc
|
|
15
|
-
test/reports
|
|
16
|
-
test/tmp
|
|
17
|
-
test/version_tmp
|
|
18
12
|
|
|
19
|
-
|
|
13
|
+
# Rubocop
|
|
14
|
+
.rubocop-http*
|
|
15
|
+
|
|
16
|
+
# test artifacts
|
|
17
|
+
spec/reports
|
|
18
|
+
coverage
|
|
19
|
+
|
|
20
|
+
# Appraisal
|
|
21
|
+
gemfiles/*.lock
|
|
22
|
+
|
|
23
|
+
# gem building artifacts
|
|
24
|
+
*.a
|
|
20
25
|
*.bundle
|
|
21
|
-
*.
|
|
26
|
+
*.gem
|
|
22
27
|
*.o
|
|
23
|
-
*.
|
|
28
|
+
*.rbc
|
|
29
|
+
*.so
|
|
30
|
+
.bundle
|
|
31
|
+
.config
|
|
32
|
+
InstalledFiles
|
|
33
|
+
checksums
|
|
34
|
+
lib/bundler/man
|
|
24
35
|
mkmf.log
|
|
25
|
-
|
|
26
|
-
|
|
36
|
+
pkg
|
|
37
|
+
tmp
|
data/.rspec
ADDED
data/.ruby-version
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.
|
|
1
|
+
2.7.5
|
data/.tool-versions
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ruby 2.7.5
|
data/Appraisals
ADDED
data/CHANGELOG.md
CHANGED
|
@@ -2,7 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
Inspired by [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|
4
4
|
|
|
5
|
-
Note
|
|
5
|
+
**Note:** This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
|
+
|
|
7
|
+
## [0.5.1] - 2023-02-17
|
|
8
|
+
### Added
|
|
9
|
+
- Integrated Appraisal into github actions for testing across multiple versions of ActiveSupport
|
|
10
|
+
-
|
|
11
|
+
## [0.5.0] - 2023-02-10
|
|
12
|
+
### Added
|
|
13
|
+
- Relaxed version requirement for ActiveSupport
|
|
6
14
|
|
|
7
15
|
## [0.4.1] - 2020-06-17
|
|
8
16
|
### Fixed
|
|
@@ -27,6 +35,9 @@ Note: This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0
|
|
|
27
35
|
- Enumerable::build_hash method ported from HoboSupport
|
|
28
36
|
- Enumerable::* operator ported from HoboSupport
|
|
29
37
|
|
|
38
|
+
[0.5.1]: https://github.com/Invoca/invoca-utils/compare/v0.5.0...v0.5.1
|
|
39
|
+
[0.5.0]: https://github.com/Invoca/invoca-utils/compare/v0.4.1...v0.5.0
|
|
40
|
+
[0.4.1]: https://github.com/Invoca/invoca-utils/compare/v0.4.0...v0.4.1
|
|
30
41
|
[0.4.0]: https://github.com/Invoca/invoca-utils/compare/v0.3.0...v0.4.0
|
|
31
42
|
[0.3.0]: https://github.com/Invoca/invoca-utils/compare/v0.2.0...v0.3.0
|
|
32
43
|
[0.2.0]: https://github.com/Invoca/invoca-utils/compare/v0.1.1...v0.2.0
|
data/Gemfile
CHANGED
|
@@ -2,21 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
source 'https://rubygems.org'
|
|
4
4
|
|
|
5
|
+
# Specify your gem's run time dependencies in invoca-utils.gemspec
|
|
5
6
|
gemspec
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
gem 'shoulda', '= 3.5.0'
|
|
16
|
-
gem 'test-unit', '= 1.2.3'
|
|
17
|
-
gem 'tzinfo'
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
source 'https://gem.fury.io/invoca' do
|
|
21
|
-
gem 'test_overrides', '~> 0.13'
|
|
22
|
-
end
|
|
8
|
+
# Specify your gem's development and test dependencies below
|
|
9
|
+
gem "appraisal", "~> 2.4"
|
|
10
|
+
gem "rake", "~> 13.0"
|
|
11
|
+
gem "rspec", "~> 3.0"
|
|
12
|
+
gem "rspec_junit_formatter", "~> 0.4"
|
|
13
|
+
# minitest, which is a transitive dependency of activesupport,
|
|
14
|
+
# version should support ruby 2.5 which is the minimum github pipeline targets
|
|
15
|
+
gem "minitest", "~> 5.10.0"
|
data/Gemfile.lock
CHANGED
|
@@ -1,68 +1,59 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
invoca-utils (0.
|
|
4
|
+
invoca-utils (0.5.1)
|
|
5
|
+
activesupport (>= 5.0)
|
|
5
6
|
|
|
6
7
|
GEM
|
|
7
8
|
remote: https://rubygems.org/
|
|
8
|
-
remote: https://gem.fury.io/invoca/
|
|
9
9
|
specs:
|
|
10
|
-
activesupport (
|
|
11
|
-
|
|
10
|
+
activesupport (5.2.8.1)
|
|
11
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
12
|
+
i18n (>= 0.7, < 2)
|
|
12
13
|
minitest (~> 5.1)
|
|
13
|
-
thread_safe (~> 0.3, >= 0.3.4)
|
|
14
14
|
tzinfo (~> 1.1)
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
i18n (
|
|
15
|
+
appraisal (2.4.1)
|
|
16
|
+
bundler
|
|
17
|
+
rake
|
|
18
|
+
thor (>= 0.14.0)
|
|
19
|
+
concurrent-ruby (1.2.0)
|
|
20
|
+
diff-lcs (1.5.0)
|
|
21
|
+
i18n (1.12.0)
|
|
22
22
|
concurrent-ruby (~> 1.0)
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
shoulda-matchers (2.8.0)
|
|
42
|
-
activesupport (>= 3.0.0)
|
|
43
|
-
test-unit (1.2.3)
|
|
44
|
-
hoe (>= 1.5.1)
|
|
45
|
-
test_overrides (0.13.0)
|
|
23
|
+
minitest (5.10.3)
|
|
24
|
+
rake (13.0.6)
|
|
25
|
+
rspec (3.12.0)
|
|
26
|
+
rspec-core (~> 3.12.0)
|
|
27
|
+
rspec-expectations (~> 3.12.0)
|
|
28
|
+
rspec-mocks (~> 3.12.0)
|
|
29
|
+
rspec-core (3.12.1)
|
|
30
|
+
rspec-support (~> 3.12.0)
|
|
31
|
+
rspec-expectations (3.12.2)
|
|
32
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
33
|
+
rspec-support (~> 3.12.0)
|
|
34
|
+
rspec-mocks (3.12.3)
|
|
35
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
36
|
+
rspec-support (~> 3.12.0)
|
|
37
|
+
rspec-support (3.12.0)
|
|
38
|
+
rspec_junit_formatter (0.6.0)
|
|
39
|
+
rspec-core (>= 2, < 4, != 2.12.0)
|
|
40
|
+
thor (1.2.1)
|
|
46
41
|
thread_safe (0.3.6)
|
|
47
|
-
tzinfo (1.2.
|
|
42
|
+
tzinfo (1.2.11)
|
|
48
43
|
thread_safe (~> 0.1)
|
|
49
44
|
|
|
50
45
|
PLATFORMS
|
|
46
|
+
arm64-darwin-22
|
|
51
47
|
ruby
|
|
48
|
+
x86_64-linux
|
|
52
49
|
|
|
53
50
|
DEPENDENCIES
|
|
54
|
-
|
|
51
|
+
appraisal (~> 2.4)
|
|
55
52
|
invoca-utils!
|
|
56
|
-
minitest
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
rr (= 1.1.2)!
|
|
61
|
-
ruby-prof!
|
|
62
|
-
shoulda (= 3.5.0)!
|
|
63
|
-
test-unit (= 1.2.3)!
|
|
64
|
-
test_overrides (~> 0.13)!
|
|
65
|
-
tzinfo!
|
|
53
|
+
minitest (~> 5.10.0)
|
|
54
|
+
rake (~> 13.0)
|
|
55
|
+
rspec (~> 3.0)
|
|
56
|
+
rspec_junit_formatter (~> 0.4)
|
|
66
57
|
|
|
67
58
|
BUNDLED WITH
|
|
68
|
-
|
|
59
|
+
2.2.29
|
data/Rakefile
CHANGED
|
@@ -2,11 +2,14 @@
|
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
4
|
require "bundler/gem_tasks"
|
|
5
|
-
require 'rake
|
|
6
|
-
require 'rake_test_warning_false'
|
|
5
|
+
require 'rake'
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
desc "run rspec unit tests"
|
|
8
|
+
begin
|
|
9
|
+
require 'rspec/core/rake_task'
|
|
10
|
+
RSpec::Core::RakeTask.new(:rspec) do |rspec_task|
|
|
11
|
+
rspec_task.pattern = "spec/**{,/*/**}/*_spec.rb"
|
|
12
|
+
end
|
|
12
13
|
end
|
|
14
|
+
|
|
15
|
+
task default: :rspec
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# This file was generated by Appraisal
|
|
2
|
+
|
|
3
|
+
source "https://rubygems.org"
|
|
4
|
+
|
|
5
|
+
gem "appraisal", "~> 2.4"
|
|
6
|
+
gem "rake", "~> 13.0"
|
|
7
|
+
gem "rspec", "~> 3.0"
|
|
8
|
+
gem "rspec_junit_formatter", "~> 0.4"
|
|
9
|
+
gem "minitest", "~> 5.10.0"
|
|
10
|
+
gem "activesupport", "~> 5.2"
|
|
11
|
+
|
|
12
|
+
gemspec path: "../"
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# This file was generated by Appraisal
|
|
2
|
+
|
|
3
|
+
source "https://rubygems.org"
|
|
4
|
+
|
|
5
|
+
gem "appraisal", "~> 2.4"
|
|
6
|
+
gem "rake", "~> 13.0"
|
|
7
|
+
gem "rspec", "~> 3.0"
|
|
8
|
+
gem "rspec_junit_formatter", "~> 0.4"
|
|
9
|
+
gem "minitest", "~> 5.10.0"
|
|
10
|
+
gem "activesupport", "~> 6.0"
|
|
11
|
+
|
|
12
|
+
gemspec path: "../"
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# This file was generated by Appraisal
|
|
2
|
+
|
|
3
|
+
source "https://rubygems.org"
|
|
4
|
+
|
|
5
|
+
gem "appraisal", "~> 2.4"
|
|
6
|
+
gem "rake", "~> 13.0"
|
|
7
|
+
gem "rspec", "~> 3.0"
|
|
8
|
+
gem "rspec_junit_formatter", "~> 0.4"
|
|
9
|
+
gem "minitest", "~> 5.10.0"
|
|
10
|
+
gem "activesupport", "~> 7.0"
|
|
11
|
+
|
|
12
|
+
gemspec path: "../"
|
data/invoca-utils.gemspec
CHANGED
|
@@ -1,22 +1,34 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
lib = File.expand_path('lib', __dir__)
|
|
2
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
|
+
|
|
3
6
|
require 'invoca/utils/version'
|
|
4
7
|
|
|
5
8
|
Gem::Specification.new do |spec|
|
|
6
9
|
spec.name = "invoca-utils"
|
|
7
10
|
spec.version = Invoca::Utils::VERSION
|
|
11
|
+
spec.licenses = ["MIT"]
|
|
12
|
+
|
|
8
13
|
spec.authors = ["Invoca development"]
|
|
9
14
|
spec.email = ["development@invoca.com"]
|
|
15
|
+
|
|
10
16
|
spec.summary = "A public collection of helpers used in multiple projects"
|
|
11
|
-
spec.
|
|
12
|
-
spec.
|
|
17
|
+
spec.description = "A public collection of helpers used in multiple projects"
|
|
18
|
+
spec.homepage = "https://github.com/Invoca/invoca-utils"
|
|
13
19
|
|
|
14
|
-
spec.metadata =
|
|
15
|
-
'allowed_push_host' => 'https://rubygems.org'
|
|
16
|
-
}
|
|
20
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
|
17
21
|
|
|
18
22
|
spec.files = `git ls-files -z`.split("\x0")
|
|
19
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |
|
|
23
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |file| File.basename(file) }
|
|
20
24
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
21
25
|
spec.require_paths = ["lib"]
|
|
26
|
+
|
|
27
|
+
# this should match the minimum github pipeline targets
|
|
28
|
+
# which is currently set to 2.5
|
|
29
|
+
spec.required_ruby_version = ">= 2.5.0"
|
|
30
|
+
|
|
31
|
+
spec.add_dependency "activesupport", ">= 5.0"
|
|
32
|
+
|
|
33
|
+
# Specify this gem's development and test dependencies in Gemfile
|
|
22
34
|
end
|
data/lib/invoca/utils/version.rb
CHANGED
|
File without changes
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'active_support/all'
|
|
4
|
+
|
|
5
|
+
require 'invoca/utils'
|
|
6
|
+
require 'rspec_junit_formatter'
|
|
7
|
+
|
|
8
|
+
RSpec.configure do |config|
|
|
9
|
+
config.add_formatter(RspecJunitFormatter, 'spec/reports/rspec.xml')
|
|
10
|
+
|
|
11
|
+
config.mock_with :rspec do |mocks|
|
|
12
|
+
mocks.verify_partial_doubles = true
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
RSpec::Support::ObjectFormatter.default_instance.max_formatted_output_length = 2_000
|
|
16
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative '../../lib/invoca/utils/array.rb'
|
|
4
|
+
require_relative '../spec_helper'
|
|
5
|
+
|
|
6
|
+
describe Array do
|
|
7
|
+
context '* operator' do
|
|
8
|
+
it 'call the same method on each item in an array and return the results as an array' do
|
|
9
|
+
expect(['some', 'short', 'words'].*.length).to eq([4, 5, 5])
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it 'handle methods with arguments' do
|
|
13
|
+
expect(['some', 'short', 'words'].*.slice(1, 2)).to eq(['om', 'ho', 'or'])
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it 'not alter normal behavior (multiplication) when there is a right hand side to the expression' do
|
|
17
|
+
expect(['some', 'short', 'words'] * 2).to eq(['some', 'short', 'words', 'some', 'short', 'words'])
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'set'
|
|
4
|
+
require_relative '../../lib/invoca/utils/enumerable.rb'
|
|
5
|
+
require_relative '../spec_helper'
|
|
6
|
+
|
|
7
|
+
describe Enumerable do
|
|
8
|
+
|
|
9
|
+
context 'map_and_find' do
|
|
10
|
+
it 'return the mapped value of the first match' do
|
|
11
|
+
expect([1, 2, 3, 4].map_and_find { |v| 'FOUND 3' if v == 3 }).to eq('FOUND 3')
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it 'return the mapped value of the first match, even if there are multiple matches' do
|
|
15
|
+
expect([1, 2, 3, 4].map_and_find { |v| "FOUND #{v}" if v > 2 }).to eq('FOUND 3')
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it 'return the provided argument if the value is not found' do
|
|
19
|
+
expect([1, 2, 3, 4].map_and_find('NOT FOUND') { |v| "FOUND 6" if v == 6 }).to eq('NOT FOUND')
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it 'return nil if the value is not found and no argument is provided' do
|
|
23
|
+
expect([1, 2, 3, 4].map_and_find { |v| "FOUND 6" if v == 6 }).to be_nil
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
context 'map_with_index' do
|
|
28
|
+
it 'call the block with the value and index' do
|
|
29
|
+
expect([10, 20, 30, 40].map_with_index { |v, index| v + index }).to eq([10, 21, 32, 43])
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it 'assumulate into the provided enumerable' do
|
|
33
|
+
expect([10, 20, 30, 40].map_with_index([1]) { |v, index| v + index }).to eq([1, 10, 21, 32, 43])
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
context 'map_hash' do
|
|
38
|
+
it 'convert enumerables into a hash using the value for key and the map result as the hash value' do
|
|
39
|
+
expect([1, 2, 3].map_hash { |v| v + 10 }).to eq({ 1 => 11, 2 => 12, 3 => 13 })
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it 'includes nils returned from map' do
|
|
43
|
+
expect([1, 2, 3].map_hash { |v| v + 10 unless v == 2 }).to eq({ 1 => 11, 2 => nil, 3 => 13 })
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
context 'build_hash' do
|
|
48
|
+
it 'convert arrays of [key, value] to a hash of { key => value }' do
|
|
49
|
+
expect(['some', 'short', 'words'].build_hash { |s| [s, s.length] }).to eq({ 'some' => 4, 'short' => 5, 'words' => 5 })
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it 'ignore nils returned from map' do
|
|
53
|
+
expect(['some', 'short', 'words'].build_hash { |s| s == 'short' ? nil : [s, s.length] }).to eq({ 'some' => 4, 'words' => 5 })
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# these seem like erroneous behavior, but, they have been left as-is for backward compatibility with hobosupport::Enumerable::build_hash
|
|
57
|
+
|
|
58
|
+
it 'convert arrays of [single_value] to a hash of { single_value => single_value }' do
|
|
59
|
+
expect(['some', 'short', 'words'].build_hash { |s| s == 'short' ? [s] : [s, s.length] }).to eq({ 'some' => 4, 'short' => 'short', 'words' => 5 })
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
it 'convert arrays of [first, ..., last] to a hash of { first => last }' do
|
|
63
|
+
expect(['some', 'short', 'words'].build_hash { |s| s == 'short' ? [s, 'two', 'three'] : [s, s.length] }).to eq({ 'some' => 4, 'short' => 'three', 'words' => 5 })
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
it 'convert empty arrays to a hash of { nil => nil }' do
|
|
67
|
+
expect(['some', 'short', 'words'].build_hash { |s| s == 'short' ? [] : [s, s.length] }).to eq({ 'some' => 4, nil => nil, 'words' => 5 })
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
context '* operator' do
|
|
72
|
+
it 'call the same method on each item in an Set and return the results as an array' do
|
|
73
|
+
expect(Set['some', 'short', 'words'].*.length).to eq([4, 5, 5])
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
it 'call the same method on each item in an Hash and return the results as an array' do
|
|
77
|
+
expect({ key1: 'value1', key2: 'value2' }.*.join(':')).to eq(['key1:value1', 'key2:value2'])
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require_relative '../
|
|
3
|
+
require_relative '../spec_helper'
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
describe Invoca::Utils do
|
|
6
6
|
context "exceptions" do
|
|
7
7
|
context ".retry_on_exception" do
|
|
8
|
-
|
|
8
|
+
it "default retries: to 1" do
|
|
9
9
|
times = 0
|
|
10
10
|
tries = []
|
|
11
11
|
result = Invoca::Utils.retry_on_exception(ArgumentError) do |try|
|
|
12
12
|
tries << try
|
|
13
13
|
times += 1
|
|
14
14
|
end
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
expect(result).to eq(1)
|
|
16
|
+
expect(tries).to eq([0])
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
context "when never raising an exception" do
|
|
20
|
-
|
|
20
|
+
it "return result" do
|
|
21
21
|
times = 0
|
|
22
22
|
tries = []
|
|
23
23
|
result = Invoca::Utils.retry_on_exception(ArgumentError, retries: 2) do |try|
|
|
@@ -26,26 +26,26 @@ class ExceptionsTest < Minitest::Test
|
|
|
26
26
|
try == 0 and raise ArgumentError, '!!!'
|
|
27
27
|
times
|
|
28
28
|
end
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
expect(result).to eq(2)
|
|
30
|
+
expect(tries).to eq([0,1])
|
|
31
31
|
end
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
context "when always raising an exception" do
|
|
35
|
-
|
|
35
|
+
it "retry and finally raise" do
|
|
36
36
|
tries = []
|
|
37
|
-
|
|
37
|
+
expect do
|
|
38
38
|
Invoca::Utils.retry_on_exception(ArgumentError, retries: 1) do |try|
|
|
39
39
|
tries << try
|
|
40
40
|
raise ArgumentError, "!!! #{try + 1}"
|
|
41
41
|
end
|
|
42
|
-
end
|
|
43
|
-
|
|
42
|
+
end.to raise_exception(ArgumentError, /!!! 2/)
|
|
43
|
+
expect(tries).to eq([0,1])
|
|
44
44
|
end
|
|
45
45
|
end
|
|
46
46
|
|
|
47
47
|
context "when raising but then succeeding" do
|
|
48
|
-
|
|
48
|
+
it "retry and finally return result" do
|
|
49
49
|
times = 0
|
|
50
50
|
result = Invoca::Utils.retry_on_exception(ArgumentError, retries: 1) do
|
|
51
51
|
times += 1
|
|
@@ -55,12 +55,12 @@ class ExceptionsTest < Minitest::Test
|
|
|
55
55
|
times
|
|
56
56
|
end
|
|
57
57
|
end
|
|
58
|
-
|
|
58
|
+
expect(result).to eq(2)
|
|
59
59
|
end
|
|
60
60
|
end
|
|
61
61
|
|
|
62
62
|
context "when raising different exceptions (array notation) but then succeeding" do
|
|
63
|
-
|
|
63
|
+
it "retry and finally return result" do
|
|
64
64
|
times = 0
|
|
65
65
|
tries = []
|
|
66
66
|
result = Invoca::Utils.retry_on_exception([ArgumentError, RuntimeError], retries: 2) do |try|
|
|
@@ -75,8 +75,8 @@ class ExceptionsTest < Minitest::Test
|
|
|
75
75
|
times
|
|
76
76
|
end
|
|
77
77
|
end
|
|
78
|
-
|
|
79
|
-
|
|
78
|
+
expect(result).to eq(3)
|
|
79
|
+
expect(tries).to eq([0, 1, 2])
|
|
80
80
|
end
|
|
81
81
|
end
|
|
82
82
|
end
|