invoca-utils 0.4.0 → 0.5.0

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.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/pipeline.yml +20 -0
  3. data/.gitignore +1 -3
  4. data/.rspec +3 -0
  5. data/.ruby-version +1 -1
  6. data/.tool-versions +1 -0
  7. data/Appraisals +13 -0
  8. data/CHANGELOG.md +10 -0
  9. data/Gemfile +9 -16
  10. data/Gemfile.lock +39 -48
  11. data/Rakefile +9 -6
  12. data/gemfiles/activesupport_5.gemfile +12 -0
  13. data/gemfiles/activesupport_5.gemfile.lock +58 -0
  14. data/gemfiles/activesupport_6.gemfile +12 -0
  15. data/gemfiles/activesupport_6.gemfile.lock +59 -0
  16. data/gemfiles/activesupport_7.gemfile +12 -0
  17. data/gemfiles/activesupport_7.gemfile.lock +57 -0
  18. data/invoca-utils.gemspec +18 -6
  19. data/lib/invoca/utils/exceptions.rb +5 -3
  20. data/lib/invoca/utils/version.rb +1 -1
  21. data/{test → spec}/helpers/constant_overrides.rb +0 -0
  22. data/spec/spec_helper.rb +16 -0
  23. data/spec/unit/array_spec.rb +20 -0
  24. data/spec/unit/enumerable_spec.rb +80 -0
  25. data/{test/unit/exceptions_test.rb → spec/unit/exceptions_spec.rb} +17 -17
  26. data/spec/unit/guaranteed_utf8_string_spec.rb +260 -0
  27. data/spec/unit/hash_spec.rb +81 -0
  28. data/spec/unit/hash_with_indifferent_access_spec.rb +100 -0
  29. data/spec/unit/map_compact_spec.rb +25 -0
  30. data/{test/unit/module_test.rb → spec/unit/module_spec.rb} +4 -4
  31. data/spec/unit/multi_sender_spec.rb +54 -0
  32. data/{test/unit/stable_sort_test.rb → spec/unit/stable_sort_spec.rb} +14 -14
  33. data/spec/unit/time_calculations_spec.rb +39 -0
  34. data/{test/unit/utils_test.rb → spec/unit/utils_spec.rb} +14 -14
  35. metadata +59 -37
  36. data/.jenkins/Jenkinsfile +0 -50
  37. data/.jenkins/ruby_build_pod.yml +0 -19
  38. data/test/test_helper.rb +0 -14
  39. data/test/unit/array_test.rb +0 -20
  40. data/test/unit/enumerable_test.rb +0 -80
  41. data/test/unit/guaranteed_utf8_string_test.rb +0 -263
  42. data/test/unit/hash_test.rb +0 -81
  43. data/test/unit/hash_with_indifferent_access_test.rb +0 -100
  44. data/test/unit/map_compact_test.rb +0 -25
  45. data/test/unit/multi_sender_test.rb +0 -56
  46. data/test/unit/time_calculations_test.rb +0 -39
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 54dcad50905bf9c0d48905b88e563c6418ea4bc852e4f85d4cd892e2b2031096
4
- data.tar.gz: 592dde85e812312a5fb5ff67d34da1d5a0127f0c2c2f5f60538baab3c63d32ff
3
+ metadata.gz: 99f6039ed702e76afaf3bd88fc084f158fcb7bbbf16cf9817a692b4adef8b5bc
4
+ data.tar.gz: 71c80ef09bfa85f98b889975e6c721f3f643d552f25cce6bb3a479216fd6b82a
5
5
  SHA512:
6
- metadata.gz: 6fac4beb8eef9b3a4ebc3615cb7711c9134e401e34ba26a2d0012b89c7962ca19440b2ceb2e0fafd5aaafcd4576717d10fddd276c4583858ffc725904194464a
7
- data.tar.gz: c312101bd66d62f9c145610be64a8e75ec931387d4dc33f581885dc5707ff7565e474fd618ddbf569ed9091a591d0f2e0a164b7899ffe311b889c62fbc5a7d37
6
+ metadata.gz: 04d05c8ea6ef6c3814b2f013d991328628af1907d4f1d703981896af36efadfcbf4344b63bcaba4eee1028951243db9cfc53bca352cd21c944ab58aed5bd3135
7
+ data.tar.gz: e5fa5ddcb14d16b44dab87bcff1f952b0588415de5ebd7e85bc6190c33bbcb82cc9a3834186441a32b2f1015872abfb789160b19d8a9d9f1910ba7eb85cdc64e
@@ -0,0 +1,20 @@
1
+ ---
2
+ name: Pipeline
3
+ on: [push]
4
+ jobs:
5
+ tests:
6
+ name: Unit Tests
7
+ runs-on: ubuntu-latest
8
+ strategy:
9
+ fail-fast: false
10
+ matrix:
11
+ ruby: [2.5, 2.6, 2.7, '3.0', 3.1]
12
+ steps:
13
+ - uses: actions/checkout@v2
14
+ - uses: ruby/setup-ruby@v1
15
+ with:
16
+ ruby-version: ${{ matrix.ruby }}
17
+ bundler: 2.2.29
18
+ bundler-cache: true
19
+ - name: Unit Tests
20
+ run: bundle exec rspec
data/.gitignore CHANGED
@@ -12,9 +12,7 @@ lib/bundler/man
12
12
  pkg
13
13
  pkg/
14
14
  rdoc
15
- test/reports
16
- test/tmp
17
- test/version_tmp
15
+ spec/reports
18
16
 
19
17
  tmp
20
18
  *.bundle
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --require spec_helper
2
+ --format progress
3
+ --color
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.6.5
1
+ 2.7.5
data/.tool-versions ADDED
@@ -0,0 +1 @@
1
+ ruby 2.7.5
data/Appraisals ADDED
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ appraise 'activesupport-5' do
4
+ gem 'activesupport', '~> 5.2'
5
+ end
6
+
7
+ appraise 'activesupport-6' do
8
+ gem 'activesupport', '~> 6.0'
9
+ end
10
+
11
+ appraise 'activesupport-7' do
12
+ gem 'activesupport', '~> 7.0'
13
+ end
data/CHANGELOG.md CHANGED
@@ -4,6 +4,14 @@ Inspired by [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
4
4
 
5
5
  Note: This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [0.5.0] - 2023-02-10
8
+ ### Added
9
+ - Relaxed version requirement for ActiveSupport
10
+
11
+ ## [0.4.1] - 2020-06-17
12
+ ### Fixed
13
+ - Support Ruby < 2.5 by adding `begin`/`end` around `rescue` in `retry_on_exception`.
14
+
7
15
  ## [0.4.0] - 2020-06-09
8
16
  ### Added
9
17
  - Added `Invoca::Utils.retry_on_exception`.
@@ -23,6 +31,8 @@ Note: This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0
23
31
  - Enumerable::build_hash method ported from HoboSupport
24
32
  - Enumerable::* operator ported from HoboSupport
25
33
 
34
+ [0.5.0]: https://github.com/Invoca/invoca-utils/compare/v0.4.1...v0.5.0
35
+ [0.4.1]: https://github.com/Invoca/invoca-utils/compare/v0.4.0...v0.4.1
26
36
  [0.4.0]: https://github.com/Invoca/invoca-utils/compare/v0.3.0...v0.4.0
27
37
  [0.3.0]: https://github.com/Invoca/invoca-utils/compare/v0.2.0...v0.3.0
28
38
  [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
- source 'https://rubygems.org' do
8
- gem 'activesupport', '~> 4.2'
9
- gem 'minitest'
10
- gem 'minitest-reporters'
11
- gem 'pry'
12
- gem 'rake'
13
- gem 'rr', '=1.1.2'
14
- gem 'ruby-prof'
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.0)
4
+ invoca-utils (0.5.0)
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 (4.2.11.3)
11
- i18n (~> 0.7)
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
- ansi (1.5.0)
16
- builder (3.2.4)
17
- coderay (1.1.3)
18
- concurrent-ruby (1.1.6)
19
- hoe (3.22.1)
20
- rake (>= 0.8, < 15.0)
21
- i18n (0.9.5)
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
- method_source (1.0.0)
24
- minitest (5.14.1)
25
- minitest-reporters (1.4.2)
26
- ansi
27
- builder
28
- minitest (>= 5.0)
29
- ruby-progressbar
30
- pry (0.13.1)
31
- coderay (~> 1.1)
32
- method_source (~> 1.0)
33
- rake (13.0.1)
34
- rr (1.1.2)
35
- ruby-prof (1.4.1)
36
- ruby-progressbar (1.10.1)
37
- shoulda (3.5.0)
38
- shoulda-context (~> 1.0, >= 1.0.1)
39
- shoulda-matchers (>= 1.4.1, < 3.0)
40
- shoulda-context (1.2.2)
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.7)
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
- activesupport (~> 4.2)!
51
+ appraisal (~> 2.4)
55
52
  invoca-utils!
56
- minitest!
57
- minitest-reporters!
58
- pry!
59
- rake!
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
- 1.17.3
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/testtask'
6
- require 'rake_test_warning_false'
5
+ require 'rake'
7
6
 
8
- task default: :test
9
-
10
- Rake::TestTask.new do |t|
11
- t.pattern = "test/**/*_test.rb"
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,58 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ invoca-utils (0.5.0)
5
+ activesupport (>= 5.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activesupport (5.2.8.1)
11
+ concurrent-ruby (~> 1.0, >= 1.0.2)
12
+ i18n (>= 0.7, < 2)
13
+ minitest (~> 5.1)
14
+ tzinfo (~> 1.1)
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
+ concurrent-ruby (~> 1.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)
41
+ thread_safe (0.3.6)
42
+ tzinfo (1.2.11)
43
+ thread_safe (~> 0.1)
44
+
45
+ PLATFORMS
46
+ arm64-darwin-22
47
+
48
+ DEPENDENCIES
49
+ activesupport (~> 5.2)
50
+ appraisal (~> 2.4)
51
+ invoca-utils!
52
+ minitest (~> 5.10.0)
53
+ rake (~> 13.0)
54
+ rspec (~> 3.0)
55
+ rspec_junit_formatter (~> 0.4)
56
+
57
+ BUNDLED WITH
58
+ 2.3.17
@@ -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,59 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ invoca-utils (0.5.0)
5
+ activesupport (>= 5.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activesupport (6.1.7.2)
11
+ concurrent-ruby (~> 1.0, >= 1.0.2)
12
+ i18n (>= 1.6, < 2)
13
+ minitest (>= 5.1)
14
+ tzinfo (~> 2.0)
15
+ zeitwerk (~> 2.3)
16
+ appraisal (2.4.1)
17
+ bundler
18
+ rake
19
+ thor (>= 0.14.0)
20
+ concurrent-ruby (1.2.0)
21
+ diff-lcs (1.5.0)
22
+ i18n (1.12.0)
23
+ concurrent-ruby (~> 1.0)
24
+ minitest (5.10.3)
25
+ rake (13.0.6)
26
+ rspec (3.12.0)
27
+ rspec-core (~> 3.12.0)
28
+ rspec-expectations (~> 3.12.0)
29
+ rspec-mocks (~> 3.12.0)
30
+ rspec-core (3.12.1)
31
+ rspec-support (~> 3.12.0)
32
+ rspec-expectations (3.12.2)
33
+ diff-lcs (>= 1.2.0, < 2.0)
34
+ rspec-support (~> 3.12.0)
35
+ rspec-mocks (3.12.3)
36
+ diff-lcs (>= 1.2.0, < 2.0)
37
+ rspec-support (~> 3.12.0)
38
+ rspec-support (3.12.0)
39
+ rspec_junit_formatter (0.6.0)
40
+ rspec-core (>= 2, < 4, != 2.12.0)
41
+ thor (1.2.1)
42
+ tzinfo (2.0.6)
43
+ concurrent-ruby (~> 1.0)
44
+ zeitwerk (2.6.6)
45
+
46
+ PLATFORMS
47
+ arm64-darwin-22
48
+
49
+ DEPENDENCIES
50
+ activesupport (~> 6.0)
51
+ appraisal (~> 2.4)
52
+ invoca-utils!
53
+ minitest (~> 5.10.0)
54
+ rake (~> 13.0)
55
+ rspec (~> 3.0)
56
+ rspec_junit_formatter (~> 0.4)
57
+
58
+ BUNDLED WITH
59
+ 2.3.17
@@ -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: "../"
@@ -0,0 +1,57 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ invoca-utils (0.5.0)
5
+ activesupport (>= 5.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activesupport (7.0.4.2)
11
+ concurrent-ruby (~> 1.0, >= 1.0.2)
12
+ i18n (>= 1.6, < 2)
13
+ minitest (>= 5.1)
14
+ tzinfo (~> 2.0)
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
+ concurrent-ruby (~> 1.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)
41
+ tzinfo (2.0.6)
42
+ concurrent-ruby (~> 1.0)
43
+
44
+ PLATFORMS
45
+ arm64-darwin-22
46
+
47
+ DEPENDENCIES
48
+ activesupport (~> 7.0)
49
+ appraisal (~> 2.4)
50
+ invoca-utils!
51
+ minitest (~> 5.10.0)
52
+ rake (~> 13.0)
53
+ rspec (~> 3.0)
54
+ rspec_junit_formatter (~> 0.4)
55
+
56
+ BUNDLED WITH
57
+ 2.3.17
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.homepage = ""
12
- spec.license = "MIT"
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/}) { |f| File.basename(f) }
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
@@ -13,9 +13,11 @@ module Invoca
13
13
  # @return the value from yield
14
14
  def retry_on_exception(exception_classes, retries: 1, before_retry: nil)
15
15
  retries.times do |attempt_number|
16
- return yield(attempt_number)
17
- rescue *Array(exception_classes) => ex
18
- before_retry&.call(ex)
16
+ begin
17
+ return yield(attempt_number)
18
+ rescue *Array(exception_classes) => ex
19
+ before_retry&.call(ex)
20
+ end
19
21
  end
20
22
 
21
23
  yield(retries) # no rescue for this last try, so any exceptions will raise out
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Invoca
4
4
  module Utils
5
- VERSION = "0.4.0"
5
+ VERSION = "0.5.0"
6
6
  end
7
7
  end
File without changes
@@ -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