darthjee-core_ext 1.7.4 → 3.0.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 (101) hide show
  1. checksums.yaml +5 -5
  2. data/.circleci/config.yml +63 -9
  3. data/.gitignore +2 -0
  4. data/.reek.yml +3 -0
  5. data/.rubocop.yml +18 -1
  6. data/.rubocop_todo.yml +15 -8
  7. data/ARRAY_README.md +72 -15
  8. data/CLASS_README.md +154 -0
  9. data/DATE_README.md +19 -9
  10. data/Dockerfile +18 -5
  11. data/ENUMERABLE_README.md +154 -4
  12. data/Gemfile +13 -0
  13. data/HASH_README.md +276 -135
  14. data/MATH_README.md +14 -10
  15. data/Makefile +7 -0
  16. data/OBJECT_README.md +18 -35
  17. data/README.md +12 -4
  18. data/Rakefile +1 -0
  19. data/SYMBOL_README.md +13 -18
  20. data/config/check_specs.yml +20 -0
  21. data/config/rubycritc.rb +12 -0
  22. data/config/yardstick.yml +45 -3
  23. data/core_ext.gemspec +10 -18
  24. data/docker-compose.yml +24 -7
  25. data/lib/darthjee/core_ext/array/hash_builder.rb +22 -5
  26. data/lib/darthjee/core_ext/array.rb +22 -14
  27. data/lib/darthjee/core_ext/class.rb +29 -10
  28. data/lib/darthjee/core_ext/date.rb +1 -0
  29. data/lib/darthjee/core_ext/enumerable.rb +67 -29
  30. data/lib/darthjee/core_ext/hash/cameliazable.rb +52 -21
  31. data/lib/darthjee/core_ext/hash/chain_fetcher.rb +18 -1
  32. data/lib/darthjee/core_ext/hash/changeable.rb +88 -0
  33. data/lib/darthjee/core_ext/hash/deep_hash_constructor/setter.rb +112 -0
  34. data/lib/darthjee/core_ext/hash/deep_hash_constructor.rb +127 -62
  35. data/lib/darthjee/core_ext/hash/key_changeable.rb +138 -66
  36. data/lib/darthjee/core_ext/hash/key_changer.rb +146 -45
  37. data/lib/darthjee/core_ext/hash/keys_sorter.rb +43 -6
  38. data/lib/darthjee/core_ext/hash/squasher.rb +131 -18
  39. data/lib/darthjee/core_ext/hash/transformable.rb +133 -41
  40. data/lib/darthjee/core_ext/hash/transposeable.rb +37 -8
  41. data/lib/darthjee/core_ext/hash/value_changer.rb +76 -36
  42. data/lib/darthjee/core_ext/hash.rb +6 -4
  43. data/lib/darthjee/core_ext/math.rb +37 -6
  44. data/lib/darthjee/core_ext/numeric.rb +13 -2
  45. data/lib/darthjee/core_ext/object.rb +27 -0
  46. data/lib/darthjee/core_ext/symbol.rb +22 -2
  47. data/lib/darthjee/core_ext/version.rb +1 -1
  48. data/scripts/check_readme.sh +6 -0
  49. data/scripts/rubycritic.sh +10 -0
  50. data/spec/integration/readme/array_spec.rb +96 -0
  51. data/spec/integration/readme/class_spec.rb +123 -0
  52. data/spec/integration/readme/date_spec.rb +20 -0
  53. data/spec/integration/readme/enumerable_spec.rb +87 -0
  54. data/spec/integration/readme/hash_spec.rb +400 -0
  55. data/spec/integration/readme/math_spec.rb +31 -0
  56. data/spec/integration/readme/object_spec.rb +49 -0
  57. data/spec/integration/readme/symbol_spec.rb +29 -0
  58. data/spec/integration/yard/darthjee/core_ext/array_spec.rb +1 -1
  59. data/spec/integration/yard/darthjee/core_ext/class/default_value_spec.rb +10 -8
  60. data/spec/integration/yard/darthjee/core_ext/enumerable_spec.rb +24 -4
  61. data/spec/integration/yard/darthjee/core_ext/hash/cameliazable_spec.rb +11 -0
  62. data/spec/integration/yard/darthjee/core_ext/hash/changeable_spec.rb +68 -0
  63. data/spec/integration/yard/darthjee/core_ext/hash/deep_hash_constructor/setter_spec.rb +34 -0
  64. data/spec/integration/yard/darthjee/core_ext/hash/deep_hash_constructor_spec.rb +65 -0
  65. data/spec/integration/yard/darthjee/core_ext/hash/key_changeable_spec.rb +8 -0
  66. data/spec/integration/yard/darthjee/core_ext/hash/key_changer_spec.rb +59 -0
  67. data/spec/integration/yard/darthjee/core_ext/hash/keys_sorter_spec.rb +25 -0
  68. data/spec/integration/yard/darthjee/core_ext/hash/squasher_spec.rb +60 -0
  69. data/spec/integration/yard/darthjee/core_ext/hash/transformable_spec.rb +67 -37
  70. data/spec/integration/yard/darthjee/core_ext/hash/transposeable_spec.rb +35 -0
  71. data/spec/integration/yard/darthjee/core_ext/hash/value_changer_spec.rb +1 -1
  72. data/spec/integration/yard/darthjee/core_ext/hash_spec.rb +13 -2
  73. data/spec/integration/yard/darthjee/core_ext/math_spec.rb +28 -0
  74. data/spec/integration/yard/darthjee/core_ext/numeric_spec.rb +11 -0
  75. data/spec/integration/yard/darthjee/core_ext/object_spec.rb +47 -0
  76. data/spec/integration/yard/darthjee/core_ext/symbol_spec.rb +17 -0
  77. data/spec/lib/array_spec.rb +2 -1
  78. data/spec/lib/darthjee/core_ext/hash/deep_hash_constructor/setter_spec.rb +64 -0
  79. data/spec/lib/darthjee/core_ext/hash/deep_hash_constructor_spec.rb +16 -156
  80. data/spec/lib/darthjee/core_ext/hash/keys_sorter_spec.rb +5 -4
  81. data/spec/lib/darthjee/core_ext/hash/squasher_spec.rb +8 -2
  82. data/spec/lib/darthjee/core_ext/hash/value_changer_spec.rb +5 -13
  83. data/spec/lib/hash_spec.rb +87 -147
  84. data/spec/lib/object_spec.rb +32 -0
  85. data/spec/lib/symbol_spec.rb +2 -2
  86. data/spec/spec_helper.rb +4 -2
  87. data/spec/support/models/client.rb +23 -0
  88. data/spec/support/models/dummy_iterator.rb +4 -4
  89. data/spec/support/models/hash/value_changer/dummy.rb +1 -0
  90. data/spec/support/shared_examples/array/array_random.rb +2 -3
  91. data/spec/support/shared_examples/hash/chain_hash_keys_changer.rb +1 -1
  92. data/spec/support/shared_examples/hash/deep_hash.rb +166 -0
  93. data/spec/support/shared_examples/hash/hash_keys_changer.rb +3 -3
  94. data/spec/support/shared_examples/hash/hash_squasher.rb +54 -9
  95. data/spec/support/shared_examples/hash/keys_sorter.rb +266 -6
  96. data/spec/support/shared_examples/hash/map_to_hash.rb +1 -1
  97. data/spec/support/shared_examples/hash/remap.rb +4 -4
  98. data/spec/support/shared_examples/hash/value_changer.rb +2 -2
  99. metadata +41 -189
  100. data/lib/darthjee/core_ext/hash/to_hash_mapper.rb +0 -25
  101. data/spec/lib/darthjee/core_ext/hash/to_hash_mapper_spec.rb +0 -11
@@ -3,167 +3,27 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe Darthjee::CoreExt::Hash::DeepHashConstructor do
6
- let(:subject) { described_class.new('.') }
7
- let(:deep_hash) { subject.deep_hash(hash) }
6
+ subject(:constructor) { described_class.new('.') }
8
7
 
9
- describe '.deep_hash' do
10
- let(:hash) do
11
- {
12
- 'person.name' => 'Some name',
13
- 'person.age' => 22,
14
- 'status' => :success,
15
- 'vehicle.fuel' => 'GASOLINE',
16
- 'vehicle.doors' => 4
17
- }
18
- end
19
-
20
- let(:expected) do
21
- {
22
- 'person' => { 'name' => 'Some name', 'age' => 22 },
23
- 'vehicle' => { 'fuel' => 'GASOLINE', 'doors' => 4 },
24
- 'status' => :success
25
- }
26
- end
27
-
28
- it 'build a deep hash' do
29
- expect(deep_hash).to eq(expected)
30
- end
31
-
32
- context 'with indexed keys' do
33
- let(:hash) do
34
- {
35
- 'person[0].name' => 'First person',
36
- 'person[0].age' => 22,
37
- 'person[1].name' => 'Second person',
38
- 'person[1].age' => 27,
39
- 'device[0]' => 'GEAR_LOCK',
40
- 'device[1]' => 'GPS',
41
- 'zipCode' => '122345-123'
42
- }
43
- end
44
-
45
- let(:expected) do
46
- {
47
- 'person' => [
48
- { 'name' => 'First person', 'age' => 22 },
49
- { 'name' => 'Second person', 'age' => 27 }
50
- ],
51
- 'device' => %w[GEAR_LOCK GPS],
52
- 'zipCode' => '122345-123'
53
- }
54
- end
55
-
56
- it 'build a deep hash with arrays' do
57
- expect(deep_hash).to eq(expected)
58
- end
59
- end
60
-
61
- context 'with a n level hash' do
62
- let(:hash) do
63
- {
64
- 'quote_request.personal.person.name' => 'Some name',
65
- 'quote_request.personal.person.age' => 22,
66
- 'quote_request.insurance.vehicle.fuel' => 'GASOLINE',
67
- 'quote_request.insurance.vehicle.doors' => 4,
68
- 'request.status' => :success,
69
- 'trials' => 3
70
- }
71
- end
72
-
73
- let(:expected) do
74
- {
75
- 'quote_request' => {
76
- 'personal' => {
77
- 'person' => { 'name' => 'Some name', 'age' => 22 }
78
- },
79
- 'insurance' => {
80
- 'vehicle' => { 'fuel' => 'GASOLINE', 'doors' => 4 }
81
- }
82
- },
83
- 'request' => { 'status' => :success },
84
- 'trials' => 3
85
- }
86
- end
87
-
88
- it 'build a deep hash with arrays' do
89
- expect(deep_hash).to eq(expected)
90
- end
91
- end
92
-
93
- context 'with a n level hash and arrays' do
94
- let(:hash) do
95
- {
96
- 'quote_request.personal.person[0].name' => 'Some name 1',
97
- 'quote_request.personal.person[0].age' => 22,
98
- 'quote_request.personal.person[1].name' => 'Some name 2',
99
- 'quote_request.personal.person[1].age' => 23,
100
- 'request[0].status.clazz' => String,
101
- 'request[1].status.clazz' => Integer,
102
- 'request[2].status.clazz' => Date,
103
- 'trials' => 3
104
- }
105
- end
106
-
107
- let(:expected) do
108
- {
109
- 'quote_request' => {
110
- 'personal' => {
111
- 'person' => [
112
- { 'name' => 'Some name 1', 'age' => 22 },
113
- { 'name' => 'Some name 2', 'age' => 23 }
114
- ]
115
- }
116
- },
117
- 'request' => [
118
- { 'status' => { 'clazz' => String } },
119
- { 'status' => { 'clazz' => Integer } },
120
- { 'status' => { 'clazz' => Date } }
121
- ],
122
- 'trials' => 3
123
- }
124
- end
125
-
126
- it 'build a deep hash with arrays' do
127
- expect(deep_hash).to eq(expected)
128
- end
129
- end
8
+ let(:hash) do
9
+ {
10
+ 'person.name' => 'John',
11
+ 'person.age' => '22'
12
+ }
13
+ end
130
14
 
131
- context 'with custom separator' do
132
- let(:subject) { described_class.new('_') }
133
- let(:hash) do
134
- {
135
- 'person_name' => 'Some name',
136
- 'person_age' => 22,
137
- 'status' => :success,
138
- 'vehicle_fuel' => 'GASOLINE',
139
- 'vehicle_doors' => 4
140
- }
141
- end
15
+ describe '#deep_hash' do
16
+ it_behaves_like 'a method that returns a deep hash' do
17
+ subject(:constructor) { described_class.new(*args) }
142
18
 
143
- it 'build a deep hash with arrays' do
144
- expect(deep_hash).to eq(expected)
145
- end
19
+ let(:result) { constructor.deep_hash(hash) }
146
20
  end
147
21
 
148
- context 'with custom separator on n level deep hash' do
149
- let(:subject) { described_class.new('_') }
150
- let(:hash) do
151
- {
152
- 'person_name_clazz' => String
153
- }
154
- end
155
-
156
- let(:expected) do
157
- {
158
- 'person' => {
159
- 'name' => { 'clazz' => String }
160
- }
161
- }
162
- end
163
-
164
- it 'build a deep hash with arrays' do
165
- expect(deep_hash).to eq(expected)
166
- end
22
+ it 'does changes hash' do
23
+ expect { constructor.deep_hash(hash) }
24
+ .to change { hash }
25
+ .from('person.name' => 'John', 'person.age' => '22')
26
+ .to('person' => { 'name' => 'John', 'age' => '22' })
167
27
  end
168
28
  end
169
29
  end
@@ -3,9 +3,10 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe Darthjee::CoreExt::Hash::KeysSorter do
6
- it_behaves_like 'a class with a keys sort method' do
7
- subject { described_class.new(hash, **options) }
6
+ subject { described_class.new(hash, **options) }
8
7
 
9
- let(:result) { subject.sort }
10
- end
8
+ let(:result) { subject.sort }
9
+
10
+ it_behaves_like 'a class with a keys sort method'
11
+ it_behaves_like 'a class with a keys sort method that changes original'
11
12
  end
@@ -3,7 +3,13 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe Darthjee::CoreExt::Hash::Squasher do
6
- it_behaves_like 'a class that has a method to squash a hash' do
7
- let(:squashed) { described_class.squash(hash) }
6
+ describe '#squash' do
7
+ it_behaves_like 'a method to squash a hash' do
8
+ let(:squashed) { described_class.new.squash(hash) }
9
+ end
10
+
11
+ it_behaves_like 'a method to squash a hash', '/' do
12
+ let(:squashed) { described_class.new('/').squash(hash) }
13
+ end
8
14
  end
9
15
  end
@@ -3,7 +3,7 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe Darthjee::CoreExt::Hash::ValueChanger do
6
- subject(:changer) { described_class.new(options, &block) }
6
+ subject(:changer) { described_class.new(**options, &block) }
7
7
 
8
8
  let(:block) { proc { |value| value.to_s.size } }
9
9
 
@@ -216,8 +216,8 @@ describe Darthjee::CoreExt::Hash::ValueChanger do
216
216
  expect(changer.change(object)).to eq(expected)
217
217
  end
218
218
 
219
- it 'does not change original array' do
220
- expect { changer.change(object) }.not_to(change { array })
219
+ it 'change original array' do
220
+ expect { changer.change(object) }.to(change { array })
221
221
  end
222
222
  end
223
223
 
@@ -230,16 +230,8 @@ describe Darthjee::CoreExt::Hash::ValueChanger do
230
230
  expect(changer.change(object)).to eq(expected)
231
231
  end
232
232
 
233
- it 'does not change original array' do
234
- expect { changer.change(object) }.not_to(change { array })
235
- end
236
- end
237
-
238
- context 'when object is not an array or hash' do
239
- let(:object) { Object.new }
240
-
241
- it 'returns object' do
242
- expect(changer.change(object)).to eq(object)
233
+ it 'changes original array' do
234
+ expect { changer.change(object) }.to(change { array })
243
235
  end
244
236
  end
245
237
  end
@@ -16,16 +16,64 @@ describe Hash do
16
16
  let(:result) { hash.chain_fetch(*keys, &block) }
17
17
  end
18
18
 
19
- it_behaves_like 'a class that has a method to squash a hash' do
20
- let(:squashed) { hash.squash }
19
+ describe '#squash' do
20
+ subject(:hash) { { a: { b: { c: 10 } } } }
21
+
22
+ it_behaves_like 'a method to squash a hash' do
23
+ let(:squashed) { hash.squash }
24
+ end
25
+
26
+ it_behaves_like 'a method to squash a hash', '/' do
27
+ let(:squashed) { hash.squash('/') }
28
+ end
29
+
30
+ it 'does not change the hash' do
31
+ expect { hash.squash }
32
+ .not_to(change { hash })
33
+ end
34
+ end
35
+
36
+ describe '#squash!' do
37
+ subject(:hash) { { a: { b: { c: 10 } } } }
38
+
39
+ it_behaves_like 'a method to squash a hash' do
40
+ let(:squashed) { hash.squash! }
41
+ end
42
+
43
+ it_behaves_like 'a method to squash a hash', '/' do
44
+ let(:squashed) { hash.squash!('/') }
45
+ end
46
+
47
+ it 'does not change the hash' do
48
+ expect { hash.squash! }
49
+ .to change { hash }
50
+ .from(a: { b: { c: 10 } })
51
+ .to('a.b.c' => 10)
52
+ end
21
53
  end
22
54
 
23
55
  it_behaves_like 'a hash with map_to_hash method' do
24
56
  let(:mapped) { hash.map_to_hash(&mapping_block) }
25
57
  end
26
58
 
27
- it_behaves_like 'a class with a keys sort method' do
28
- let(:result) { hash.sort_keys(**options) }
59
+ describe '#sort_keys!' do
60
+ it_behaves_like 'a class with a keys sort method' do
61
+ let(:result) { hash.sort_keys!(**options) }
62
+ end
63
+
64
+ it_behaves_like 'a class with a keys sort method that changes original' do
65
+ let(:result) { hash.sort_keys!(**options) }
66
+ end
67
+ end
68
+
69
+ describe '#sort_keys' do
70
+ it_behaves_like 'a class with a keys sort method' do
71
+ let(:result) { hash.sort_keys(**options) }
72
+ end
73
+
74
+ it_behaves_like 'a class with a keys sort method that not change self' do
75
+ let(:result) { hash.sort_keys(**options) }
76
+ end
29
77
  end
30
78
 
31
79
  describe '#exclusive_merge' do
@@ -59,159 +107,38 @@ describe Hash do
59
107
  describe '#to_deep_hash' do
60
108
  subject(:hash) do
61
109
  {
62
- 'person.name' => 'Some name',
63
- 'person.age' => 22,
64
- 'status' => :success,
65
- 'vehicle.fuel' => 'GASOLINE',
66
- 'vehicle.doors' => 4
110
+ 'person.name' => 'John',
111
+ 'person.age' => '22'
67
112
  }
68
113
  end
69
114
 
70
- let(:expected) do
71
- {
72
- 'person' => { 'name' => 'Some name', 'age' => 22 },
73
- 'vehicle' => { 'fuel' => 'GASOLINE', 'doors' => 4 },
74
- 'status' => :success
75
- }
76
- end
77
-
78
- it 'build a deep hash' do
79
- expect(hash.to_deep_hash).to eq(expected)
80
- end
81
-
82
- context 'with indexed keys' do
83
- subject(:hash) do
84
- {
85
- 'person[0].name' => 'First person',
86
- 'person[0].age' => 22,
87
- 'person[1].name' => 'Second person',
88
- 'person[1].age' => 27,
89
- 'device[0]' => 'GEAR_LOCK',
90
- 'device[1]' => 'GPS',
91
- 'zipCode' => '122345-123'
92
- }
93
- end
94
-
95
- let(:expected) do
96
- {
97
- 'person' => [
98
- { 'name' => 'First person', 'age' => 22 },
99
- { 'name' => 'Second person', 'age' => 27 }
100
- ],
101
- 'device' => %w[GEAR_LOCK GPS],
102
- 'zipCode' => '122345-123'
103
- }
104
- end
105
-
106
- it 'build a deep hash with arrays' do
107
- expect(hash.to_deep_hash).to eq(expected)
108
- end
115
+ it_behaves_like 'a method that returns a deep hash' do
116
+ let(:result) { hash.to_deep_hash(*args) }
109
117
  end
110
118
 
111
- context 'with a n level hash' do
112
- subject(:hash) do
113
- {
114
- 'quote_request.personal.person.name' => 'Some name',
115
- 'quote_request.personal.person.age' => 22,
116
- 'quote_request.insurance.vehicle.fuel' => 'GASOLINE',
117
- 'quote_request.insurance.vehicle.doors' => 4,
118
- 'request.status' => :success,
119
- 'trials' => 3
120
- }
121
- end
122
-
123
- let(:expected) do
124
- {
125
- 'quote_request' => {
126
- 'personal' => {
127
- 'person' => { 'name' => 'Some name', 'age' => 22 }
128
- },
129
- 'insurance' => {
130
- 'vehicle' => { 'fuel' => 'GASOLINE', 'doors' => 4 }
131
- }
132
- },
133
- 'request' => { 'status' => :success },
134
- 'trials' => 3
135
- }
136
- end
137
-
138
- it 'build a deep hash with arrays' do
139
- expect(hash.to_deep_hash).to eq(expected)
140
- end
119
+ it 'does not change hash' do
120
+ expect { hash.to_deep_hash }
121
+ .not_to(change { hash })
141
122
  end
123
+ end
142
124
 
143
- context 'with a n level hash and arrays' do
144
- subject(:hash) do
145
- {
146
- 'quote_request.personal.person[0].name' => 'Some name 1',
147
- 'quote_request.personal.person[0].age' => 22,
148
- 'quote_request.personal.person[1].name' => 'Some name 2',
149
- 'quote_request.personal.person[1].age' => 23,
150
- 'request[0].status.clazz' => String,
151
- 'request[1].status.clazz' => Integer,
152
- 'request[2].status.clazz' => Date,
153
- 'trials' => 3
154
- }
155
- end
156
-
157
- let(:expected) do
158
- {
159
- 'quote_request' => {
160
- 'personal' => {
161
- 'person' => [
162
- { 'name' => 'Some name 1', 'age' => 22 },
163
- { 'name' => 'Some name 2', 'age' => 23 }
164
- ]
165
- }
166
- },
167
- 'request' => [
168
- { 'status' => { 'clazz' => String } },
169
- { 'status' => { 'clazz' => Integer } },
170
- { 'status' => { 'clazz' => Date } }
171
- ],
172
- 'trials' => 3
173
- }
174
- end
175
-
176
- it 'build a deep hash with arrays' do
177
- expect(hash.to_deep_hash).to eq(expected)
178
- end
125
+ describe '#to_deep_hash!' do
126
+ subject(:hash) do
127
+ {
128
+ 'person.name' => 'John',
129
+ 'person.age' => '22'
130
+ }
179
131
  end
180
132
 
181
- context 'with custom separator' do
182
- subject(:hash) do
183
- {
184
- 'person_name' => 'Some name',
185
- 'person_age' => 22,
186
- 'status' => :success,
187
- 'vehicle_fuel' => 'GASOLINE',
188
- 'vehicle_doors' => 4
189
- }
190
- end
191
-
192
- it 'build a deep hash with arrays' do
193
- expect(hash.to_deep_hash('_')).to eq(expected)
194
- end
133
+ it_behaves_like 'a method that returns a deep hash' do
134
+ let(:result) { hash.to_deep_hash!(*args) }
195
135
  end
196
136
 
197
- context 'with custom separator on n level deep hash' do
198
- subject(:hash) do
199
- {
200
- 'person_name_clazz' => String
201
- }
202
- end
203
-
204
- let(:expected) do
205
- {
206
- 'person' => {
207
- 'name' => { 'clazz' => String }
208
- }
209
- }
210
- end
211
-
212
- it 'build a deep hash with arrays' do
213
- expect(hash.to_deep_hash('_')).to eq(expected)
214
- end
137
+ it 'does changes hash' do
138
+ expect { hash.to_deep_hash! }
139
+ .to change { hash }
140
+ .from('person.name' => 'John', 'person.age' => '22')
141
+ .to('person' => { 'name' => 'John', 'age' => '22' })
215
142
  end
216
143
  end
217
144
 
@@ -283,6 +210,18 @@ describe Hash do
283
210
  it { expect(list).to be_empty }
284
211
  end
285
212
 
213
+ context 'when mapping returns empty arrays' do
214
+ let(:block) { proc { [] } }
215
+
216
+ it { expect(list).not_to be_empty }
217
+ end
218
+
219
+ context 'when mapping returns empty strings' do
220
+ let(:block) { proc { '' } }
221
+
222
+ it { expect(list).not_to be_empty }
223
+ end
224
+
286
225
  context 'when block returns false' do
287
226
  let(:block) { proc { false } }
288
227
 
@@ -314,7 +253,8 @@ describe Hash do
314
253
  list
315
254
  end
316
255
 
317
- it { expect(list).to eq(hash.values[1..-1].map(&:to_s)) }
256
+ it { expect(list).to eq(hash.values[1..].map(&:to_s)) }
257
+
318
258
  it 'calls the mapping only once for each value' do
319
259
  expect(transformer).to have_received(:transform).exactly(4)
320
260
  end
@@ -34,4 +34,36 @@ describe Object do
34
34
  end
35
35
  end
36
36
  end
37
+
38
+ # rubocop: disable RSpec/PredicateMatcher
39
+ describe '#trueful?' do
40
+ context 'when object is an empty array' do
41
+ it { expect([].trueful?).to be_truthy }
42
+ end
43
+
44
+ context 'when object is an empty hash' do
45
+ it { expect({}.trueful?).to be_truthy }
46
+ end
47
+
48
+ context 'when object is an empty string' do
49
+ it { expect(''.trueful?).to be_truthy }
50
+ end
51
+
52
+ context 'when object is a simple object' do
53
+ it { expect(described_class.new.trueful?).to be_truthy }
54
+ end
55
+
56
+ context 'when object is true' do
57
+ it { expect(true.trueful?).to be_truthy }
58
+ end
59
+
60
+ context 'when object is nil' do
61
+ it { expect(nil.trueful?).not_to be_truthy }
62
+ end
63
+
64
+ context 'when object is false' do
65
+ it { expect(false.trueful?).not_to be_truthy }
66
+ end
67
+ end
68
+ # rubocop: enable RSpec/PredicateMatcher
37
69
  end
@@ -4,7 +4,7 @@ require 'spec_helper'
4
4
 
5
5
  describe Symbol do
6
6
  describe '#camelize' do
7
- it { expect(:sym.camelize).to be_kind_of(described_class) }
7
+ it { expect(:sym.camelize).to be_a(described_class) }
8
8
 
9
9
  context 'when called with upper option' do
10
10
  it 'camelize the symbol' do
@@ -26,7 +26,7 @@ describe Symbol do
26
26
  end
27
27
 
28
28
  describe '#underscore' do
29
- it { expect(:symBol.underscore).to be_kind_of(described_class) }
29
+ it { expect(:symBol.underscore).to be_a(described_class) }
30
30
 
31
31
  context 'when called with upper option' do
32
32
  it 'underscore the symbol' do
data/spec/spec_helper.rb CHANGED
@@ -1,12 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'simplecov'
4
+ require 'simplecov_json_formatter'
4
5
 
5
- SimpleCov.profiles.define 'gem' do
6
+ SimpleCov.start do
6
7
  add_filter '/spec/'
8
+
9
+ SimpleCov.formatter = SimpleCov::Formatter::JSONFormatter if ENV['COVERAGE_JSON'] == 'true'
7
10
  end
8
11
 
9
- SimpleCov.start 'gem'
10
12
  require 'pry-nav'
11
13
  require 'darthjee/core_ext'
12
14
 
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Client
4
+ def initialize(existing_ids)
5
+ @existing_ids = existing_ids
6
+ end
7
+
8
+ def request(id)
9
+ requested << id
10
+
11
+ return unless existing_ids.include?(id)
12
+
13
+ { id: }
14
+ end
15
+
16
+ def requested
17
+ @requested ||= []
18
+ end
19
+
20
+ private
21
+
22
+ attr_reader :existing_ids
23
+ end
@@ -5,11 +5,11 @@ class DummyIterator
5
5
  @array = array
6
6
  end
7
7
 
8
- def map(*args, &block)
9
- @array.map(*args, &block)
8
+ def map(*, &)
9
+ @array.map(*, &)
10
10
  end
11
11
 
12
- def each(*args, &block)
13
- @array.each(*args, &block)
12
+ def each(*, &)
13
+ @array.each(*, &)
14
14
  end
15
15
  end
@@ -18,6 +18,7 @@ class Hash
18
18
  def eql?(other)
19
19
  return true if equals?(other)
20
20
  return false unless other.is_a?(self.class)
21
+
21
22
  a.value == value
22
23
  end
23
24
  end
@@ -3,13 +3,12 @@
3
3
  shared_examples 'a method that returns a random element' do |method|
4
4
  let(:array) { [7, 5, 3] }
5
5
 
6
- (0..2).each do |index|
6
+ 3.times do |index|
7
7
  context "when random returns #{index}" do
8
8
  let!(:expected) { array[index] }
9
9
 
10
10
  before do
11
- allow(Random).to receive(:rand)
12
- .with(array.size) { index }
11
+ allow(Random).to receive(:rand).and_return(index)
13
12
  end
14
13
 
15
14
  it 'returns the randomized index of the array' do
@@ -60,7 +60,7 @@ shared_examples 'a method that is able to chain change keys' do |method|
60
60
  end
61
61
 
62
62
  context 'when options are given' do
63
- let(:options) { { recursive: recursive } }
63
+ let(:options) { { recursive: } }
64
64
 
65
65
  context 'with recursion' do
66
66
  let(:recursive) { true }