dry-configurable 0.7.0 → 0.8.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.
- checksums.yaml +5 -5
- data/.gitignore +0 -1
- data/.travis.yml +5 -12
- data/CHANGELOG.md +46 -2
- data/CONTRIBUTING.md +29 -0
- data/Gemfile +1 -0
- data/README.md +18 -31
- data/dry-configurable.gemspec +5 -4
- data/lib/dry/configurable/config.rb +109 -40
- data/lib/dry/configurable/error.rb +0 -2
- data/lib/dry/configurable/setting.rb +37 -0
- data/lib/dry/configurable/settings/argument_parser.rb +50 -0
- data/lib/dry/configurable/settings.rb +92 -0
- data/lib/dry/configurable/test_interface.rb +5 -1
- data/lib/dry/configurable/version.rb +1 -1
- data/lib/dry/configurable.rb +116 -127
- metadata +44 -37
- data/.ruby-version +0 -1
- data/lib/dry/configurable/argument_parser.rb +0 -91
- data/lib/dry/configurable/config/value.rb +0 -27
- data/lib/dry/configurable/nested_config.rb +0 -33
- data/spec/integration/configurable_spec.rb +0 -25
- data/spec/spec_helper.rb +0 -92
- data/spec/support/shared_examples/configurable.rb +0 -391
- data/spec/unit/dry/configurable/argument_parser_spec.rb +0 -114
- data/spec/unit/dry/configurable/config/value_spec.rb +0 -55
- data/spec/unit/dry/configurable/config_spec.rb +0 -186
data/spec/spec_helper.rb
DELETED
@@ -1,92 +0,0 @@
|
|
1
|
-
if ENV['COVERAGE'] == 'true' && RUBY_ENGINE == 'ruby' && RUBY_VERSION == '2.3.1'
|
2
|
-
require 'simplecov'
|
3
|
-
|
4
|
-
SimpleCov.start do
|
5
|
-
add_filter '/spec/'
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
10
|
-
RSpec.configure do |config|
|
11
|
-
config.expect_with :rspec do |expectations|
|
12
|
-
# This option will default to `true` in RSpec 4. It makes the `description`
|
13
|
-
# and `failure_message` of custom matchers include text for helper methods
|
14
|
-
# defined using `chain`, e.g.:
|
15
|
-
# be_bigger_than(2).and_smaller_than(4).description
|
16
|
-
# # => "be bigger than 2 and smaller than 4"
|
17
|
-
# ...rather than:
|
18
|
-
# # => "be bigger than 2"
|
19
|
-
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
20
|
-
end
|
21
|
-
|
22
|
-
config.mock_with :rspec do |mocks|
|
23
|
-
# Prevents you from mocking or stubbing a method that does not exist on
|
24
|
-
# a real object. This is generally recommended, and will default to
|
25
|
-
# `true` in RSpec 4.
|
26
|
-
mocks.verify_partial_doubles = true
|
27
|
-
end
|
28
|
-
|
29
|
-
# This option will default to `:apply_to_host_groups` in RSpec 4 (and will
|
30
|
-
# have no way to turn it off -- the option exists only for backwards
|
31
|
-
# compatibility in RSpec 3). It causes shared context metadata to be
|
32
|
-
# inherited by the metadata hash of host groups and examples, rather than
|
33
|
-
# triggering implicit auto-inclusion in groups with matching metadata.
|
34
|
-
config.shared_context_metadata_behavior = :apply_to_host_groups
|
35
|
-
|
36
|
-
# This allows you to limit a spec run to individual examples or groups
|
37
|
-
# you care about by tagging them with `:focus` metadata. When nothing
|
38
|
-
# is tagged with `:focus`, all examples get run. RSpec also provides
|
39
|
-
# aliases for `it`, `describe`, and `context` that include `:focus`
|
40
|
-
# metadata: `fit`, `fdescribe` and `fcontext`, respectively.
|
41
|
-
config.filter_run_when_matching :focus
|
42
|
-
|
43
|
-
# Allows RSpec to persist some state between runs in order to support
|
44
|
-
# the `--only-failures` and `--next-failure` CLI options. We recommend
|
45
|
-
# you configure your source control system to ignore this file.
|
46
|
-
config.example_status_persistence_file_path = 'spec/examples.txt'
|
47
|
-
|
48
|
-
# Limits the available syntax to the non-monkey patched syntax that is
|
49
|
-
# recommended. For more details, see:
|
50
|
-
# - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
|
51
|
-
# - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
52
|
-
# - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
|
53
|
-
config.disable_monkey_patching!
|
54
|
-
|
55
|
-
# This setting enables warnings. It's recommended, but in some cases may
|
56
|
-
# be too noisy due to issues in dependencies.
|
57
|
-
config.warnings = true
|
58
|
-
|
59
|
-
# Many RSpec users commonly either run the entire suite or an individual
|
60
|
-
# file, and it's useful to allow more verbose output when running an
|
61
|
-
# individual spec file.
|
62
|
-
if config.files_to_run.one?
|
63
|
-
# Use the documentation formatter for detailed output,
|
64
|
-
# unless a formatter has already been configured
|
65
|
-
# (e.g. via a command-line flag).
|
66
|
-
config.default_formatter = 'doc'
|
67
|
-
end
|
68
|
-
|
69
|
-
# Print the n slowest examples and example groups at the
|
70
|
-
# end of the spec run, to help surface which specs are running
|
71
|
-
# particularly slow.
|
72
|
-
config.profile_examples = 3
|
73
|
-
|
74
|
-
# Run specs in random order to surface order dependencies. If you find an
|
75
|
-
# order dependency and want to debug it, you can fix the order by providing
|
76
|
-
# the seed, which is printed after each run.
|
77
|
-
# --seed 1234
|
78
|
-
config.order = :random
|
79
|
-
|
80
|
-
# Seed global randomization in this process using the `--seed` CLI option.
|
81
|
-
# Setting this allows you to use `--seed` to deterministically reproduce
|
82
|
-
# test failures related to randomization by passing the same `--seed` value
|
83
|
-
# as the one that triggered the failure.
|
84
|
-
Kernel.srand config.seed
|
85
|
-
end
|
86
|
-
|
87
|
-
require 'dry/configurable'
|
88
|
-
require 'dry/configurable/test_interface'
|
89
|
-
|
90
|
-
Dir[Pathname(__FILE__).dirname.join('support/**/*.rb').to_s].each do |file|
|
91
|
-
require file
|
92
|
-
end
|
@@ -1,391 +0,0 @@
|
|
1
|
-
RSpec.shared_examples 'a configurable class' do
|
2
|
-
describe Dry::Configurable do
|
3
|
-
describe 'settings' do
|
4
|
-
context 'without processor option' do
|
5
|
-
context 'without default value' do
|
6
|
-
before do
|
7
|
-
klass.setting :dsn
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'returns nil' do
|
11
|
-
expect(klass.config.dsn).to be(nil)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
context 'with default value' do
|
16
|
-
context 'with a nil default value' do
|
17
|
-
before do
|
18
|
-
klass.setting :dsn, nil
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'returns the default value' do
|
22
|
-
expect(klass.config.dsn).to be(nil)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
context 'with a false default value' do
|
27
|
-
before do
|
28
|
-
klass.setting :dsn, false
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'returns the default value' do
|
32
|
-
expect(klass.config.dsn).to be(false)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
context 'with a string default value' do
|
37
|
-
before do
|
38
|
-
klass.setting :dsn, 'sqlite:memory'
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'returns the default value' do
|
42
|
-
expect(klass.config.dsn).to eq('sqlite:memory')
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
context 'with a hash default value' do
|
47
|
-
before do
|
48
|
-
klass.setting :db_config, {
|
49
|
-
user: 'root',
|
50
|
-
password: ''
|
51
|
-
}
|
52
|
-
end
|
53
|
-
|
54
|
-
it 'returns the default value' do
|
55
|
-
expect(klass.config.db_config).to eq(
|
56
|
-
user: 'root',
|
57
|
-
password: ''
|
58
|
-
)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
context 'reader option' do
|
64
|
-
context 'without passing option' do
|
65
|
-
before do
|
66
|
-
klass.setting :dsn
|
67
|
-
end
|
68
|
-
|
69
|
-
before do
|
70
|
-
klass.configure do |config|
|
71
|
-
config.dsn = 'jdbc:sqlite:memory'
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'will not create a getter method' do
|
76
|
-
expect(klass.respond_to?(:dsn)).to be_falsey
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
context 'with hash as value ' do
|
81
|
-
before do
|
82
|
-
klass.setting :dsn, { foo: 'bar' }, reader: true
|
83
|
-
end
|
84
|
-
|
85
|
-
it 'will create a getter method' do
|
86
|
-
expect(klass.dsn).to eq(foo: 'bar')
|
87
|
-
expect(klass.respond_to?(:dsn)).to be_truthy
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
context 'with option set to true' do
|
92
|
-
before do
|
93
|
-
klass.setting :dsn, 'testing', reader: true
|
94
|
-
end
|
95
|
-
|
96
|
-
it 'will create a getter method' do
|
97
|
-
expect(klass.dsn).to eq 'testing'
|
98
|
-
expect(klass.respond_to?(:dsn)).to be_truthy
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
context 'with nested configuration' do
|
103
|
-
before do
|
104
|
-
klass.setting :dsn, reader: true do
|
105
|
-
setting :pool, 5
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
it 'will create a nested getter method' do
|
110
|
-
expect(klass.dsn.pool).to eq 5
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
context 'with processor' do
|
115
|
-
context 'with default value' do
|
116
|
-
before do
|
117
|
-
klass.setting(:dsn, 'memory', reader: true) { |dsn| "sqlite:#{dsn}" }
|
118
|
-
end
|
119
|
-
|
120
|
-
it 'returns the default value' do
|
121
|
-
expect(klass.dsn).to eq('sqlite:memory')
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
context 'without default value' do
|
126
|
-
before do
|
127
|
-
klass.setting(:dsn, reader: true) { |dsn| "sqlite:#{dsn}" }
|
128
|
-
end
|
129
|
-
|
130
|
-
it 'returns the default value' do
|
131
|
-
expect(klass.dsn).to eq(nil)
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
context 'nested configuration' do
|
138
|
-
before do
|
139
|
-
klass.setting :database do
|
140
|
-
setting :dsn, 'sqlite:memory'
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
it 'returns the default value' do
|
145
|
-
expect(klass.config.database.dsn).to eq('sqlite:memory')
|
146
|
-
end
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
context 'with processor' do
|
151
|
-
context 'without default value' do
|
152
|
-
before do
|
153
|
-
klass.setting(:dsn) { |dsn| "sqlite:#{dsn}" }
|
154
|
-
end
|
155
|
-
|
156
|
-
it 'returns nil' do
|
157
|
-
expect(klass.config.dsn).to be(nil)
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
|
-
context 'with default value' do
|
162
|
-
before do
|
163
|
-
klass.setting(:dsn, 'memory') { |dsn| "sqlite:#{dsn}" }
|
164
|
-
end
|
165
|
-
|
166
|
-
it 'returns the default value' do
|
167
|
-
expect(klass.config.dsn).to eq('sqlite:memory')
|
168
|
-
end
|
169
|
-
end
|
170
|
-
|
171
|
-
context 'nested configuration' do
|
172
|
-
before do
|
173
|
-
klass.setting :database do
|
174
|
-
setting(:dsn, 'memory') { |dsn| "sqlite:#{dsn}" }
|
175
|
-
end
|
176
|
-
end
|
177
|
-
|
178
|
-
it 'returns the default value' do
|
179
|
-
expect(klass.config.database.dsn).to eq('sqlite:memory')
|
180
|
-
end
|
181
|
-
end
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
|
-
describe 'configuration' do
|
186
|
-
context 'without nesting' do
|
187
|
-
context 'without processor' do
|
188
|
-
before do
|
189
|
-
klass.setting :dsn, 'sqlite:memory'
|
190
|
-
end
|
191
|
-
|
192
|
-
before do
|
193
|
-
klass.configure do |config|
|
194
|
-
config.dsn = 'jdbc:sqlite:memory'
|
195
|
-
end
|
196
|
-
end
|
197
|
-
|
198
|
-
it 'updates the config value' do
|
199
|
-
expect(klass.config.dsn).to eq('jdbc:sqlite:memory')
|
200
|
-
end
|
201
|
-
end
|
202
|
-
|
203
|
-
context 'with processor' do
|
204
|
-
before do
|
205
|
-
klass.setting(:dsn, 'sqlite') { |dsn| "#{dsn}:memory" }
|
206
|
-
end
|
207
|
-
|
208
|
-
before do
|
209
|
-
klass.configure do |config|
|
210
|
-
config.dsn = 'jdbc:sqlite'
|
211
|
-
end
|
212
|
-
end
|
213
|
-
|
214
|
-
it 'updates the config value' do
|
215
|
-
expect(klass.config.dsn).to eq('jdbc:sqlite:memory')
|
216
|
-
end
|
217
|
-
end
|
218
|
-
end
|
219
|
-
|
220
|
-
context 'with nesting' do
|
221
|
-
context 'without processor' do
|
222
|
-
before do
|
223
|
-
klass.setting :database do
|
224
|
-
setting :dsn, 'sqlite:memory'
|
225
|
-
end
|
226
|
-
|
227
|
-
klass.configure do |config|
|
228
|
-
config.database.dsn = 'jdbc:sqlite:memory'
|
229
|
-
end
|
230
|
-
end
|
231
|
-
|
232
|
-
it 'updates the config value' do
|
233
|
-
expect(klass.config.database.dsn).to eq('jdbc:sqlite:memory')
|
234
|
-
end
|
235
|
-
end
|
236
|
-
|
237
|
-
context 'with processor' do
|
238
|
-
before do
|
239
|
-
klass.setting :database do
|
240
|
-
setting(:dsn, 'sqlite') { |dsn| "#{dsn}:memory" }
|
241
|
-
end
|
242
|
-
|
243
|
-
klass.configure do |config|
|
244
|
-
config.database.dsn = 'jdbc:sqlite'
|
245
|
-
end
|
246
|
-
end
|
247
|
-
|
248
|
-
it 'updates the config value' do
|
249
|
-
expect(klass.config.database.dsn).to eq('jdbc:sqlite:memory')
|
250
|
-
end
|
251
|
-
end
|
252
|
-
end
|
253
|
-
|
254
|
-
context 'when finalized' do
|
255
|
-
before do
|
256
|
-
klass.setting :dsn
|
257
|
-
klass.configure do |config|
|
258
|
-
config.dsn = 'jdbc:sqlite'
|
259
|
-
end
|
260
|
-
klass.finalize!
|
261
|
-
end
|
262
|
-
|
263
|
-
it 'disallows modification' do
|
264
|
-
expect do
|
265
|
-
klass.configure do |config|
|
266
|
-
config.dsn = 'jdbc:sqlite'
|
267
|
-
end
|
268
|
-
end.to raise_error(Dry::Configurable::FrozenConfig, 'Cannot modify frozen config')
|
269
|
-
end
|
270
|
-
|
271
|
-
it 'disallows direct modification on config' do
|
272
|
-
expect do
|
273
|
-
klass.config.dsn = 'jdbc:sqlite:memory'
|
274
|
-
end.to raise_error(Dry::Configurable::FrozenConfig, 'Cannot modify frozen config')
|
275
|
-
end
|
276
|
-
end
|
277
|
-
|
278
|
-
context 'when inherited' do
|
279
|
-
context 'without processor' do
|
280
|
-
before do
|
281
|
-
klass.setting :dsn
|
282
|
-
klass.configure do |config|
|
283
|
-
config.dsn = 'jdbc:sqlite:memory'
|
284
|
-
end
|
285
|
-
end
|
286
|
-
|
287
|
-
subject!(:subclass) { Class.new(klass) }
|
288
|
-
|
289
|
-
it 'retains its configuration' do
|
290
|
-
expect(subclass.config.dsn).to eq('jdbc:sqlite:memory')
|
291
|
-
end
|
292
|
-
|
293
|
-
context 'when the inherited config is modified' do
|
294
|
-
before do
|
295
|
-
subclass.configure do |config|
|
296
|
-
config.dsn = 'jdbc:sqlite:file'
|
297
|
-
end
|
298
|
-
end
|
299
|
-
|
300
|
-
it 'does not modify the original' do
|
301
|
-
expect(klass.config.dsn).to eq('jdbc:sqlite:memory')
|
302
|
-
expect(subclass.config.dsn).to eq('jdbc:sqlite:file')
|
303
|
-
end
|
304
|
-
end
|
305
|
-
end
|
306
|
-
|
307
|
-
context 'with processor' do
|
308
|
-
before do
|
309
|
-
klass.setting(:dsn) { |dsn| "#{dsn}:memory" }
|
310
|
-
klass.configure do |config|
|
311
|
-
config.dsn = 'jdbc:sqlite'
|
312
|
-
end
|
313
|
-
end
|
314
|
-
|
315
|
-
subject!(:subclass) { Class.new(klass) }
|
316
|
-
|
317
|
-
it 'retains its configuration' do
|
318
|
-
expect(subclass.config.dsn).to eq('jdbc:sqlite:memory')
|
319
|
-
end
|
320
|
-
|
321
|
-
context 'when the inherited config is modified' do
|
322
|
-
before do
|
323
|
-
subclass.configure do |config|
|
324
|
-
config.dsn = 'sqlite'
|
325
|
-
end
|
326
|
-
end
|
327
|
-
|
328
|
-
it 'does not modify the original' do
|
329
|
-
expect(klass.config.dsn).to eq('jdbc:sqlite:memory')
|
330
|
-
expect(subclass.config.dsn).to eq('sqlite:memory')
|
331
|
-
end
|
332
|
-
end
|
333
|
-
end
|
334
|
-
|
335
|
-
context 'when the inherited settings are modified' do
|
336
|
-
before do
|
337
|
-
klass.setting :dsn
|
338
|
-
subclass.setting :db
|
339
|
-
klass.configure do |config|
|
340
|
-
config.dsn = 'jdbc:sqlite:memory'
|
341
|
-
end
|
342
|
-
end
|
343
|
-
|
344
|
-
subject!(:subclass) { Class.new(klass) }
|
345
|
-
|
346
|
-
it 'does not modify the original' do
|
347
|
-
expect(klass.settings).to_not include(:db)
|
348
|
-
end
|
349
|
-
end
|
350
|
-
end
|
351
|
-
end
|
352
|
-
|
353
|
-
context 'Test Interface' do
|
354
|
-
before { klass.enable_test_interface }
|
355
|
-
|
356
|
-
describe 'reset_config' do
|
357
|
-
before do
|
358
|
-
klass.setting :dsn, nil
|
359
|
-
klass.setting :pool do
|
360
|
-
setting :size, nil
|
361
|
-
end
|
362
|
-
|
363
|
-
klass.configure do |config|
|
364
|
-
config.dsn = 'sqlite:memory'
|
365
|
-
config.pool.size = 5
|
366
|
-
end
|
367
|
-
|
368
|
-
klass.reset_config
|
369
|
-
end
|
370
|
-
|
371
|
-
it 'resets configuration to default values' do
|
372
|
-
expect(klass.config.dsn).to be_nil
|
373
|
-
expect(klass.config.pool.size).to be_nil
|
374
|
-
end
|
375
|
-
end
|
376
|
-
end
|
377
|
-
|
378
|
-
context 'Try to set new value after config has been created' do
|
379
|
-
before do
|
380
|
-
klass.setting :dsn, 'sqlite:memory'
|
381
|
-
klass.config
|
382
|
-
end
|
383
|
-
|
384
|
-
it 'raise an exception' do
|
385
|
-
expect { klass.setting :pool, 5 }.to raise_error(
|
386
|
-
Dry::Configurable::AlreadyDefinedConfig
|
387
|
-
)
|
388
|
-
end
|
389
|
-
end
|
390
|
-
end
|
391
|
-
end
|
@@ -1,114 +0,0 @@
|
|
1
|
-
RSpec.describe Dry::Configurable::ArgumentParser do
|
2
|
-
let(:klass) { Dry::Configurable::ArgumentParser }
|
3
|
-
|
4
|
-
context 'with no args' do
|
5
|
-
let(:parsed) { klass.new([]) }
|
6
|
-
|
7
|
-
it 'return default values' do
|
8
|
-
expect(parsed.value).to eq nil
|
9
|
-
expect(parsed.options).to eq({})
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
context 'with value and options' do
|
14
|
-
let(:parsed) { klass.new([value, options]) }
|
15
|
-
|
16
|
-
context 'valid options' do
|
17
|
-
let(:value) { 'dry-rb' }
|
18
|
-
let(:options) do
|
19
|
-
{ reader: true }
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'returns correct value and options' do
|
23
|
-
expect(parsed.value).to eq 'dry-rb'
|
24
|
-
expect(parsed.options).to eq(reader: true)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
context 'invalid options' do
|
29
|
-
let(:value) { 'dry-rb' }
|
30
|
-
let(:options) do
|
31
|
-
{ writer: true }
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'returns correct values and empty options' do
|
35
|
-
expect(parsed.value).to eq 'dry-rb'
|
36
|
-
expect(parsed.options).to eq({})
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
context 'values as hash' do
|
41
|
-
let(:value) do
|
42
|
-
{ db: 'dry-rb' }
|
43
|
-
end
|
44
|
-
let(:options) do
|
45
|
-
{ reader: true }
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'returns correct values and empty options' do
|
49
|
-
expect(parsed.value).to eq(db: 'dry-rb')
|
50
|
-
expect(parsed.options).to eq(reader: true)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
context 'values as array' do
|
55
|
-
let(:value) { [1, 2, 3] }
|
56
|
-
let(:options) do
|
57
|
-
{ reader: true }
|
58
|
-
end
|
59
|
-
|
60
|
-
it 'returns correct values and empty options' do
|
61
|
-
expect(parsed.value).to eq([1, 2, 3])
|
62
|
-
expect(parsed.options).to eq(reader: true)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
context 'with value only' do
|
68
|
-
let(:parsed) { klass.new([value]) }
|
69
|
-
context 'valid options' do
|
70
|
-
let(:value) { 'dry-rb' }
|
71
|
-
|
72
|
-
it 'returns correct value and options' do
|
73
|
-
expect(parsed.value).to eq 'dry-rb'
|
74
|
-
expect(parsed.options).to eq({})
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
context 'with hash with non option key' do
|
79
|
-
let(:value) do
|
80
|
-
{ writer: true }
|
81
|
-
end
|
82
|
-
|
83
|
-
it 'returns correct value and options' do
|
84
|
-
expect(parsed.value).to eq(writer: true)
|
85
|
-
expect(parsed.options).to eq({})
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
context 'with hash with option key' do
|
90
|
-
let(:value) do
|
91
|
-
{ reader: true, writer: true }
|
92
|
-
end
|
93
|
-
|
94
|
-
it 'returns correct value and options' do
|
95
|
-
expect(parsed.value).to eq nil
|
96
|
-
expect(parsed.options).to eq(reader: true)
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
context 'with options only' do
|
102
|
-
let(:parsed) { klass.new([options]) }
|
103
|
-
context 'valid options' do
|
104
|
-
let(:options) do
|
105
|
-
{ reader: true }
|
106
|
-
end
|
107
|
-
|
108
|
-
it 'returns correct value and options' do
|
109
|
-
expect(parsed.value).to eq nil
|
110
|
-
expect(parsed.options).to eq(reader: true)
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
RSpec.describe Dry::Configurable::Config::Value do
|
2
|
-
let(:klass) { Dry::Configurable::Config::Value }
|
3
|
-
let(:config) { klass.new(name, value, processor) }
|
4
|
-
let(:name) { :db }
|
5
|
-
let(:value) { 'test' }
|
6
|
-
let(:processor) { ->(v) { v } }
|
7
|
-
|
8
|
-
describe '#initialize' do
|
9
|
-
it 'coerces string name to symbol' do
|
10
|
-
config = klass.new('db', value, processor)
|
11
|
-
|
12
|
-
expect(config.name).to eq(:db)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
describe '#name' do
|
17
|
-
subject! { config.name }
|
18
|
-
|
19
|
-
it { is_expected.to eq(name) }
|
20
|
-
end
|
21
|
-
|
22
|
-
describe '#value' do
|
23
|
-
subject! { config.value }
|
24
|
-
|
25
|
-
context 'when value is not NONE' do
|
26
|
-
it { is_expected.to eq(value) }
|
27
|
-
end
|
28
|
-
|
29
|
-
context 'when value is NONE' do
|
30
|
-
let(:value) { klass::NONE }
|
31
|
-
|
32
|
-
it { is_expected.to be(nil) }
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
describe '#processor' do
|
37
|
-
subject! { config.processor }
|
38
|
-
|
39
|
-
it { is_expected.to eq(processor) }
|
40
|
-
end
|
41
|
-
|
42
|
-
describe '#none?' do
|
43
|
-
subject! { config.none? }
|
44
|
-
|
45
|
-
context 'when value is not NONE' do
|
46
|
-
it { is_expected.to be(false) }
|
47
|
-
end
|
48
|
-
|
49
|
-
context 'when value is NONE' do
|
50
|
-
let(:value) { klass::NONE }
|
51
|
-
|
52
|
-
it { is_expected.to be(true) }
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|