qonfig 0.24.0 → 0.27.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +62 -0
- data/.gitignore +0 -2
- data/.rubocop.yml +19 -1
- data/CHANGELOG.md +53 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +129 -0
- data/LICENSE.txt +1 -1
- data/README.md +115 -5
- data/Rakefile +0 -1
- data/gemfiles/with_external_deps.gemfile +2 -0
- data/gemfiles/with_external_deps.gemfile.lock +123 -0
- data/gemfiles/without_external_deps.gemfile.lock +113 -0
- data/lib/qonfig/commands/definition/load_from_env/value_converter.rb +2 -0
- data/lib/qonfig/commands/definition/load_from_env.rb +2 -0
- data/lib/qonfig/data_set.rb +3 -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/loaders/yaml.rb +3 -1
- data/lib/qonfig/plugins/pretty_print/requirements.rb +3 -0
- data/lib/qonfig/plugins/pretty_print.rb +1 -0
- data/lib/qonfig/plugins/toml/commands/definition/expose_toml.rb +3 -3
- data/lib/qonfig/plugins/vault/commands/definition/expose_vault.rb +142 -0
- data/lib/qonfig/plugins/vault/commands/definition/load_from_vault.rb +53 -0
- data/lib/qonfig/plugins/vault/dsl.rb +35 -0
- data/lib/qonfig/plugins/vault/errors.rb +9 -0
- data/lib/qonfig/plugins/vault/loaders/vault.rb +74 -0
- data/lib/qonfig/plugins/vault.rb +24 -0
- data/lib/qonfig/plugins.rb +1 -0
- data/lib/qonfig/settings/key_matcher.rb +3 -1
- data/lib/qonfig/settings.rb +83 -22
- data/lib/qonfig/uploaders/base.rb +2 -0
- data/lib/qonfig/uploaders/yaml.rb +2 -0
- data/lib/qonfig/version.rb +1 -1
- data/lib/qonfig.rb +4 -1
- data/qonfig.gemspec +9 -8
- data/sig/.keep +0 -0
- data/spec/artifacts/.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 +919 -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 +46 -0
- data/spec/support/meta_scopes.rb +20 -0
- data/spec/support/spec_support.rb +42 -0
- metadata +181 -15
- data/.travis.yml +0 -47
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe 'Iteration over setting keys (#each_setting / #deep_each_setting)' do
|
4
|
+
let(:config) do
|
5
|
+
Class.new(Qonfig::DataSet) do
|
6
|
+
setting :db do
|
7
|
+
setting :creds do
|
8
|
+
setting :user, 'D@iVeR'
|
9
|
+
setting :password, 'test123'
|
10
|
+
setting :data, test: false
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
setting :telegraf_url, 'udp://localhost:8094'
|
15
|
+
setting :telegraf_prefix, 'test'
|
16
|
+
end.new
|
17
|
+
end
|
18
|
+
|
19
|
+
specify '#each_setting provides ("key" => value) format' do
|
20
|
+
key_value_pairs = {}.tap do |pairs|
|
21
|
+
config.each_setting do |setting_key, setting_value|
|
22
|
+
pairs[setting_key] = setting_value
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
expect(key_value_pairs).to match(
|
27
|
+
'db' => config.settings.db,
|
28
|
+
'telegraf_url' => 'udp://localhost:8094',
|
29
|
+
'telegraf_prefix' => 'test'
|
30
|
+
)
|
31
|
+
end
|
32
|
+
|
33
|
+
specify '#deep_each_setting provides ("key.sub_key.subkey" => value) format' do
|
34
|
+
key_value_pairs = {}.tap do |pairs|
|
35
|
+
config.deep_each_setting do |setting_key, setting_value|
|
36
|
+
pairs[setting_key] = setting_value
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
expect(key_value_pairs).to match(
|
41
|
+
'db.creds.user' => 'D@iVeR',
|
42
|
+
'db.creds.password' => 'test123',
|
43
|
+
'db.creds.data' => { test: false },
|
44
|
+
'telegraf_url' => 'udp://localhost:8094',
|
45
|
+
'telegraf_prefix' => 'test'
|
46
|
+
)
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,240 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe 'Load from ENV' do
|
4
|
+
specify 'defines config object by ENV data' do
|
5
|
+
ENV['QONFIG_SPEC_TRUE_VALUE_V1'] = 'true'
|
6
|
+
ENV['QONFIG_SPEC_TRUE_VALUE_V2'] = 't'
|
7
|
+
ENV['QONFIG_SPEC_TRUE_VALUE_V3'] = 'TRUE'
|
8
|
+
ENV['QONFIG_SPEC_TRUE_VALUE_V4'] = 'T'
|
9
|
+
|
10
|
+
ENV['QONFIG_SPEC_FALSE_VALUE_V1'] = 'false'
|
11
|
+
ENV['QONFIG_SPEC_FALSE_VALUE_V2'] = 'f'
|
12
|
+
ENV['QONFIG_SPEC_FALSE_VALUE_V3'] = 'FALSE'
|
13
|
+
ENV['QONFIG_SPEC_FALSE_VALUE_V4'] = 'F'
|
14
|
+
|
15
|
+
ENV['QONFIG_SPEC_INTEGER_VALUE'] = '1'
|
16
|
+
ENV['QONFIG_SPEC_FLOAT_VALUE'] = '1.55'
|
17
|
+
|
18
|
+
ENV['QONFIG_SPEC_ARRAY_VALUE_V1'] = 'true, t, TRUE ,T , false,f,FALSE,f'
|
19
|
+
ENV['QONFIG_SPEC_ARRAY_VALUE_V2'] = '1, 2, 3.4, 5.6 ,0.0'
|
20
|
+
ENV['QONFIG_SPEC_ARRAY_VALUE_V3'] = 'Qonfig,Settings,DSL'
|
21
|
+
|
22
|
+
ENV['QONFIG_SPEC_QUOTED_STRING_VALUE_V1'] = '"test, please"'
|
23
|
+
ENV['QONFIG_SPEC_QUOTED_STRING_VALUE_V2'] = "'please, test'"
|
24
|
+
|
25
|
+
ENV['QONFIG_SPEC_GENERIC_VALUE_V1'] = '1,66'
|
26
|
+
ENV['QONFIG_SPEC_GENERIC_VALUE_V2'] = '123.456trueTRUEfalseFALSEtTfF.123'
|
27
|
+
|
28
|
+
ENV['NON_QONFIG_SPEC_GENERIC_VALUE'] = 'test'
|
29
|
+
|
30
|
+
class EnvConfig < Qonfig::DataSet
|
31
|
+
setting :default do
|
32
|
+
load_from_env
|
33
|
+
end
|
34
|
+
|
35
|
+
setting :converted do
|
36
|
+
load_from_env convert_values: true
|
37
|
+
end
|
38
|
+
|
39
|
+
setting :prefixed do
|
40
|
+
load_from_env prefix: 'QONFIG_SPEC'
|
41
|
+
end
|
42
|
+
|
43
|
+
setting :prefix_regexp do
|
44
|
+
load_from_env prefix: /\Aqonfig.*\z/i
|
45
|
+
end
|
46
|
+
|
47
|
+
setting :trimmed_prefix do
|
48
|
+
load_from_env prefix: 'QONFIG_SPEC_', trim_prefix: true
|
49
|
+
end
|
50
|
+
|
51
|
+
setting :all_in do
|
52
|
+
load_from_env convert_values: true, prefix: 'QONFIG_SPEC_', trim_prefix: true
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
config = EnvConfig.new
|
57
|
+
|
58
|
+
# rubocop:disable Layout/LineLength, Naming/VariableNumber
|
59
|
+
expect(config[:default][:QONFIG_SPEC_TRUE_VALUE_V1]).to eq('true')
|
60
|
+
expect(config[:default][:QONFIG_SPEC_TRUE_VALUE_V2]).to eq('t')
|
61
|
+
expect(config[:default][:QONFIG_SPEC_TRUE_VALUE_V3]).to eq('TRUE')
|
62
|
+
expect(config[:default][:QONFIG_SPEC_TRUE_VALUE_V4]).to eq('T')
|
63
|
+
expect(config[:default][:QONFIG_SPEC_FALSE_VALUE_V1]).to eq('false')
|
64
|
+
expect(config[:default][:QONFIG_SPEC_FALSE_VALUE_V2]).to eq('f')
|
65
|
+
expect(config[:default][:QONFIG_SPEC_FALSE_VALUE_V3]).to eq('FALSE')
|
66
|
+
expect(config[:default][:QONFIG_SPEC_FALSE_VALUE_V4]).to eq('F')
|
67
|
+
expect(config[:default][:QONFIG_SPEC_INTEGER_VALUE]).to eq('1')
|
68
|
+
expect(config[:default][:QONFIG_SPEC_FLOAT_VALUE]).to eq('1.55')
|
69
|
+
expect(config[:default][:QONFIG_SPEC_GENERIC_VALUE_V1]).to eq('1,66')
|
70
|
+
expect(config[:default][:QONFIG_SPEC_GENERIC_VALUE_V2]).to eq('123.456trueTRUEfalseFALSEtTfF.123')
|
71
|
+
expect(config[:default][:QONFIG_SPEC_ARRAY_VALUE_V1]).to eq('true, t, TRUE ,T , false,f,FALSE,f')
|
72
|
+
expect(config[:default][:QONFIG_SPEC_ARRAY_VALUE_V2]).to eq('1, 2, 3.4, 5.6 ,0.0')
|
73
|
+
expect(config[:default][:QONFIG_SPEC_ARRAY_VALUE_V3]).to eq('Qonfig,Settings,DSL')
|
74
|
+
expect(config[:default][:QONFIG_SPEC_QUOTED_STRING_VALUE_V1]).to eq('"test, please"')
|
75
|
+
expect(config[:default][:QONFIG_SPEC_QUOTED_STRING_VALUE_V2]).to eq("'please, test'")
|
76
|
+
expect(config[:default][:NON_QONFIG_SPEC_GENERIC_VALUE]).to eq('test')
|
77
|
+
|
78
|
+
expect(config[:converted][:QONFIG_SPEC_TRUE_VALUE_V1]).to eq(true)
|
79
|
+
expect(config[:converted][:QONFIG_SPEC_TRUE_VALUE_V2]).to eq(true)
|
80
|
+
expect(config[:converted][:QONFIG_SPEC_TRUE_VALUE_V3]).to eq(true)
|
81
|
+
expect(config[:converted][:QONFIG_SPEC_TRUE_VALUE_V4]).to eq(true)
|
82
|
+
expect(config[:converted][:QONFIG_SPEC_FALSE_VALUE_V1]).to eq(false)
|
83
|
+
expect(config[:converted][:QONFIG_SPEC_FALSE_VALUE_V2]).to eq(false)
|
84
|
+
expect(config[:converted][:QONFIG_SPEC_FALSE_VALUE_V3]).to eq(false)
|
85
|
+
expect(config[:converted][:QONFIG_SPEC_FALSE_VALUE_V4]).to eq(false)
|
86
|
+
expect(config[:converted][:QONFIG_SPEC_INTEGER_VALUE]).to eq(1)
|
87
|
+
expect(config[:converted][:QONFIG_SPEC_FLOAT_VALUE]).to eq(1.55)
|
88
|
+
expect(config[:converted][:QONFIG_SPEC_GENERIC_VALUE_V1]).to eq([1, 66])
|
89
|
+
expect(config[:converted][:QONFIG_SPEC_GENERIC_VALUE_V2]).to eq('123.456trueTRUEfalseFALSEtTfF.123')
|
90
|
+
expect(config[:converted][:QONFIG_SPEC_ARRAY_VALUE_V1]).to eq([true, true, true, true, false, false, false, false])
|
91
|
+
expect(config[:converted][:QONFIG_SPEC_ARRAY_VALUE_V2]).to eq([1, 2, 3.4, 5.6, 0.0])
|
92
|
+
expect(config[:converted][:QONFIG_SPEC_ARRAY_VALUE_V3]).to eq(%w[Qonfig Settings DSL])
|
93
|
+
expect(config[:converted][:QONFIG_SPEC_QUOTED_STRING_VALUE_V1]).to eq('test, please')
|
94
|
+
expect(config[:converted][:QONFIG_SPEC_QUOTED_STRING_VALUE_V2]).to eq('please, test')
|
95
|
+
expect(config[:converted][:NON_QONFIG_SPEC_GENERIC_VALUE]).to eq('test')
|
96
|
+
|
97
|
+
expect(config[:prefixed][:QONFIG_SPEC_TRUE_VALUE_V1]).to eq('true')
|
98
|
+
expect(config[:prefixed][:QONFIG_SPEC_TRUE_VALUE_V2]).to eq('t')
|
99
|
+
expect(config[:prefixed][:QONFIG_SPEC_TRUE_VALUE_V3]).to eq('TRUE')
|
100
|
+
expect(config[:prefixed][:QONFIG_SPEC_TRUE_VALUE_V4]).to eq('T')
|
101
|
+
expect(config[:prefixed][:QONFIG_SPEC_FALSE_VALUE_V1]).to eq('false')
|
102
|
+
expect(config[:prefixed][:QONFIG_SPEC_FALSE_VALUE_V2]).to eq('f')
|
103
|
+
expect(config[:prefixed][:QONFIG_SPEC_FALSE_VALUE_V3]).to eq('FALSE')
|
104
|
+
expect(config[:prefixed][:QONFIG_SPEC_FALSE_VALUE_V4]).to eq('F')
|
105
|
+
expect(config[:prefixed][:QONFIG_SPEC_INTEGER_VALUE]).to eq('1')
|
106
|
+
expect(config[:prefixed][:QONFIG_SPEC_FLOAT_VALUE]).to eq('1.55')
|
107
|
+
expect(config[:prefixed][:QONFIG_SPEC_GENERIC_VALUE_V1]).to eq('1,66')
|
108
|
+
expect(config[:prefixed][:QONFIG_SPEC_GENERIC_VALUE_V2]).to eq('123.456trueTRUEfalseFALSEtTfF.123')
|
109
|
+
expect(config[:prefixed][:QONFIG_SPEC_ARRAY_VALUE_V1]).to eq('true, t, TRUE ,T , false,f,FALSE,f')
|
110
|
+
expect(config[:prefixed][:QONFIG_SPEC_ARRAY_VALUE_V2]).to eq('1, 2, 3.4, 5.6 ,0.0')
|
111
|
+
expect(config[:prefixed][:QONFIG_SPEC_ARRAY_VALUE_V3]).to eq('Qonfig,Settings,DSL')
|
112
|
+
expect(config[:prefixed][:QONFIG_SPEC_QUOTED_STRING_VALUE_V1]).to eq('"test, please"')
|
113
|
+
expect(config[:prefixed][:QONFIG_SPEC_QUOTED_STRING_VALUE_V2]).to eq("'please, test'")
|
114
|
+
expect { config[:prefixed][:NON_QONFIG_SPEC_GENERIC_VALUE] }.to raise_error(Qonfig::UnknownSettingError)
|
115
|
+
|
116
|
+
expect(config[:prefix_regexp][:QONFIG_SPEC_TRUE_VALUE_V1]).to eq('true')
|
117
|
+
expect(config[:prefix_regexp][:QONFIG_SPEC_TRUE_VALUE_V2]).to eq('t')
|
118
|
+
expect(config[:prefix_regexp][:QONFIG_SPEC_TRUE_VALUE_V3]).to eq('TRUE')
|
119
|
+
expect(config[:prefix_regexp][:QONFIG_SPEC_TRUE_VALUE_V4]).to eq('T')
|
120
|
+
expect(config[:prefix_regexp][:QONFIG_SPEC_FALSE_VALUE_V1]).to eq('false')
|
121
|
+
expect(config[:prefix_regexp][:QONFIG_SPEC_FALSE_VALUE_V2]).to eq('f')
|
122
|
+
expect(config[:prefix_regexp][:QONFIG_SPEC_FALSE_VALUE_V3]).to eq('FALSE')
|
123
|
+
expect(config[:prefix_regexp][:QONFIG_SPEC_FALSE_VALUE_V4]).to eq('F')
|
124
|
+
expect(config[:prefix_regexp][:QONFIG_SPEC_INTEGER_VALUE]).to eq('1')
|
125
|
+
expect(config[:prefix_regexp][:QONFIG_SPEC_FLOAT_VALUE]).to eq('1.55')
|
126
|
+
expect(config[:prefix_regexp][:QONFIG_SPEC_GENERIC_VALUE_V1]).to eq('1,66')
|
127
|
+
expect(config[:prefix_regexp][:QONFIG_SPEC_GENERIC_VALUE_V2]).to eq('123.456trueTRUEfalseFALSEtTfF.123')
|
128
|
+
expect(config[:prefix_regexp][:QONFIG_SPEC_ARRAY_VALUE_V1]).to eq('true, t, TRUE ,T , false,f,FALSE,f')
|
129
|
+
expect(config[:prefix_regexp][:QONFIG_SPEC_ARRAY_VALUE_V2]).to eq('1, 2, 3.4, 5.6 ,0.0')
|
130
|
+
expect(config[:prefix_regexp][:QONFIG_SPEC_ARRAY_VALUE_V3]).to eq('Qonfig,Settings,DSL')
|
131
|
+
expect(config[:prefix_regexp][:QONFIG_SPEC_QUOTED_STRING_VALUE_V1]).to eq('"test, please"')
|
132
|
+
expect(config[:prefix_regexp][:QONFIG_SPEC_QUOTED_STRING_VALUE_V2]).to eq("'please, test'")
|
133
|
+
expect { config[:prefix_regexp][:NON_QONFIG_SPEC_GENERIC_VALUE] }.to raise_error(Qonfig::UnknownSettingError)
|
134
|
+
|
135
|
+
expect(config[:trimmed_prefix][:TRUE_VALUE_V1]).to eq('true')
|
136
|
+
expect(config[:trimmed_prefix][:TRUE_VALUE_V2]).to eq('t')
|
137
|
+
expect(config[:trimmed_prefix][:TRUE_VALUE_V3]).to eq('TRUE')
|
138
|
+
expect(config[:trimmed_prefix][:TRUE_VALUE_V4]).to eq('T')
|
139
|
+
expect(config[:trimmed_prefix][:FALSE_VALUE_V1]).to eq('false')
|
140
|
+
expect(config[:trimmed_prefix][:FALSE_VALUE_V2]).to eq('f')
|
141
|
+
expect(config[:trimmed_prefix][:FALSE_VALUE_V3]).to eq('FALSE')
|
142
|
+
expect(config[:trimmed_prefix][:FALSE_VALUE_V4]).to eq('F')
|
143
|
+
expect(config[:trimmed_prefix][:INTEGER_VALUE]).to eq('1')
|
144
|
+
expect(config[:trimmed_prefix][:FLOAT_VALUE]).to eq('1.55')
|
145
|
+
expect(config[:trimmed_prefix][:GENERIC_VALUE_V1]).to eq('1,66')
|
146
|
+
expect(config[:trimmed_prefix][:GENERIC_VALUE_V2]).to eq('123.456trueTRUEfalseFALSEtTfF.123')
|
147
|
+
expect(config[:trimmed_prefix][:ARRAY_VALUE_V1]).to eq('true, t, TRUE ,T , false,f,FALSE,f')
|
148
|
+
expect(config[:trimmed_prefix][:ARRAY_VALUE_V2]).to eq('1, 2, 3.4, 5.6 ,0.0')
|
149
|
+
expect(config[:trimmed_prefix][:ARRAY_VALUE_V3]).to eq('Qonfig,Settings,DSL')
|
150
|
+
expect(config[:trimmed_prefix][:QUOTED_STRING_VALUE_V1]).to eq('"test, please"')
|
151
|
+
expect(config[:trimmed_prefix][:QUOTED_STRING_VALUE_V2]).to eq("'please, test'")
|
152
|
+
expect { config[:trimmed_prefix][:NON_QONFIG_SPEC_GENERIC_VALUE] }.to raise_error(Qonfig::UnknownSettingError)
|
153
|
+
|
154
|
+
expect(config[:all_in][:TRUE_VALUE_V1]).to eq(true)
|
155
|
+
expect(config[:all_in][:TRUE_VALUE_V2]).to eq(true)
|
156
|
+
expect(config[:all_in][:TRUE_VALUE_V3]).to eq(true)
|
157
|
+
expect(config[:all_in][:TRUE_VALUE_V4]).to eq(true)
|
158
|
+
expect(config[:all_in][:FALSE_VALUE_V1]).to eq(false)
|
159
|
+
expect(config[:all_in][:FALSE_VALUE_V2]).to eq(false)
|
160
|
+
expect(config[:all_in][:FALSE_VALUE_V3]).to eq(false)
|
161
|
+
expect(config[:all_in][:FALSE_VALUE_V4]).to eq(false)
|
162
|
+
expect(config[:all_in][:INTEGER_VALUE]).to eq(1)
|
163
|
+
expect(config[:all_in][:FLOAT_VALUE]).to eq(1.55)
|
164
|
+
expect(config[:all_in][:GENERIC_VALUE_V1]).to eq([1, 66])
|
165
|
+
expect(config[:all_in][:GENERIC_VALUE_V2]).to eq('123.456trueTRUEfalseFALSEtTfF.123')
|
166
|
+
expect(config[:all_in][:ARRAY_VALUE_V1]).to eq([true, true, true, true, false, false, false, false])
|
167
|
+
expect(config[:all_in][:ARRAY_VALUE_V2]).to eq([1, 2, 3.4, 5.6, 0.0])
|
168
|
+
expect(config[:all_in][:ARRAY_VALUE_V3]).to eq(%w[Qonfig Settings DSL])
|
169
|
+
expect(config[:all_in][:QUOTED_STRING_VALUE_V1]).to eq('test, please')
|
170
|
+
expect(config[:all_in][:QUOTED_STRING_VALUE_V2]).to eq('please, test')
|
171
|
+
expect { config[:all_in][:NON_QONFIG_SPEC_GENERIC_VALUE] }.to raise_error(Qonfig::UnknownSettingError)
|
172
|
+
# rubocop:enable Layout/LineLength, Naming/VariableNumber
|
173
|
+
end
|
174
|
+
|
175
|
+
specify 'incorrect definition' do
|
176
|
+
incorrect_convert_value_option_values = [
|
177
|
+
123, '123', 'true', 't', 'false', 'f', Object.new, 123.5, Class.new
|
178
|
+
]
|
179
|
+
|
180
|
+
incorrect_prefix_option_values = [
|
181
|
+
123, Object.new, 123.5, true, false, Class.new
|
182
|
+
]
|
183
|
+
|
184
|
+
incorrect_trim_prefix_option_values = [
|
185
|
+
123, '123', 'true', 't', 'false', 'f', Object.new, 123.5, Class.new
|
186
|
+
]
|
187
|
+
|
188
|
+
correct_convert_value_option_values = [true, false]
|
189
|
+
correct_prefix_option_values = [nil, 'qonfig', /\Aqonfig.*\z/i]
|
190
|
+
correct_trim_prefix_option_values = [true, false]
|
191
|
+
|
192
|
+
incorrect_convert_value_option_values.each do |incorrect_option|
|
193
|
+
expect do
|
194
|
+
Class.new(Qonfig::DataSet) do
|
195
|
+
load_from_env convert_values: incorrect_option
|
196
|
+
end
|
197
|
+
end.to raise_error(Qonfig::ArgumentError)
|
198
|
+
end
|
199
|
+
|
200
|
+
incorrect_prefix_option_values.each do |incorrect_option|
|
201
|
+
expect do
|
202
|
+
Class.new(Qonfig::DataSet) do
|
203
|
+
load_from_env prefix: incorrect_option
|
204
|
+
end
|
205
|
+
end.to raise_error(Qonfig::ArgumentError)
|
206
|
+
end
|
207
|
+
|
208
|
+
incorrect_trim_prefix_option_values.each do |incorrect_option|
|
209
|
+
expect do
|
210
|
+
Class.new(Qonfig::DataSet) do
|
211
|
+
load_from_env trim_prefix: incorrect_option
|
212
|
+
end
|
213
|
+
end.to raise_error(Qonfig::ArgumentError)
|
214
|
+
end
|
215
|
+
|
216
|
+
correct_convert_value_option_values.each do |correct_option|
|
217
|
+
expect do
|
218
|
+
Class.new(Qonfig::DataSet) do
|
219
|
+
load_from_env convert_values: correct_option
|
220
|
+
end
|
221
|
+
end.not_to raise_error
|
222
|
+
end
|
223
|
+
|
224
|
+
correct_prefix_option_values.each do |correct_option|
|
225
|
+
expect do
|
226
|
+
Class.new(Qonfig::DataSet) do
|
227
|
+
load_from_env prefix: correct_option
|
228
|
+
end
|
229
|
+
end.not_to raise_error
|
230
|
+
end
|
231
|
+
|
232
|
+
correct_trim_prefix_option_values.each do |correct_option|
|
233
|
+
expect do
|
234
|
+
Class.new(Qonfig::DataSet) do
|
235
|
+
load_from_env trim_prefix: correct_option
|
236
|
+
end
|
237
|
+
end.not_to raise_error
|
238
|
+
end
|
239
|
+
end
|
240
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe 'Load from JSON' do
|
4
|
+
specify 'defines config object by json instructions' do
|
5
|
+
class JSONBasedConfig < Qonfig::DataSet
|
6
|
+
load_from_json SpecSupport.fixture_path('json_object_sample.json')
|
7
|
+
|
8
|
+
setting :nested do
|
9
|
+
load_from_json SpecSupport.fixture_path('json_object_sample.json')
|
10
|
+
end
|
11
|
+
|
12
|
+
setting :with_empty_objects do
|
13
|
+
load_from_json SpecSupport.fixture_path('json_with_empty_object.json')
|
14
|
+
end
|
15
|
+
|
16
|
+
setting :with_erb do
|
17
|
+
load_from_json SpecSupport.fixture_path('json_with_erb.json')
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
JSONBasedConfig.new.settings.tap do |conf|
|
22
|
+
expect(conf.user).to eq('D@iVeR')
|
23
|
+
expect(conf.maxAuthCount).to eq(55)
|
24
|
+
expect(conf.rubySettings.allowedVersions).to eq(['2.3', '2.4.2', '1.9.8'])
|
25
|
+
expect(conf.rubySettings.gitLink).to eq(nil)
|
26
|
+
expect(conf.rubySettings.withAdditionals).to eq(false)
|
27
|
+
|
28
|
+
expect(conf.nested.user).to eq('D@iVeR')
|
29
|
+
expect(conf.nested.maxAuthCount).to eq(55)
|
30
|
+
expect(conf.nested.rubySettings.allowedVersions).to eq(['2.3', '2.4.2', '1.9.8'])
|
31
|
+
expect(conf.nested.rubySettings.gitLink).to eq(nil)
|
32
|
+
expect(conf.nested.rubySettings.withAdditionals).to eq(false)
|
33
|
+
|
34
|
+
expect(conf.with_empty_objects.requirements).to eq({})
|
35
|
+
expect(conf.with_empty_objects.credentials.excluded).to eq({})
|
36
|
+
|
37
|
+
expect(conf.with_erb.count).to eq(10_000)
|
38
|
+
expect(conf.with_erb.credentials.excluded).to eq('some string here')
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
specify 'fails when json object has non-hash-like structure' do
|
43
|
+
class IncompatibleJSONConfig < Qonfig::DataSet
|
44
|
+
load_from_json SpecSupport.fixture_path('json_array_sample.json')
|
45
|
+
end
|
46
|
+
|
47
|
+
expect { IncompatibleJSONConfig.new }.to raise_error(Qonfig::IncompatibleJSONStructureError)
|
48
|
+
end
|
49
|
+
|
50
|
+
specify 'support for Pathname in file path' do
|
51
|
+
class PathanmeJSONLoadCheckConfig < Qonfig::DataSet
|
52
|
+
load_from_json Pathname.new(SpecSupport.fixture_path('json_object_sample.json'))
|
53
|
+
end
|
54
|
+
|
55
|
+
config = PathanmeJSONLoadCheckConfig.new
|
56
|
+
|
57
|
+
expect(config.settings.user).to eq('D@iVeR')
|
58
|
+
expect(config.settings.maxAuthCount).to eq(55)
|
59
|
+
expect(config.settings.rubySettings.allowedVersions).to eq(['2.3', '2.4.2', '1.9.8'])
|
60
|
+
expect(config.settings.rubySettings.gitLink).to eq(nil)
|
61
|
+
expect(config.settings.rubySettings.withAdditionals).to eq(false)
|
62
|
+
end
|
63
|
+
|
64
|
+
describe ':strict mode option (when file doesnt exist)' do
|
65
|
+
context 'when :strict => true (by default)' do
|
66
|
+
specify 'fails with corresponding error' do
|
67
|
+
# check default behaviour (strict: true)
|
68
|
+
class FailingJSONConfig < Qonfig::DataSet
|
69
|
+
load_from_json 'no_file.json'
|
70
|
+
end
|
71
|
+
|
72
|
+
expect { FailingJSONConfig.new }.to raise_error(Qonfig::FileNotFoundError)
|
73
|
+
|
74
|
+
class ExplicitlyStrictedJSONCOnfig < Qonfig::DataSet
|
75
|
+
load_from_json 'no_file.json', strict: true
|
76
|
+
end
|
77
|
+
|
78
|
+
expect { ExplicitlyStrictedJSONCOnfig.new }.to raise_error(Qonfig::FileNotFoundError)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context 'when :strict => false' do
|
83
|
+
specify 'does not fail - empty config' do
|
84
|
+
class NonFailingJSONConfig < Qonfig::DataSet
|
85
|
+
load_from_json 'no_file.json', strict: false
|
86
|
+
|
87
|
+
setting :nested do
|
88
|
+
load_from_json 'no_file.json', strict: false
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
expect { NonFailingJSONConfig.new }.not_to raise_error
|
93
|
+
expect(NonFailingJSONConfig.new.to_h).to eq('nested' => {})
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe '#load_from_self => format: :json' do
|
4
|
+
specify ':json-format support' do
|
5
|
+
class JsonEndDataConfig < Qonfig::DataSet
|
6
|
+
load_from_self format: :json
|
7
|
+
end
|
8
|
+
|
9
|
+
config = JsonEndDataConfig.new
|
10
|
+
|
11
|
+
expect(config.settings.credentials.user).to eq('admin')
|
12
|
+
expect(config.settings.credentials.password).to eq('123')
|
13
|
+
expect(config.settings.credentials.enabled).to eq(true)
|
14
|
+
expect(config.settings.amount).to eq(123.456)
|
15
|
+
expect(config.settings.data).to eq(nil)
|
16
|
+
expect(config.settings.methods).to eq([1, 'test', nil, true, false, ['data']])
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
__END__
|
21
|
+
|
22
|
+
{
|
23
|
+
"credentials": {
|
24
|
+
"user": "admin",
|
25
|
+
"password": "123",
|
26
|
+
"enabled": true
|
27
|
+
},
|
28
|
+
"amount": 123.456,
|
29
|
+
"data": null,
|
30
|
+
"methods": [1, "test", null, true, false, ["data"]]
|
31
|
+
}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe '#load_from_self => format: <unsupported>' do
|
4
|
+
specify 'fails on unsupported formats' do
|
5
|
+
expect do
|
6
|
+
Class.new(Qonfig::DataSet) do
|
7
|
+
load_from_self format: :atata
|
8
|
+
end
|
9
|
+
end.to raise_error(Qonfig::UnsupportedLoaderFormatError)
|
10
|
+
end
|
11
|
+
|
12
|
+
specify 'fails on empty format parameter' do
|
13
|
+
expect do
|
14
|
+
Class.new(Qonfig::DataSet) do
|
15
|
+
load_from_self format: ''
|
16
|
+
end
|
17
|
+
end.to raise_error(Qonfig::UnsupportedLoaderFormatError)
|
18
|
+
end
|
19
|
+
|
20
|
+
specify 'fails on incorrect format parameter' do
|
21
|
+
expect do
|
22
|
+
Class.new(Qonfig::DataSet) do
|
23
|
+
load_from_self format: Object.new
|
24
|
+
end
|
25
|
+
end.to raise_error(Qonfig::ArgumentError)
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe '#load_from_self => format: :yaml' do
|
4
|
+
specify ':yaml/:yml-format support' do
|
5
|
+
class YamlEndDataConfig < Qonfig::DataSet
|
6
|
+
setting :by_yml do
|
7
|
+
load_from_self format: :yml # the same as :yaml
|
8
|
+
end
|
9
|
+
|
10
|
+
setting :by_yaml do
|
11
|
+
load_from_self format: :yaml # the same as :yml
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
config = YamlEndDataConfig.new
|
16
|
+
|
17
|
+
# NOTE: format: :yml
|
18
|
+
expect(config.settings.by_yml.credentials.user).to eq('admin')
|
19
|
+
expect(config.settings.by_yml.credentials.password).to eq('123')
|
20
|
+
expect(config.settings.by_yml.credentials.enabled).to eq(true)
|
21
|
+
expect(config.settings.by_yml.amount).to eq(123.456)
|
22
|
+
expect(config.settings.by_yml.data).to eq(nil)
|
23
|
+
expect(config.settings.by_yml.methods).to eq([1, 'test', nil, true, false, ['data']])
|
24
|
+
|
25
|
+
# NOTE: format: :yaml
|
26
|
+
expect(config.settings.by_yaml.credentials.user).to eq('admin')
|
27
|
+
expect(config.settings.by_yaml.credentials.password).to eq('123')
|
28
|
+
expect(config.settings.by_yaml.credentials.enabled).to eq(true)
|
29
|
+
expect(config.settings.by_yaml.amount).to eq(123.456)
|
30
|
+
expect(config.settings.by_yaml.data).to eq(nil)
|
31
|
+
expect(config.settings.by_yaml.methods).to eq([1, 'test', nil, true, false, ['data']])
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
__END__
|
36
|
+
|
37
|
+
credentials:
|
38
|
+
user: 'admin'
|
39
|
+
password: '123'
|
40
|
+
enabled: true
|
41
|
+
amount: 123.456
|
42
|
+
data: ~
|
43
|
+
methods:
|
44
|
+
- 1
|
45
|
+
- 'test'
|
46
|
+
- ~
|
47
|
+
- true
|
48
|
+
- false
|
49
|
+
- ['data']
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe 'Load from self (hash-like __END__ data representation with ERB inserts)' do
|
4
|
+
specify 'defines config object by self-contained __END__ yaml data with ERB inserts' do
|
5
|
+
class SelfDefinedWithErbConfig < Qonfig::DataSet
|
6
|
+
load_from_self
|
7
|
+
end
|
8
|
+
|
9
|
+
SelfDefinedWithErbConfig.new.settings.tap do |conf|
|
10
|
+
expect(conf.defaults.host).to eq('localhost')
|
11
|
+
expect(conf.defaults.user).to eq('0exp')
|
12
|
+
expect(conf.defaults.password).to eq('password4')
|
13
|
+
expect(conf.defaults.credentials).to eq({})
|
14
|
+
|
15
|
+
expect(conf.staging.host).to eq('yandex.ru')
|
16
|
+
expect(conf.staging.user).to eq('0exp')
|
17
|
+
expect(conf.staging.password).to eq('password4')
|
18
|
+
expect(conf.staging.credentials).to eq({})
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
__END__
|
24
|
+
|
25
|
+
defaults: &defaults
|
26
|
+
host: localhost
|
27
|
+
user: <%= '0exp' %>
|
28
|
+
password: <%= "password#{(2 * 2)}" %>
|
29
|
+
credentials: <%= {} %>
|
30
|
+
|
31
|
+
staging:
|
32
|
+
<<: *defaults
|
33
|
+
host: yandex.ru
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe 'Load from self (hash-like __END__ data representation)' do
|
4
|
+
specify 'defines config object by self-contained __END__ yaml data' do
|
5
|
+
class SelfDefinedConfig < Qonfig::DataSet
|
6
|
+
load_from_self # yaml format will be automatically resolved
|
7
|
+
|
8
|
+
setting :with_nesting do
|
9
|
+
load_from_self
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
SelfDefinedConfig.new.settings.tap do |conf|
|
14
|
+
# access via method
|
15
|
+
expect(conf.secret_key).to eq('top-mega-secret')
|
16
|
+
expect(conf.api_host).to eq('super.puper-google.com')
|
17
|
+
expect(conf.requirements).to eq({})
|
18
|
+
expect(conf.connection_timeout.seconds).to eq(10)
|
19
|
+
expect(conf.connection_timeout.enabled).to eq(false)
|
20
|
+
expect(conf.defaults.port).to eq(12_345)
|
21
|
+
expect(conf.defaults.host).to eq('localhost')
|
22
|
+
expect(conf.staging.port).to eq(12_345)
|
23
|
+
expect(conf.staging.host).to eq('google.kek')
|
24
|
+
|
25
|
+
# access via index
|
26
|
+
expect(conf['secret_key']).to eq('top-mega-secret')
|
27
|
+
expect(conf['api_host']).to eq('super.puper-google.com')
|
28
|
+
expect(conf['requirements']).to eq({})
|
29
|
+
expect(conf[:connection_timeout]['seconds']).to eq(10)
|
30
|
+
expect(conf[:connection_timeout]['enabled']).to eq(false)
|
31
|
+
expect(conf['defaults']['port']).to eq(12_345)
|
32
|
+
expect(conf['defaults']['host']).to eq('localhost')
|
33
|
+
expect(conf['staging']['port']).to eq(12_345)
|
34
|
+
expect(conf['staging']['host']).to eq('google.kek')
|
35
|
+
|
36
|
+
expect(conf.with_nesting.secret_key).to eq('top-mega-secret')
|
37
|
+
expect(conf.with_nesting.api_host).to eq('super.puper-google.com')
|
38
|
+
expect(conf.with_nesting.connection_timeout.seconds).to eq(10)
|
39
|
+
expect(conf.with_nesting.connection_timeout.enabled).to eq(false)
|
40
|
+
expect(conf.with_nesting.requirements).to eq({})
|
41
|
+
|
42
|
+
expect(conf[:with_nesting]['secret_key']).to eq('top-mega-secret')
|
43
|
+
expect(conf[:with_nesting]['api_host']).to eq('super.puper-google.com')
|
44
|
+
expect(conf[:with_nesting][:requirements]).to eq({})
|
45
|
+
expect(conf[:with_nesting][:connection_timeout]['seconds']).to eq(10)
|
46
|
+
expect(conf[:with_nesting][:connection_timeout]['enabled']).to eq(false)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
__END__
|
52
|
+
|
53
|
+
defaults: &defaults
|
54
|
+
port: 12345
|
55
|
+
host: 'localhost'
|
56
|
+
|
57
|
+
staging:
|
58
|
+
<<: *defaults
|
59
|
+
host: 'google.kek'
|
60
|
+
|
61
|
+
secret_key: top-mega-secret
|
62
|
+
api_host: super.puper-google.com
|
63
|
+
requirements: {}
|
64
|
+
:connection_timeout:
|
65
|
+
seconds: 10
|
66
|
+
enabled: false
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe 'Load from self (non-hash-like __END__ data representation)' do
|
4
|
+
specify 'fails when yaml data is not represented as a hash' do
|
5
|
+
class IncompatibleSelfDataConfig < Qonfig::DataSet
|
6
|
+
load_from_self
|
7
|
+
end
|
8
|
+
|
9
|
+
expect { IncompatibleSelfDataConfig.new }.to raise_error(
|
10
|
+
Qonfig::IncompatibleEndDataStructureError
|
11
|
+
)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
__END__
|
16
|
+
|
17
|
+
- user
|
18
|
+
- password
|
19
|
+
- 123
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe 'Load from self (without __END__ data)' do
|
4
|
+
specify 'fails when yaml data is not represented as a hash' do
|
5
|
+
class MissingSelfDataConfig < Qonfig::DataSet
|
6
|
+
load_from_self
|
7
|
+
end
|
8
|
+
|
9
|
+
expect { MissingSelfDataConfig.new }.to raise_error(Qonfig::SelfDataNotFoundError)
|
10
|
+
end
|
11
|
+
end
|