qonfig 0.25.0 → 0.26.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -2
- data/.rubocop.yml +19 -1
- data/.travis.yml +7 -2
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +102 -0
- data/README.md +2 -0
- data/gemfiles/with_external_deps.gemfile.lock +112 -0
- data/gemfiles/without_external_deps.gemfile.lock +102 -0
- data/lib/qonfig.rb +1 -1
- data/lib/qonfig/commands/definition/load_from_env.rb +2 -0
- data/lib/qonfig/commands/definition/load_from_env/value_converter.rb +2 -0
- data/lib/qonfig/imports/direct_key.rb +8 -2
- data/lib/qonfig/imports/mappings.rb +8 -2
- data/lib/qonfig/loaders/basic.rb +2 -0
- data/lib/qonfig/loaders/json.rb +2 -1
- data/lib/qonfig/settings.rb +5 -1
- data/lib/qonfig/settings/key_matcher.rb +1 -1
- data/lib/qonfig/uploaders/base.rb +2 -0
- data/lib/qonfig/uploaders/yaml.rb +2 -0
- data/lib/qonfig/version.rb +1 -1
- data/qonfig.gemspec +4 -6
- data/sig/.keep +0 -0
- data/spec/features/clear_options_spec.rb +92 -0
- data/spec/features/compacted_config_spec.rb +308 -0
- data/spec/features/composition_spec.rb +207 -0
- data/spec/features/config_definition_and_representation_spec.rb +535 -0
- data/spec/features/definition_order_spec.rb +69 -0
- data/spec/features/dig_functionality_spec.rb +47 -0
- data/spec/features/dot_notation_spec.rb +159 -0
- data/spec/features/export_settings_spec.rb +138 -0
- data/spec/features/expose_json_spec.rb +281 -0
- data/spec/features/expose_self/format_option_dynamic_spec.rb +69 -0
- data/spec/features/expose_self/format_option_json_spec.rb +74 -0
- data/spec/features/expose_self/format_option_unsupported_spec.rb +27 -0
- data/spec/features/expose_self/format_option_yaml_spec.rb +77 -0
- data/spec/features/expose_self_spec.rb +97 -0
- data/spec/features/expose_yaml_spec.rb +263 -0
- data/spec/features/freeze_state_spec.rb +122 -0
- data/spec/features/get_config_keys_spec.rb +62 -0
- data/spec/features/get_config_values_spec.rb +41 -0
- data/spec/features/has_a_key_spec.rb +48 -0
- data/spec/features/import_settings_spec.rb +323 -0
- data/spec/features/indifferent_access_spec.rb +57 -0
- data/spec/features/inheritance_spec.rb +110 -0
- data/spec/features/instantiation_without_class_definition_spec.rb +59 -0
- data/spec/features/iteration_over_setting_keys_spec.rb +48 -0
- data/spec/features/load_from_env_spec.rb +240 -0
- data/spec/features/load_from_json_spec.rb +97 -0
- data/spec/features/load_from_self/format_option_json_spec.rb +31 -0
- data/spec/features/load_from_self/format_option_unsupported_spec.rb +27 -0
- data/spec/features/load_from_self/format_option_yaml_spec.rb +49 -0
- data/spec/features/load_from_self/with_erb_instructions_spec.rb +33 -0
- data/spec/features/load_from_self/with_hash_like_data_representation_spec.rb +66 -0
- data/spec/features/load_from_self/with_non_hash_like_data_representation_spec.rb +19 -0
- data/spec/features/load_from_self/without_end_data_spec.rb +11 -0
- data/spec/features/load_from_yaml_spec.rb +110 -0
- data/spec/features/load_setting_values_from_file/by_instance_method_examples.rb +171 -0
- data/spec/features/load_setting_values_from_file/by_macros_examples.rb +165 -0
- data/spec/features/load_setting_values_from_file/load_from_json_spec.rb +21 -0
- data/spec/features/load_setting_values_from_file/load_from_self/json_format/end_data_with_env_spec.rb +100 -0
- data/spec/features/load_setting_values_from_file/load_from_self/json_format/with_end_data_spec.rb +129 -0
- data/spec/features/load_setting_values_from_file/load_from_self/json_format/with_incorrect_end_data_spec.rb +34 -0
- data/spec/features/load_setting_values_from_file/load_from_self/json_format/without_end_data_spec.rb +65 -0
- data/spec/features/load_setting_values_from_file/load_from_self/yaml_format/end_data_with_env_spec.rb +94 -0
- data/spec/features/load_setting_values_from_file/load_from_self/yaml_format/with_end_data_spec.rb +126 -0
- data/spec/features/load_setting_values_from_file/load_from_self/yaml_format/with_incorrect_end_data_spec.rb +32 -0
- data/spec/features/load_setting_values_from_file/load_from_self/yaml_format/without_end_data_spec.rb +65 -0
- data/spec/features/load_setting_values_from_file/load_from_yaml_spec.rb +21 -0
- data/spec/features/load_setting_values_from_file/shared_behavior_spec.rb +33 -0
- data/spec/features/mixin_spec.rb +387 -0
- data/spec/features/non_redefineable_core_methods_spec.rb +29 -0
- data/spec/features/plugins/pretty_print_spec.rb +86 -0
- data/spec/features/plugins/toml/expose_self/format_option_toml_spec.rb +71 -0
- data/spec/features/plugins/toml/expose_toml_spec.rb +221 -0
- data/spec/features/plugins/toml/load_from_self/format_option_toml_spec.rb +27 -0
- data/spec/features/plugins/toml/load_from_toml_spec.rb +109 -0
- data/spec/features/plugins/toml/load_setting_values_from_file/load_from_toml_spec.rb +27 -0
- data/spec/features/plugins/toml/load_setting_values_from_file/load_toml_from_self/end_data_with_env_spec.rb +95 -0
- data/spec/features/plugins/toml/load_setting_values_from_file/load_toml_from_self/with_end_data_spec.rb +125 -0
- data/spec/features/plugins/toml/load_setting_values_from_file/load_toml_from_self/with_incorrect_end_data_spec.rb +34 -0
- data/spec/features/plugins/toml/load_setting_values_from_file/load_toml_from_self/without_end_data_spec.rb +65 -0
- data/spec/features/plugins/toml/load_setting_values_from_file/shared_behavior_spec.rb +34 -0
- data/spec/features/plugins/toml/save_to_toml_spec.rb +149 -0
- data/spec/features/plugins/vault/expose_vault_spec.rb +117 -0
- data/spec/features/plugins/vault/load_from_vault_spec.rb +80 -0
- data/spec/features/plugins_spec.rb +89 -0
- data/spec/features/reload_spec.rb +75 -0
- data/spec/features/run_code_with_temporary_settings_spec.rb +104 -0
- data/spec/features/save_to_file/save_to_json_spec.rb +157 -0
- data/spec/features/save_to_file/save_to_yaml_spec.rb +189 -0
- data/spec/features/settings_as_predicates_spec.rb +47 -0
- data/spec/features/settings_redefinition_spec.rb +30 -0
- data/spec/features/slice_functionality_spec.rb +69 -0
- data/spec/features/subset_functionality_spec.rb +49 -0
- data/spec/features/validation_spec.rb +916 -0
- data/spec/fixtures/array_settings.yml +3 -0
- data/spec/fixtures/expose_json/incompatible_root_structure.json +6 -0
- data/spec/fixtures/expose_json/incompatible_structure.json +4 -0
- data/spec/fixtures/expose_json/project.development.json +7 -0
- data/spec/fixtures/expose_json/project.json +30 -0
- data/spec/fixtures/expose_json/project.production.json +7 -0
- data/spec/fixtures/expose_json/project.staging.json +7 -0
- data/spec/fixtures/expose_json/project.test.json +7 -0
- data/spec/fixtures/expose_yaml/incompatible_structure.yml +2 -0
- data/spec/fixtures/expose_yaml/project.development.yml +4 -0
- data/spec/fixtures/expose_yaml/project.production.yml +4 -0
- data/spec/fixtures/expose_yaml/project.staging.yml +4 -0
- data/spec/fixtures/expose_yaml/project.test.yml +4 -0
- data/spec/fixtures/expose_yaml/project.yml +25 -0
- data/spec/fixtures/json_array_sample.json +14 -0
- data/spec/fixtures/json_object_sample.json +9 -0
- data/spec/fixtures/json_with_empty_object.json +6 -0
- data/spec/fixtures/json_with_erb.json +6 -0
- data/spec/fixtures/plugins/toml/expose_toml/project.development.toml +4 -0
- data/spec/fixtures/plugins/toml/expose_toml/project.production.toml +4 -0
- data/spec/fixtures/plugins/toml/expose_toml/project.staging.toml +4 -0
- data/spec/fixtures/plugins/toml/expose_toml/project.test.toml +4 -0
- data/spec/fixtures/plugins/toml/expose_toml/project.toml +27 -0
- data/spec/fixtures/plugins/toml/mini_file.toml +6 -0
- data/spec/fixtures/plugins/toml/toml_sample_with_all_types.toml +72 -0
- data/spec/fixtures/plugins/toml/values_file/with_env.toml +13 -0
- data/spec/fixtures/plugins/toml/values_file/without_env.toml +6 -0
- data/spec/fixtures/rubocop_settings.yml +12 -0
- data/spec/fixtures/shared_settings_with_aliases.yml +10 -0
- data/spec/fixtures/travis_settings.yml +6 -0
- data/spec/fixtures/values_file/with_env.json +19 -0
- data/spec/fixtures/values_file/with_env.yml +17 -0
- data/spec/fixtures/values_file/without_env.json +8 -0
- data/spec/fixtures/values_file/without_env.yml +5 -0
- data/spec/fixtures/with_empty_hash.yml +4 -0
- data/spec/fixtures/with_erb_instructions.yml +3 -0
- data/spec/spec_helper.rb +27 -0
- data/spec/support/meta_scopes.rb +20 -0
- data/spec/support/spec_support.rb +42 -0
- metadata +128 -11
@@ -0,0 +1,157 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe 'Save to .json (JSON)' do
|
4
|
+
describe 'saving' do
|
5
|
+
let(:config_file_name) { "#{SecureRandom.uuid}.json" }
|
6
|
+
let(:config_file_path) { SpecSupport.artifact_path(config_file_name) }
|
7
|
+
let(:config_klass) do
|
8
|
+
Class.new(Qonfig::DataSet) do
|
9
|
+
setting :sentry do
|
10
|
+
setting :user, 'D@iVeR'
|
11
|
+
setting :callback, -> { 'loaded' }
|
12
|
+
end
|
13
|
+
|
14
|
+
setting :server_port, 123
|
15
|
+
setting :enabled, true
|
16
|
+
end
|
17
|
+
end
|
18
|
+
let(:config) { config_klass.new }
|
19
|
+
|
20
|
+
specify 'correctly represents config as JSON' do
|
21
|
+
# NOTE: step 1) save config (each config's value can be pre-processed via block)
|
22
|
+
config.save_to_json(path: config_file_path) do |value|
|
23
|
+
value.is_a?(Proc) ? value.call : value
|
24
|
+
end
|
25
|
+
|
26
|
+
# NOTE: step 2) read saved file
|
27
|
+
file_data = File.read(config_file_path)
|
28
|
+
|
29
|
+
expect(file_data).to eq(<<~JSON.strip)
|
30
|
+
{
|
31
|
+
"sentry": {
|
32
|
+
"user": "D@iVeR",
|
33
|
+
"callback": "loaded"
|
34
|
+
},
|
35
|
+
"server_port": 123,
|
36
|
+
"enabled": true
|
37
|
+
}
|
38
|
+
JSON
|
39
|
+
end
|
40
|
+
|
41
|
+
specify 'support for Pathname in file path' do
|
42
|
+
config.save_to_json(path: Pathname.new(config_file_path)) do |value|
|
43
|
+
value.is_a?(Proc) ? value.call : value
|
44
|
+
end
|
45
|
+
|
46
|
+
file_data = File.read(config_file_path)
|
47
|
+
|
48
|
+
expect(file_data).to eq(<<~JSON.strip)
|
49
|
+
{
|
50
|
+
"sentry": {
|
51
|
+
"user": "D@iVeR",
|
52
|
+
"callback": "loaded"
|
53
|
+
},
|
54
|
+
"server_port": 123,
|
55
|
+
"enabled": true
|
56
|
+
}
|
57
|
+
JSON
|
58
|
+
end
|
59
|
+
|
60
|
+
specify 'rewrites existing file' do
|
61
|
+
config_a = Class.new(Qonfig::DataSet) do
|
62
|
+
setting :kek, 'kek'
|
63
|
+
end.new
|
64
|
+
|
65
|
+
config_b = Class.new(Qonfig::DataSet) do
|
66
|
+
setting :pek, 'pek'
|
67
|
+
end.new
|
68
|
+
|
69
|
+
# first save (initial write)
|
70
|
+
config_a.save_to_json(path: config_file_path)
|
71
|
+
file_data = File.read(config_file_path) # NOTE: initial path
|
72
|
+
expect(file_data).to eq(<<~JSON.strip)
|
73
|
+
{
|
74
|
+
"kek": "kek"
|
75
|
+
}
|
76
|
+
JSON
|
77
|
+
|
78
|
+
# subsequent save (rewrite)
|
79
|
+
config_b.save_to_json(path: config_file_path)
|
80
|
+
file_data = File.read(config_file_path) # NOTE: same path
|
81
|
+
expect(file_data).to eq(<<~JSON.strip)
|
82
|
+
{
|
83
|
+
"pek": "pek"
|
84
|
+
}
|
85
|
+
JSON
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe 'data representation' do
|
90
|
+
let(:config_file_name) { "#{SecureRandom.uuid}.json" }
|
91
|
+
let(:config_file_path) { SpecSupport.artifact_path(config_file_name) }
|
92
|
+
let(:config_klass) do
|
93
|
+
Class.new(Qonfig::DataSet) do
|
94
|
+
setting :true_bollean, true
|
95
|
+
setting :false_boolean, false
|
96
|
+
setting :empty_object, {}
|
97
|
+
setting :filled_object, { a: 1, b: nil, 'c' => true, d: '1', e: false }
|
98
|
+
setting :null_data, nil
|
99
|
+
setting :collection, ['1', 2, true, false, nil, [], {}]
|
100
|
+
end
|
101
|
+
end
|
102
|
+
let(:config) { config_klass.new }
|
103
|
+
|
104
|
+
specify 'correctly represents JSON data types' do
|
105
|
+
# NOTE: step 1) save config
|
106
|
+
config.save_to_json(path: config_file_path)
|
107
|
+
|
108
|
+
# NOTE: step 2) read saved file
|
109
|
+
file_data = File.read(config_file_path)
|
110
|
+
|
111
|
+
expect(file_data).to eq(<<~JSON.strip)
|
112
|
+
{
|
113
|
+
"true_bollean": true,
|
114
|
+
"false_boolean": false,
|
115
|
+
"empty_object": {
|
116
|
+
},
|
117
|
+
"filled_object": {
|
118
|
+
"a": 1,
|
119
|
+
"b": null,
|
120
|
+
"c": true,
|
121
|
+
"d": "1",
|
122
|
+
"e": false
|
123
|
+
},
|
124
|
+
"null_data": null,
|
125
|
+
"collection": [ "1", 2, true, false, null, [], {
|
126
|
+
}]
|
127
|
+
}
|
128
|
+
JSON
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
describe 'saving with native JSON settings' do
|
133
|
+
let(:config_file_name) { "#{SecureRandom.uuid}.json" }
|
134
|
+
let(:config_file_path) { SpecSupport.artifact_path(config_file_name) }
|
135
|
+
let(:config_klass) do
|
136
|
+
Class.new(Qonfig::DataSet) do
|
137
|
+
setting :server do
|
138
|
+
setting :address, 'localhost'
|
139
|
+
setting :port, 12_345
|
140
|
+
end
|
141
|
+
|
142
|
+
setting :enabled, true
|
143
|
+
end
|
144
|
+
end
|
145
|
+
let(:config) { config_klass.new }
|
146
|
+
|
147
|
+
specify '(SMOKE TEST) uses native JSON.generate(...) attributes (:options kwarg)' do
|
148
|
+
config = config_klass.new
|
149
|
+
config.save_to_json(path: config_file_path, options: {
|
150
|
+
# NOTE: our options (save json representation in one line without spaces)
|
151
|
+
indent: '', space: '', object_nl: ''
|
152
|
+
})
|
153
|
+
file_data = File.read(config_file_path)
|
154
|
+
expect(file_data).to eq('{"server":{"address":"localhost","port":12345},"enabled":true}')
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
@@ -0,0 +1,189 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe 'Save to .yml (YAML)' do
|
4
|
+
describe 'saving' do
|
5
|
+
let(:config_file_name) { "#{SecureRandom.uuid}.yml" }
|
6
|
+
let(:config_file_path) { SpecSupport.artifact_path(config_file_name) }
|
7
|
+
let(:config_klass) do
|
8
|
+
Class.new(Qonfig::DataSet) do
|
9
|
+
setting :sentry do
|
10
|
+
setting :user, 'D@iVeR'
|
11
|
+
setting :callback, -> { 'loaded' }
|
12
|
+
end
|
13
|
+
|
14
|
+
setting :server_port, 123
|
15
|
+
setting :enabled, true
|
16
|
+
end
|
17
|
+
end
|
18
|
+
let(:config) { config_klass.new }
|
19
|
+
|
20
|
+
context 'with key symbolization' do
|
21
|
+
before do
|
22
|
+
# NOTE: step 1) save config (each config's value can be pre-processed via block)
|
23
|
+
config.save_to_yaml(path: config_file_path, symbolize_keys: true) do |value|
|
24
|
+
value.is_a?(Proc) ? value.call : value
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
specify 'correctly represents config as YAML' do
|
29
|
+
# NOTE: step 2) read saved file
|
30
|
+
file_data = File.read(config_file_path)
|
31
|
+
|
32
|
+
expect(file_data).to eq(<<~YAML.strip << "\n")
|
33
|
+
---
|
34
|
+
:sentry:
|
35
|
+
:user: D@iVeR
|
36
|
+
:callback: loaded
|
37
|
+
:server_port: 123
|
38
|
+
:enabled: true
|
39
|
+
YAML
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'without key symbolization' do
|
44
|
+
before do
|
45
|
+
# NOTE: step 1) save config (each config's value can be pre-processed via block)
|
46
|
+
config.save_to_yaml(path: config_file_path, symbolize_keys: false) do |value|
|
47
|
+
value.is_a?(Proc) ? value.call : value
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
specify 'correctly represents config as YAML' do
|
52
|
+
# NOTE: step 2) read saved file
|
53
|
+
file_data = File.read(config_file_path)
|
54
|
+
|
55
|
+
expect(file_data).to eq(<<~YAML.strip << "\n")
|
56
|
+
---
|
57
|
+
sentry:
|
58
|
+
user: D@iVeR
|
59
|
+
callback: loaded
|
60
|
+
server_port: 123
|
61
|
+
enabled: true
|
62
|
+
YAML
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
specify 'support for Pathname in file path' do
|
67
|
+
config.save_to_yaml(path: Pathname.new(config_file_path), symbolize_keys: false) do |value|
|
68
|
+
value.is_a?(Proc) ? value.call : value
|
69
|
+
end
|
70
|
+
|
71
|
+
file_data = File.read(config_file_path)
|
72
|
+
|
73
|
+
expect(file_data).to eq(<<~YAML.strip << "\n")
|
74
|
+
---
|
75
|
+
sentry:
|
76
|
+
user: D@iVeR
|
77
|
+
callback: loaded
|
78
|
+
server_port: 123
|
79
|
+
enabled: true
|
80
|
+
YAML
|
81
|
+
end
|
82
|
+
|
83
|
+
specify 'rewrites existing file' do
|
84
|
+
config_a = Class.new(Qonfig::DataSet) do
|
85
|
+
setting :kek, 'kek'
|
86
|
+
end.new
|
87
|
+
|
88
|
+
config_b = Class.new(Qonfig::DataSet) do
|
89
|
+
setting :pek, 'pek'
|
90
|
+
end.new
|
91
|
+
|
92
|
+
# first save (initial write)
|
93
|
+
config_a.save_to_yaml(path: config_file_path)
|
94
|
+
file_data = File.read(config_file_path) # NOTE: initial path
|
95
|
+
expect(file_data).to eq(<<~YAML.strip << "\n")
|
96
|
+
---
|
97
|
+
kek: kek
|
98
|
+
YAML
|
99
|
+
|
100
|
+
# subsequent save (rewrite)
|
101
|
+
config_b.save_to_yaml(path: config_file_path)
|
102
|
+
file_data = File.read(config_file_path) # NOTE: same path
|
103
|
+
expect(file_data).to eq(<<~YAML.strip << "\n")
|
104
|
+
---
|
105
|
+
pek: pek
|
106
|
+
YAML
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
describe 'data representation' do
|
111
|
+
let(:config_file_name) { "#{SecureRandom.uuid}.yml" }
|
112
|
+
let(:config_file_path) { SpecSupport.artifact_path(config_file_name) }
|
113
|
+
let(:config_klass) do
|
114
|
+
Class.new(Qonfig::DataSet) do
|
115
|
+
setting :true_bollean, true
|
116
|
+
setting :false_boolean, false
|
117
|
+
setting :empty_object, {}
|
118
|
+
setting :filled_object, { a: 1, b: nil, 'c' => true, d: '1', e: false }
|
119
|
+
setting :null_data, nil
|
120
|
+
setting :collection, ['1', 2, true, false, nil, [], {}]
|
121
|
+
end
|
122
|
+
end
|
123
|
+
let(:config) { config_klass.new }
|
124
|
+
|
125
|
+
specify 'correctly represents YAML data types' do
|
126
|
+
# NOTE: step 1) save config
|
127
|
+
config.save_to_yaml(path: config_file_path)
|
128
|
+
|
129
|
+
# NOTE: step 2) read saved file
|
130
|
+
file_data = File.read(config_file_path)
|
131
|
+
|
132
|
+
expect(file_data).to eq(<<~YAML.strip << "\n")
|
133
|
+
---
|
134
|
+
true_bollean: true
|
135
|
+
false_boolean: false
|
136
|
+
empty_object: {}
|
137
|
+
filled_object:
|
138
|
+
:a: 1
|
139
|
+
:b: ~
|
140
|
+
c: true
|
141
|
+
:d: '1'
|
142
|
+
:e: false
|
143
|
+
null_data: ~
|
144
|
+
collection:
|
145
|
+
- '1'
|
146
|
+
- 2
|
147
|
+
- true
|
148
|
+
- false
|
149
|
+
- ~
|
150
|
+
- []
|
151
|
+
- {}
|
152
|
+
YAML
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
describe 'saving with native YAML settings' do
|
157
|
+
let(:config_file_name) { "#{SecureRandom.uuid}.yml" }
|
158
|
+
let(:config_file_path) { SpecSupport.artifact_path(config_file_name) }
|
159
|
+
let(:config_klass) do
|
160
|
+
Class.new(Qonfig::DataSet) do
|
161
|
+
setting :server do
|
162
|
+
setting :address, 'localhost'
|
163
|
+
setting :port, 12_345
|
164
|
+
end
|
165
|
+
|
166
|
+
setting :enabled, true
|
167
|
+
end
|
168
|
+
end
|
169
|
+
let(:config) { config_klass.new }
|
170
|
+
|
171
|
+
specify '(SMOKE TEST) uses native YAML.dump(...) attributes (:options kwarg)' do
|
172
|
+
config = config_klass.new
|
173
|
+
config.save_to_yaml(path: config_file_path, options: {
|
174
|
+
# NOTE: put current YAML version in start of file (in first line)
|
175
|
+
indentation: 2, header: true
|
176
|
+
})
|
177
|
+
file_data = File.read(config_file_path)
|
178
|
+
|
179
|
+
expect(file_data).to eq(<<~YAML.strip << "\n")
|
180
|
+
%YAML 1.1
|
181
|
+
---
|
182
|
+
server:
|
183
|
+
address: localhost
|
184
|
+
port: 12345
|
185
|
+
enabled: true
|
186
|
+
YAML
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe 'Settings as Predicates' do
|
4
|
+
specify 'boolean nature of the option value' do
|
5
|
+
class BooleanCheckConfig < Qonfig::DataSet
|
6
|
+
setting :database do
|
7
|
+
setting :user
|
8
|
+
setting :host, 'google.com'
|
9
|
+
end
|
10
|
+
|
11
|
+
setting :enable_mocks, true
|
12
|
+
end
|
13
|
+
|
14
|
+
config = BooleanCheckConfig.new
|
15
|
+
|
16
|
+
# predicats
|
17
|
+
expect(config.settings.database.user?).to eq(false)
|
18
|
+
expect(config.settings.database.host?).to eq(true)
|
19
|
+
expect(config.settings.enable_mocks?).to eq(true)
|
20
|
+
# setting roots always returns true
|
21
|
+
expect(config.settings.database?).to eq(true)
|
22
|
+
|
23
|
+
# reconfigure and check again
|
24
|
+
config.configure do |conf|
|
25
|
+
conf.database.user = 'D@iVeR'
|
26
|
+
conf.database.host = nil
|
27
|
+
conf.enable_mocks = false
|
28
|
+
end
|
29
|
+
|
30
|
+
# predicates
|
31
|
+
expect(config.settings.database.user?).to eq(true)
|
32
|
+
expect(config.settings.database.host?).to eq(false)
|
33
|
+
expect(config.settings.enable_mocks?).to eq(false)
|
34
|
+
# setting roots always returns true
|
35
|
+
expect(config.settings.database?).to eq(true)
|
36
|
+
|
37
|
+
# clear all options
|
38
|
+
config.configure do |conf|
|
39
|
+
conf.database.user = nil
|
40
|
+
conf.database.host = nil
|
41
|
+
conf.enable_mocks = nil
|
42
|
+
end
|
43
|
+
|
44
|
+
# setting roots always returns true
|
45
|
+
expect(config.settings.database?).to eq(true)
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe 'Settings redefinition' do
|
4
|
+
specify '.re_setting DSL command redefines previously defined setting keys' do
|
5
|
+
class BaseRedefinableConfig < Qonfig::DataSet
|
6
|
+
setting :nested do
|
7
|
+
setting :some_key, 100_500
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class ChildRedefinitionConfig < BaseRedefinableConfig
|
12
|
+
re_setting :nested, :some_value
|
13
|
+
end
|
14
|
+
|
15
|
+
class AnotherChildRedefinitionConfig < BaseRedefinableConfig
|
16
|
+
re_setting :nested do
|
17
|
+
setting :another_key, 'test'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
redefinable_config = BaseRedefinableConfig.new
|
22
|
+
expect(redefinable_config[:nested][:some_key]).to eq(100_500)
|
23
|
+
|
24
|
+
child_redefinition_config = ChildRedefinitionConfig.new
|
25
|
+
expect(child_redefinition_config[:nested]).to eq(:some_value)
|
26
|
+
|
27
|
+
another_child_redefinition_config = AnotherChildRedefinitionConfig.new
|
28
|
+
expect(another_child_redefinition_config[:nested][:another_key]).to eq('test')
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# rubocop:disable Layout/LineLength
|
4
|
+
describe '(#slice/#slice_value)-functionality' do
|
5
|
+
specify '#slice/#slice_value functionality works as expected :)' do
|
6
|
+
class SlicingConfig < Qonfig::DataSet
|
7
|
+
setting :db do
|
8
|
+
setting :creds do
|
9
|
+
setting :user, 'D@iVeR'
|
10
|
+
setting :data, test: false
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
config = SlicingConfig.new
|
16
|
+
|
17
|
+
db_slice = { 'db' => { 'creds' => { 'user' => 'D@iVeR', 'data' => { test: false } } } }
|
18
|
+
creds_slice = { 'creds' => { 'user' => 'D@iVeR', 'data' => { test: false } } }
|
19
|
+
user_slice = { 'user' => 'D@iVeR' }
|
20
|
+
data_slice = { 'data' => { test: false } }
|
21
|
+
|
22
|
+
# access to the slice (with indifferent keys type)
|
23
|
+
expect(config.slice(:db)).to match(db_slice)
|
24
|
+
expect(config.slice('db', :creds)).to match(creds_slice)
|
25
|
+
expect(config.slice(:db, 'creds', :user)).to match(user_slice)
|
26
|
+
expect(config.slice(:db, :creds, 'data')).to match(data_slice)
|
27
|
+
|
28
|
+
# try to slice with with unexistent keys
|
29
|
+
expect { config.slice(:db, :creds, :megazavr) }.to raise_error(Qonfig::UnknownSettingError)
|
30
|
+
expect { config.slice(:db, :test) }.to raise_error(Qonfig::UnknownSettingError)
|
31
|
+
|
32
|
+
# you cant slice over setting values - you can do it only over the setting keys!
|
33
|
+
expect { config.slice(:db, :creds, :data, :test) }.to raise_error(Qonfig::UnknownSettingError)
|
34
|
+
|
35
|
+
# slice with empty key list
|
36
|
+
# rubocop:disable Lint/RedundantSplatExpansion
|
37
|
+
expect { config.slice(*[]) }.to raise_error(Qonfig::ArgumentError)
|
38
|
+
expect { config.slice }.to raise_error(Qonfig::ArgumentError)
|
39
|
+
# rubocop:enable Lint/RedundantSplatExpansion
|
40
|
+
|
41
|
+
# slice over unexistent option
|
42
|
+
expect { config.slice(:db, :creds, :session) }.to raise_error(Qonfig::UnknownSettingError)
|
43
|
+
expect { config.slice(:a, :b, :c, :d) }.to raise_error(Qonfig::UnknownSettingError)
|
44
|
+
|
45
|
+
# access to the sliced value (with indifferent keys type)
|
46
|
+
expect(config.slice_value(:db)).to match(db_slice['db'])
|
47
|
+
expect(config.slice_value('db', :creds)).to match(creds_slice['creds'])
|
48
|
+
expect(config.slice_value(:db, 'creds', :user)).to eq(user_slice['user'])
|
49
|
+
expect(config.slice_value(:db, :creds, 'data')).to match(data_slice['data'])
|
50
|
+
|
51
|
+
# try to slice value over with unexistent keys
|
52
|
+
expect { config.slice_value(:db, :creds, :megazavr) }.to raise_error(Qonfig::UnknownSettingError)
|
53
|
+
expect { config.slice_value(:db, :test) }.to raise_error(Qonfig::UnknownSettingError)
|
54
|
+
|
55
|
+
# you cant slice over setting values - you can do it only over the setting keys!
|
56
|
+
expect { config.slice_value(:db, :creds, :data, :test) }.to raise_error(Qonfig::UnknownSettingError)
|
57
|
+
|
58
|
+
# slice with empty key list
|
59
|
+
# rubocop:disable Lint/RedundantSplatExpansion
|
60
|
+
expect { config.slice_value(*[]) }.to raise_error(Qonfig::ArgumentError)
|
61
|
+
expect { config.slice_value }.to raise_error(Qonfig::ArgumentError)
|
62
|
+
# rubocop:enable Lint/RedundantSplatExpansion
|
63
|
+
|
64
|
+
# slice over unexistent option
|
65
|
+
expect { config.slice_value(:db, :creds, :session) }.to raise_error(Qonfig::UnknownSettingError)
|
66
|
+
expect { config.slice_value(:a, :b, :c, :d) }.to raise_error(Qonfig::UnknownSettingError)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
# rubocop:enable Layout/LineLength
|