invoca-utils 0.4.1 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/pipeline.yml +40 -0
  3. data/.gitignore +28 -17
  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 +12 -1
  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_6.gemfile +12 -0
  14. data/gemfiles/activesupport_7.gemfile +12 -0
  15. data/invoca-utils.gemspec +18 -6
  16. data/lib/invoca/utils/version.rb +1 -1
  17. data/{test → spec}/helpers/constant_overrides.rb +0 -0
  18. data/spec/spec_helper.rb +16 -0
  19. data/spec/unit/array_spec.rb +20 -0
  20. data/spec/unit/enumerable_spec.rb +80 -0
  21. data/{test/unit/exceptions_test.rb → spec/unit/exceptions_spec.rb} +17 -17
  22. data/spec/unit/guaranteed_utf8_string_spec.rb +260 -0
  23. data/spec/unit/hash_spec.rb +81 -0
  24. data/spec/unit/hash_with_indifferent_access_spec.rb +100 -0
  25. data/spec/unit/map_compact_spec.rb +25 -0
  26. data/{test/unit/module_test.rb → spec/unit/module_spec.rb} +4 -4
  27. data/spec/unit/multi_sender_spec.rb +54 -0
  28. data/{test/unit/stable_sort_test.rb → spec/unit/stable_sort_spec.rb} +14 -14
  29. data/spec/unit/time_calculations_spec.rb +39 -0
  30. data/{test/unit/utils_test.rb → spec/unit/utils_spec.rb} +14 -14
  31. metadata +56 -37
  32. data/.jenkins/Jenkinsfile +0 -50
  33. data/.jenkins/ruby_build_pod.yml +0 -19
  34. data/test/test_helper.rb +0 -14
  35. data/test/unit/array_test.rb +0 -20
  36. data/test/unit/enumerable_test.rb +0 -80
  37. data/test/unit/guaranteed_utf8_string_test.rb +0 -263
  38. data/test/unit/hash_test.rb +0 -81
  39. data/test/unit/hash_with_indifferent_access_test.rb +0 -100
  40. data/test/unit/map_compact_test.rb +0 -25
  41. data/test/unit/multi_sender_test.rb +0 -56
  42. data/test/unit/time_calculations_test.rb +0 -39
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bc2c9db5fc433f7e4f0abfc7ba11ca6a41065e5a4e9a233bb6f38fa8d310e0d0
4
- data.tar.gz: 426e3b56dcb95d79b964d613198b2c483050da092999a4ccd4e29348231b0588
3
+ metadata.gz: c8684fc70ce068552001b1cd99cf11a8f60882e23d46b9a56f94276e5c5b6403
4
+ data.tar.gz: c429285201930b90be6ea32d043f9625fcd22b493b6c4871ea912d55800958d2
5
5
  SHA512:
6
- metadata.gz: b0e762c4b3a2e044abc0a340dc741a9258b2a3afbca3caf575f5f160067fef863ce10d40b03bc374275d0953c9984fd0bf2253df8d5cdcc0e43774bbf42948fe
7
- data.tar.gz: fc973c0be3d37b5f8e38f2e12d9ea45a87539c78ff8afe7b7f8adf8351d623f847af68a1d9df96bbc39938894dfb6e2bf2fe4f36ef182278f80b3511381cdedf
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
- *.gem
3
- *.rbc
4
- .bundle
5
- .config
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
- tmp
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
- *.so
26
+ *.gem
22
27
  *.o
23
- *.a
28
+ *.rbc
29
+ *.so
30
+ .bundle
31
+ .config
32
+ InstalledFiles
33
+ checksums
34
+ lib/bundler/man
24
35
  mkmf.log
25
- .idea/
26
- .rubocop-http*
36
+ pkg
37
+ tmp
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
@@ -2,7 +2,15 @@
2
2
 
3
3
  Inspired by [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
4
4
 
5
- Note: This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
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
- 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.1)
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 (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,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.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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Invoca
4
4
  module Utils
5
- VERSION = "0.4.1"
5
+ VERSION = "0.5.1"
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
@@ -1,23 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative '../test_helper'
3
+ require_relative '../spec_helper'
4
4
 
5
- class ExceptionsTest < Minitest::Test
5
+ describe Invoca::Utils do
6
6
  context "exceptions" do
7
7
  context ".retry_on_exception" do
8
- should "default retries: to 1" do
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
- assert_equal 1, result
16
- assert_equal [0], tries
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
- should "return result" do
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
- assert_equal 2, result
30
- assert_equal [0, 1], tries
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
- should "retry and finally raise" do
35
+ it "retry and finally raise" do
36
36
  tries = []
37
- assert_raises(ArgumentError, /!!! 2/) do
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
- assert_equal [0, 1], tries
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
- should "retry and finally return result" do
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
- assert_equal 2, result
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
- should "retry and finally return result" do
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
- assert_equal 3, result
79
- assert_equal [0, 1, 2], tries
78
+ expect(result).to eq(3)
79
+ expect(tries).to eq([0, 1, 2])
80
80
  end
81
81
  end
82
82
  end