invoca-utils 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -1,38 +1,38 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative '../test_helper'
3
+ require_relative '../spec_helper'
4
4
 
5
- class StableSortTest < Minitest::Test
5
+ describe Enumerable do
6
6
  context "#stable_sort_by" do
7
- should "preserve the original order if all sort the same" do
7
+ it "preserve the original order if all sort the same" do
8
8
  list_to_sort = [:b, :d, :c, :a, :e, :f]
9
9
 
10
- assert_equal list_to_sort, list_to_sort.stable_sort_by { |c| 0 }
10
+ expect(list_to_sort.stable_sort_by { |c| 0 }).to eq(list_to_sort)
11
11
  end
12
12
 
13
- should "order by keys first and then position" do
13
+ it "order by keys first and then position" do
14
14
  list_to_sort = [:b, :d, :c, :a, :e, :f]
15
15
  order = [:a, :b, :c]
16
16
 
17
17
  result = list_to_sort.stable_sort_by { |c| order.index(c) || order.length }
18
- assert_equal [:a, :b, :c, :d, :e, :f], result
18
+ expect(result).to eq([:a, :b, :c, :d, :e, :f])
19
19
  end
20
20
 
21
- should "order by keys only if needed" do
21
+ it "order by keys only if needed" do
22
22
  list_to_sort = [:b, :d, :c, :a, :e, :f]
23
23
  result = list_to_sort.stable_sort_by { |c| c.to_s }
24
- assert_equal [:a, :b, :c, :d, :e, :f], result
24
+ expect(result).to eq([:a, :b, :c, :d, :e, :f])
25
25
  end
26
26
  end
27
27
 
28
28
  context "stable_sort" do
29
- should "preserve the original order if all sort the same" do
29
+ it "preserve the original order if all sort the same" do
30
30
  list_to_sort = [:b, :d, :c, :a, :e, :f]
31
31
 
32
- assert_equal list_to_sort, list_to_sort.stable_sort { |first, second| 0 }
32
+ expect(list_to_sort.stable_sort { |first, second| 0 }).to eq(list_to_sort)
33
33
  end
34
34
 
35
- should "order by keys first and then position" do
35
+ it "order by keys first and then position" do
36
36
  list_to_sort = [:b, :d, :c, :a, :e, :f]
37
37
  order = [:a, :b, :c]
38
38
 
@@ -42,13 +42,13 @@ class StableSortTest < Minitest::Test
42
42
  first_pos <=> second_pos
43
43
  end
44
44
 
45
- assert_equal [:a, :b, :c, :d, :e, :f], result
45
+ expect(result).to eq([:a, :b, :c, :d, :e, :f])
46
46
  end
47
47
 
48
- should "order by keys only if needed" do
48
+ it "order by keys only if needed" do
49
49
  list_to_sort = [:b, :d, :c, :a, :e, :f]
50
50
  result = list_to_sort.stable_sort{ |first, second| first.to_s <=> second.to_s }
51
- assert_equal [:a, :b, :c, :d, :e, :f], result
51
+ expect(result).to eq([:a, :b, :c, :d, :e, :f])
52
52
  end
53
53
  end
54
54
  end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../spec_helper'
4
+
5
+ describe Time do
6
+ context "beginning_of_hour" do
7
+ Time.zone = 'Pacific Time (US & Canada)'
8
+ [
9
+ Time.now,
10
+ Time.zone.now,
11
+ Time.local(2009),
12
+ Time.local(2009,3,4,5),
13
+ Time.local(2001,12,31,23,59),
14
+ Time.local(1970,1,1)
15
+ ].each_with_index do |time, index|
16
+ it "give back a time with no minutes, seconds, or msec: #{time} (#{index})" do
17
+ t = time.beginning_of_hour
18
+ expect(time.year).to eq(t.year)
19
+ expect(time.month).to eq(t.month)
20
+ expect(time.day).to eq(t.day)
21
+ expect(time.hour).to eq(t.hour)
22
+ expect(t.min).to eq(0)
23
+ expect(t.sec).to eq(0)
24
+ expect(t.usec).to eq(0)
25
+ end
26
+ end
27
+ end
28
+
29
+ context "end_of_day_whole_sec" do
30
+ it "return the end of day with whole_sec" do
31
+ t = Time.now
32
+ end_of_day = t.end_of_day
33
+ end_whole_sec = t.end_of_day_whole_sec
34
+ expect(end_whole_sec.usec).to eq(0.0)
35
+ expect(end_whole_sec.to_i).to eq(end_of_day.to_i)
36
+ expect(end_whole_sec.sec).to eq(end_of_day.sec)
37
+ end
38
+ end
39
+ end
@@ -1,49 +1,49 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative '../test_helper'
3
+ require_relative '../spec_helper'
4
4
  require_relative '../helpers/constant_overrides'
5
5
 
6
- class UtilsTest < Minitest::Test
6
+ describe Invoca::Utils do
7
7
  include ConstantOverrides
8
8
 
9
9
  context "global namespace issues" do
10
- setup do
10
+ before do
11
11
  setup_constant_overrides
12
12
  end
13
13
 
14
- teardown do
14
+ after do
15
15
  cleanup_constant_overrides
16
16
  end
17
17
 
18
- should "define Diff as Invoca::Utils::Diff" do
19
- assert_equal ::Diff, Invoca::Utils::Diff
18
+ it "define Diff as Invoca::Utils::Diff" do
19
+ expect(Invoca::Utils::Diff).to eq(::Diff)
20
20
  end
21
21
 
22
- should "define Diffable as Diffable" do
23
- assert_equal ::Diffable, Invoca::Utils::Diffable
22
+ it "define Diffable as Diffable" do
23
+ expect(Invoca::Utils::Diffable).to eq(::Diffable)
24
24
  end
25
25
 
26
26
  context "when Diff is defined in the global namespace" do
27
- setup do
27
+ before do
28
28
  @class = Class.new
29
29
  set_test_const("Diff", @class)
30
30
  load 'invoca/utils.rb'
31
31
  end
32
32
 
33
- should "not define Diff as Invoca::Utils::Diff" do
34
- assert_equal ::Diff, @class
33
+ it "not define Diff as Invoca::Utils::Diff" do
34
+ expect(@class).to eq(::Diff)
35
35
  end
36
36
  end
37
37
 
38
38
  context "when Diffable is defined in the global namespace" do
39
- setup do
39
+ before do
40
40
  @class = Class.new
41
41
  set_test_const("Diffable", @class)
42
42
  load 'invoca/utils.rb'
43
43
  end
44
44
 
45
- should "define Diffable as Invoca::Utils::Diffable" do
46
- assert_equal ::Diffable, @class
45
+ it "define Diffable as Invoca::Utils::Diffable" do
46
+ expect(@class).to eq(::Diffable)
47
47
  end
48
48
  end
49
49
  end
metadata CHANGED
@@ -1,33 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: invoca-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Invoca development
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-09 00:00:00.000000000 Z
12
- dependencies: []
13
- description:
11
+ date: 2023-02-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '5.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '5.0'
27
+ description: A public collection of helpers used in multiple projects
14
28
  email:
15
29
  - development@invoca.com
16
30
  executables: []
17
31
  extensions: []
18
32
  extra_rdoc_files: []
19
33
  files:
34
+ - ".github/workflows/pipeline.yml"
20
35
  - ".gitignore"
21
- - ".jenkins/Jenkinsfile"
22
- - ".jenkins/ruby_build_pod.yml"
36
+ - ".rspec"
23
37
  - ".rubocop.yml"
24
38
  - ".ruby-version"
39
+ - ".tool-versions"
40
+ - Appraisals
25
41
  - CHANGELOG.md
26
42
  - Gemfile
27
43
  - Gemfile.lock
28
44
  - LICENSE.txt
29
45
  - README.md
30
46
  - Rakefile
47
+ - gemfiles/activesupport_5.gemfile
48
+ - gemfiles/activesupport_5.gemfile.lock
49
+ - gemfiles/activesupport_6.gemfile
50
+ - gemfiles/activesupport_6.gemfile.lock
51
+ - gemfiles/activesupport_7.gemfile
52
+ - gemfiles/activesupport_7.gemfile.lock
31
53
  - invoca-utils.gemspec
32
54
  - lib/invoca/utils.rb
33
55
  - lib/invoca/utils/array.rb
@@ -45,21 +67,21 @@ files:
45
67
  - lib/invoca/utils/stable_sort.rb
46
68
  - lib/invoca/utils/time.rb
47
69
  - lib/invoca/utils/version.rb
48
- - test/helpers/constant_overrides.rb
49
- - test/test_helper.rb
50
- - test/unit/array_test.rb
51
- - test/unit/enumerable_test.rb
52
- - test/unit/exceptions_test.rb
53
- - test/unit/guaranteed_utf8_string_test.rb
54
- - test/unit/hash_test.rb
55
- - test/unit/hash_with_indifferent_access_test.rb
56
- - test/unit/map_compact_test.rb
57
- - test/unit/module_test.rb
58
- - test/unit/multi_sender_test.rb
59
- - test/unit/stable_sort_test.rb
60
- - test/unit/time_calculations_test.rb
61
- - test/unit/utils_test.rb
62
- homepage: ''
70
+ - spec/helpers/constant_overrides.rb
71
+ - spec/spec_helper.rb
72
+ - spec/unit/array_spec.rb
73
+ - spec/unit/enumerable_spec.rb
74
+ - spec/unit/exceptions_spec.rb
75
+ - spec/unit/guaranteed_utf8_string_spec.rb
76
+ - spec/unit/hash_spec.rb
77
+ - spec/unit/hash_with_indifferent_access_spec.rb
78
+ - spec/unit/map_compact_spec.rb
79
+ - spec/unit/module_spec.rb
80
+ - spec/unit/multi_sender_spec.rb
81
+ - spec/unit/stable_sort_spec.rb
82
+ - spec/unit/time_calculations_spec.rb
83
+ - spec/unit/utils_spec.rb
84
+ homepage: https://github.com/Invoca/invoca-utils
63
85
  licenses:
64
86
  - MIT
65
87
  metadata:
@@ -72,29 +94,29 @@ required_ruby_version: !ruby/object:Gem::Requirement
72
94
  requirements:
73
95
  - - ">="
74
96
  - !ruby/object:Gem::Version
75
- version: '0'
97
+ version: 2.5.0
76
98
  required_rubygems_version: !ruby/object:Gem::Requirement
77
99
  requirements:
78
100
  - - ">="
79
101
  - !ruby/object:Gem::Version
80
102
  version: '0'
81
103
  requirements: []
82
- rubygems_version: 3.0.3
104
+ rubygems_version: 3.1.6
83
105
  signing_key:
84
106
  specification_version: 4
85
107
  summary: A public collection of helpers used in multiple projects
86
108
  test_files:
87
- - test/helpers/constant_overrides.rb
88
- - test/test_helper.rb
89
- - test/unit/array_test.rb
90
- - test/unit/enumerable_test.rb
91
- - test/unit/exceptions_test.rb
92
- - test/unit/guaranteed_utf8_string_test.rb
93
- - test/unit/hash_test.rb
94
- - test/unit/hash_with_indifferent_access_test.rb
95
- - test/unit/map_compact_test.rb
96
- - test/unit/module_test.rb
97
- - test/unit/multi_sender_test.rb
98
- - test/unit/stable_sort_test.rb
99
- - test/unit/time_calculations_test.rb
100
- - test/unit/utils_test.rb
109
+ - spec/helpers/constant_overrides.rb
110
+ - spec/spec_helper.rb
111
+ - spec/unit/array_spec.rb
112
+ - spec/unit/enumerable_spec.rb
113
+ - spec/unit/exceptions_spec.rb
114
+ - spec/unit/guaranteed_utf8_string_spec.rb
115
+ - spec/unit/hash_spec.rb
116
+ - spec/unit/hash_with_indifferent_access_spec.rb
117
+ - spec/unit/map_compact_spec.rb
118
+ - spec/unit/module_spec.rb
119
+ - spec/unit/multi_sender_spec.rb
120
+ - spec/unit/stable_sort_spec.rb
121
+ - spec/unit/time_calculations_spec.rb
122
+ - spec/unit/utils_spec.rb
data/.jenkins/Jenkinsfile DELETED
@@ -1,50 +0,0 @@
1
- #!/usr/bin/groovy
2
- @Library('jenkins-pipeline@v0.4.5')
3
- import com.invoca.docker.*;
4
- pipeline {
5
- agent {
6
- kubernetes {
7
- defaultContainer "ruby"
8
- yamlFile ".jenkins/ruby_build_pod.yml"
9
- }
10
- }
11
-
12
- environment {
13
- GITHUB_TOKEN = credentials('github_token')
14
- BUNDLE_GEM__FURY__IO = credentials('gemfury_deploy_token')
15
- }
16
-
17
- stages {
18
- stage('Setup') {
19
- steps {
20
- script {
21
- sh 'bundle install'
22
- }
23
- }
24
- }
25
- stage('Unit Test') {
26
- steps {
27
- script {
28
- sh 'bundle exec rake'
29
- }
30
- }
31
- post {
32
- always { junit '*/reports/*.xml' }
33
- success { updateGitHubStatus('clean-build', 'success', 'Unit tests.') }
34
- failure { updateGitHubStatus('clean-build', 'failure', 'Unit tests.') }
35
- }
36
- }
37
- }
38
- }
39
-
40
- void updateGitHubStatus(String context, String status, String description) {
41
- gitHubStatus([
42
- repoSlug: 'Invoca/invoca-utils',
43
- sha: env.GIT_COMMIT,
44
- description: description,
45
- context: context,
46
- targetURL: env.BUILD_URL,
47
- token: env.GITHUB_TOKEN,
48
- status: status
49
- ])
50
- }
@@ -1,19 +0,0 @@
1
- ---
2
- apiVersion: v1
3
- kind: Pod
4
- metadata:
5
- labels:
6
- jenkins/invoca-utils: 'true'
7
- namespace: jenkins
8
- name: invoca-utils
9
- spec:
10
- containers:
11
- - name: ruby
12
- image: ruby:2.6.5
13
- tty: true
14
- resources:
15
- requests:
16
- memory: "100Mi"
17
- command:
18
- - cat
19
-
data/test/test_helper.rb DELETED
@@ -1,14 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "minitest/autorun"
4
- require 'rr'
5
- require 'shoulda'
6
- require 'pry'
7
- require 'active_support/all'
8
-
9
- require 'invoca/utils'
10
- require "minitest/reporters"
11
- Minitest::Reporters.use! [
12
- Minitest::Reporters::DefaultReporter.new,
13
- Minitest::Reporters::JUnitReporter.new
14
- ]
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../../lib/invoca/utils/array.rb'
4
- require_relative '../test_helper'
5
-
6
- class ArrayTest < Minitest::Test
7
- context '* operator' do
8
- should 'call the same method on each item in an array and return the results as an array' do
9
- assert_equal([4, 5, 5], ['some', 'short', 'words'].*.length)
10
- end
11
-
12
- should 'handle methods with arguments' do
13
- assert_equal(['om', 'ho', 'or'], ['some', 'short', 'words'].*.slice(1, 2))
14
- end
15
-
16
- should 'not alter normal behavior (multiplication) when there is a right hand side to the expression' do
17
- assert_equal(['some', 'short', 'words', 'some', 'short', 'words'], ['some', 'short', 'words'] * 2)
18
- end
19
- end
20
- end
@@ -1,80 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'set'
4
- require_relative '../../lib/invoca/utils/enumerable.rb'
5
- require_relative '../test_helper'
6
-
7
- class EnumerableTest < Minitest::Test
8
-
9
- context 'map_and_find' do
10
- should 'return the mapped value of the first match' do
11
- assert_equal('FOUND 3', [1, 2, 3, 4].map_and_find { |v| 'FOUND 3' if v == 3 })
12
- end
13
-
14
- should 'return the mapped value of the first match, even if there are multiple matches' do
15
- assert_equal('FOUND 3', [1, 2, 3, 4].map_and_find { |v| "FOUND #{v}" if v > 2 })
16
- end
17
-
18
- should 'return the provided argument if the value is not found' do
19
- assert_equal('NOT FOUND', [1, 2, 3, 4].map_and_find('NOT FOUND') { |v| "FOUND 6" if v == 6 })
20
- end
21
-
22
- should 'return nil if the value is not found and no argument is provided' do
23
- assert_nil([1, 2, 3, 4].map_and_find { |v| "FOUND 6" if v == 6 })
24
- end
25
- end
26
-
27
- context 'map_with_index' do
28
- should 'call the block with the value and index' do
29
- assert_equal([10, 21, 32, 43], [10, 20, 30, 40].map_with_index { |v, index| v + index })
30
- end
31
-
32
- should 'assumulate into the provided enumerable' do
33
- assert_equal([1, 10, 21, 32, 43], [10, 20, 30, 40].map_with_index([1]) { |v, index| v + index })
34
- end
35
- end
36
-
37
- context 'map_hash' do
38
- should 'convert enumerables into a hash using the value for key and the map result as the hash value' do
39
- assert_equal({ 1 => 11, 2 => 12, 3 => 13 }, [1, 2, 3].map_hash { |v| v + 10 })
40
- end
41
-
42
- should 'includes nils returned from map' do
43
- assert_equal({ 1 => 11, 2 => nil, 3 => 13 }, [1, 2, 3].map_hash { |v| v + 10 unless v == 2 })
44
- end
45
- end
46
-
47
- context 'build_hash' do
48
- should 'convert arrays of [key, value] to a hash of { key => value }' do
49
- assert_equal({ 'some' => 4, 'short' => 5, 'words' => 5 }, ['some', 'short', 'words'].build_hash { |s| [s, s.length] })
50
- end
51
-
52
- should 'ignore nils returned from map' do
53
- assert_equal({ 'some' => 4, 'words' => 5 }, ['some', 'short', 'words'].build_hash { |s| s == 'short' ? nil : [s, s.length] })
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
- should 'convert arrays of [single_value] to a hash of { single_value => single_value }' do
59
- assert_equal({ 'some' => 4, 'short' => 'short', 'words' => 5 }, ['some', 'short', 'words'].build_hash { |s| s == 'short' ? [s] : [s, s.length] })
60
- end
61
-
62
- should 'convert arrays of [first, ..., last] to a hash of { first => last }' do
63
- assert_equal({ 'some' => 4, 'short' => 'three', 'words' => 5 }, ['some', 'short', 'words'].build_hash { |s| s == 'short' ? [s, 'two', 'three'] : [s, s.length] })
64
- end
65
-
66
- should 'convert empty arrays to a hash of { nil => nil }' do
67
- assert_equal({ 'some' => 4, nil => nil, 'words' => 5 }, ['some', 'short', 'words'].build_hash { |s| s == 'short' ? [] : [s, s.length] })
68
- end
69
- end
70
-
71
- context '* operator' do
72
- should 'call the same method on each item in an Set and return the results as an array' do
73
- assert_equal([4, 5, 5], Set['some', 'short', 'words'].*.length)
74
- end
75
-
76
- should 'call the same method on each item in an Hash and return the results as an array' do
77
- assert_equal(['key1:value1', 'key2:value2'], { key1: 'value1', key2: 'value2' }.*.join(':'))
78
- end
79
- end
80
- end