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,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../../load_setting_values_from_file/by_macros_examples'
|
4
|
+
require_relative '../../../load_setting_values_from_file/by_instance_method_examples'
|
5
|
+
|
6
|
+
describe 'Plugins(toml): Load setting values from file', plugin: :toml do
|
7
|
+
describe 'DSL macros (Qonfig::DataSet.values_file)' do
|
8
|
+
it_behaves_like(
|
9
|
+
'load setting values from file by macros',
|
10
|
+
file_format: :toml,
|
11
|
+
file_name: SpecSupport.fixture_path('plugins', 'toml', 'values_file', 'without_env.toml'),
|
12
|
+
file_with_env_name: SpecSupport.fixture_path('plugins', 'toml', 'values_file',
|
13
|
+
'with_env.toml')
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
describe 'Instance methods (Qonfig::DataSet#load_from_file/.load_from_toml' do
|
18
|
+
it_behaves_like(
|
19
|
+
'load setting values from file by instance methods',
|
20
|
+
file_format: :toml,
|
21
|
+
load_by: :load_from_toml,
|
22
|
+
file_name: SpecSupport.fixture_path('plugins', 'toml', 'values_file', 'without_env.toml'),
|
23
|
+
file_with_env_name: SpecSupport.fixture_path('plugins', 'toml', 'values_file',
|
24
|
+
'with_env.toml')
|
25
|
+
)
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe 'Plugins(toml): .values_file / #load_from_self (__END__ data with env)', plugin: :toml do
|
4
|
+
describe 'DSL macros' do
|
5
|
+
context '__END__ data has corresponding env key' do
|
6
|
+
let(:config_klass) do
|
7
|
+
Class.new(Qonfig::DataSet) do
|
8
|
+
values_file :self, format: :toml, expose: :production
|
9
|
+
|
10
|
+
setting :user, 'D@iVeR'
|
11
|
+
setting :queue do
|
12
|
+
setting :adapter, 'que'
|
13
|
+
setting :concurrency, 2
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
specify 'loads setting values of corresponding environment' do
|
19
|
+
config = config_klass.new
|
20
|
+
|
21
|
+
expect(config.settings.user).to eq('iAmDaiveR')
|
22
|
+
expect(config.settings.queue.adapter).to eq('in_memory')
|
23
|
+
expect(config.settings.queue.concurrency).to eq(50)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context '__END__ data does not have correspodning env key' do
|
28
|
+
let(:config_klass) do
|
29
|
+
Class.new(Qonfig::DataSet) do
|
30
|
+
values_file :self, format: :toml, expose: :staging
|
31
|
+
|
32
|
+
setting :user, 'D@iVeR'
|
33
|
+
setting :queue do
|
34
|
+
setting :adapter, 'que'
|
35
|
+
setting :concurrency, 2
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
specify 'ignrores values from __END__ data' do
|
41
|
+
config = config_klass.new
|
42
|
+
|
43
|
+
expect(config.settings.user).to eq('D@iVeR')
|
44
|
+
expect(config.settings.queue.adapter).to eq('que')
|
45
|
+
expect(config.settings.queue.concurrency).to eq(2)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe 'Instance method' do
|
51
|
+
let(:config) do
|
52
|
+
Qonfig::DataSet.build do
|
53
|
+
setting :user, 'D@iVeR'
|
54
|
+
setting :queue do
|
55
|
+
setting :adapter, 'que'
|
56
|
+
setting :concurrency, 2
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context '__END__ data has corresponding env key' do
|
62
|
+
specify 'loads setting values of corresponding environment' do
|
63
|
+
config.load_from_self(format: :toml, expose: :production)
|
64
|
+
|
65
|
+
expect(config.settings.user).to eq('iAmDaiveR')
|
66
|
+
expect(config.settings.queue.adapter).to eq('in_memory')
|
67
|
+
expect(config.settings.queue.concurrency).to eq(50)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context '__END__ data does not have correspodning env key' do
|
72
|
+
specify 'ignrores values from __END__ data' do
|
73
|
+
config.load_from_self(format: :toml, expose: :staging)
|
74
|
+
|
75
|
+
expect(config.settings.user).to eq('D@iVeR')
|
76
|
+
expect(config.settings.queue.adapter).to eq('que')
|
77
|
+
expect(config.settings.queue.concurrency).to eq(2)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
__END__
|
84
|
+
|
85
|
+
[test]
|
86
|
+
user = '0exp'
|
87
|
+
[test.queue]
|
88
|
+
adapter = 'sidekiq'
|
89
|
+
concurrency = 25
|
90
|
+
|
91
|
+
[production]
|
92
|
+
user = 'iAmDaiveR'
|
93
|
+
[production.queue]
|
94
|
+
adapter = 'in_memory'
|
95
|
+
concurrency = 50
|
@@ -0,0 +1,125 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe 'Plugins(toml): .values_file / #load_from_self (with __END__ data)', plugin: :toml do
|
4
|
+
describe 'DSL macros' do
|
5
|
+
let(:config_klass) do
|
6
|
+
Class.new(Qonfig::DataSet) do
|
7
|
+
values_file :self, format: :toml
|
8
|
+
|
9
|
+
setting :user, 'D@iVeR'
|
10
|
+
setting :queue do
|
11
|
+
setting :adapter, 'que'
|
12
|
+
setting :concurrency, 2
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
specify 'loads setting values from __END__ defined as TOML instructions' do
|
18
|
+
config = config_klass.new
|
19
|
+
|
20
|
+
expect(config.settings.user).to eq('0exp')
|
21
|
+
expect(config.settings.queue.adapter).to eq('sidekiq')
|
22
|
+
expect(config.settings.queue.concurrency).to eq(25)
|
23
|
+
end
|
24
|
+
|
25
|
+
specify 'foramt of __END__ data can be inferred automatically' do
|
26
|
+
config = Qonfig::DataSet.build do
|
27
|
+
values_file :self
|
28
|
+
|
29
|
+
setting :user
|
30
|
+
setting :queue do
|
31
|
+
setting :adapter
|
32
|
+
setting :concurrency
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
expect(config.settings.user).to eq('0exp')
|
37
|
+
expect(config.settings.queue.adapter).to eq('sidekiq')
|
38
|
+
expect(config.settings.queue.concurrency).to eq(25)
|
39
|
+
end
|
40
|
+
|
41
|
+
specify 'fails when __END__ data has extra keys' do
|
42
|
+
expect do
|
43
|
+
Qonfig::DataSet.build { values_file :self }
|
44
|
+
end.to raise_error(Qonfig::UnknownSettingError)
|
45
|
+
|
46
|
+
expect do
|
47
|
+
Qonfig::DataSet.build do
|
48
|
+
values_file :self
|
49
|
+
|
50
|
+
setting :user
|
51
|
+
setting :queue do
|
52
|
+
setting :adapter
|
53
|
+
setting :concurrency
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end.not_to raise_error
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe 'Instance method' do
|
61
|
+
let(:config_klass) do
|
62
|
+
Class.new(Qonfig::DataSet) do
|
63
|
+
setting :user, 'D@iVeR'
|
64
|
+
setting :queue do
|
65
|
+
setting :adapter, 'que'
|
66
|
+
setting :concurrency, 2
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
specify 'loads setting values from __END__ defined as TOML instructions' do
|
72
|
+
config = config_klass.new
|
73
|
+
|
74
|
+
expect(config.settings.user).to eq('D@iVeR')
|
75
|
+
expect(config.settings.queue.adapter).to eq('que')
|
76
|
+
expect(config.settings.queue.concurrency).to eq(2)
|
77
|
+
|
78
|
+
config.load_from_self(format: :toml)
|
79
|
+
|
80
|
+
expect(config.settings.user).to eq('0exp')
|
81
|
+
expect(config.settings.queue.adapter).to eq('sidekiq')
|
82
|
+
expect(config.settings.queue.concurrency).to eq(25)
|
83
|
+
end
|
84
|
+
|
85
|
+
specify 'format of __END__ data can be inferred automatically' do
|
86
|
+
config = config_klass.new
|
87
|
+
config.load_from_self
|
88
|
+
|
89
|
+
expect(config.settings.user).to eq('0exp')
|
90
|
+
expect(config.settings.queue.adapter).to eq('sidekiq')
|
91
|
+
expect(config.settings.queue.concurrency).to eq(25)
|
92
|
+
end
|
93
|
+
|
94
|
+
specify 'reloading process returns original values' do
|
95
|
+
config = config_klass.new
|
96
|
+
config.load_from_self
|
97
|
+
config.reload!
|
98
|
+
|
99
|
+
expect(config.settings.user).to eq('D@iVeR')
|
100
|
+
expect(config.settings.queue.adapter).to eq('que')
|
101
|
+
expect(config.settings.queue.concurrency).to eq(2)
|
102
|
+
end
|
103
|
+
|
104
|
+
specify 'fails when __END__ data has extra keys' do
|
105
|
+
config = Qonfig::DataSet.build {}
|
106
|
+
expect { config.load_from_self }.to raise_error(Qonfig::UnknownSettingError)
|
107
|
+
|
108
|
+
config = Qonfig::DataSet.build do
|
109
|
+
setting :user
|
110
|
+
setting :queue do
|
111
|
+
setting :adapter
|
112
|
+
setting :concurrency
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
expect { config.load_from_self }.not_to raise_error
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
__END__
|
122
|
+
user = '0exp'
|
123
|
+
[queue]
|
124
|
+
adapter = 'sidekiq'
|
125
|
+
concurrency = 25
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# rubocop:disable Layout/LineLength
|
4
|
+
describe 'Plugins(toml): .values_file / #load_from_self (with incorrect __END__ data)', plugin: :toml do
|
5
|
+
describe 'DSL macros' do
|
6
|
+
let(:config_klass) do
|
7
|
+
Class.new(Qonfig::DataSet) do
|
8
|
+
values_file :self, format: :toml
|
9
|
+
setting :user, 'D@iVeR'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
specify 'fails with corresponding error' do
|
14
|
+
expect { config_klass.new }.to raise_error(Qonfig::TOMLLoaderParseError)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'Instance method' do
|
19
|
+
let(:config) do
|
20
|
+
Qonfig::DataSet.build { setting :user, 'D@iVeR' }
|
21
|
+
end
|
22
|
+
|
23
|
+
specify 'fails with corresponding error' do
|
24
|
+
expect { config.load_from_self(format: :toml) }.to raise_error(Qonfig::TOMLLoaderParseError)
|
25
|
+
expect(config.settings.user).to eq('D@iVeR')
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
# rubocop:enable Layout/LineLength
|
30
|
+
|
31
|
+
__END__
|
32
|
+
|
33
|
+
user = '0exp'
|
34
|
+
asdf|"ASD"
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe 'Plugins(toml): .values_file / #load_from_self (without __END__ data)', plugin: :toml do
|
4
|
+
describe 'DSL macros' do
|
5
|
+
context 'strict behavior' do
|
6
|
+
let(:config_klass) do
|
7
|
+
Class.new(Qonfig::DataSet) do
|
8
|
+
values_file :self, format: :toml, strict: true
|
9
|
+
setting :user, 'D@iVeR'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
specify 'fails with Qonfig::SelfDataNotFoundError' do
|
14
|
+
expect { config_klass.new }.to raise_error(Qonfig::SelfDataNotFoundError)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'non-strict behavior (default)' do
|
19
|
+
let(:config_klass) do
|
20
|
+
Class.new(Qonfig::DataSet) do
|
21
|
+
values_file :self, format: :toml
|
22
|
+
setting :user, 'D@iVeR'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
specify 'config instantiation works well :)' do
|
27
|
+
config = nil
|
28
|
+
expect { config = config_klass.new }.not_to raise_error
|
29
|
+
expect(config.settings.user).to eq('D@iVeR')
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe 'Instance method' do
|
35
|
+
context 'strict behavior (default)' do
|
36
|
+
let(:config_klass) do
|
37
|
+
Class.new(Qonfig::DataSet) { setting :user, 'D@iVeR' }
|
38
|
+
end
|
39
|
+
|
40
|
+
specify 'fails with Qonfig::SelfDataNotFoundError' do
|
41
|
+
config = config_klass.new
|
42
|
+
|
43
|
+
expect do
|
44
|
+
config.load_from_self(format: :toml, strict: true)
|
45
|
+
end.to raise_error(Qonfig::SelfDataNotFoundError)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'non-strict behavior' do
|
50
|
+
let(:config_klass) do
|
51
|
+
Class.new(Qonfig::DataSet) { setting :user, 'D@iVeR' }
|
52
|
+
end
|
53
|
+
|
54
|
+
specify 'no errors :)' do
|
55
|
+
config = config_klass.new
|
56
|
+
|
57
|
+
expect do
|
58
|
+
config.load_from_self(format: :toml, strict: false)
|
59
|
+
end.not_to raise_error
|
60
|
+
|
61
|
+
expect(config.settings.user).to eq('D@iVeR')
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe 'Plugin(:toml) .values_file / #load_from_file (shared behavior)', plugin: :toml do
|
4
|
+
describe 'unsupported format failures' do
|
5
|
+
describe 'DSL macros' do
|
6
|
+
specify 'fails on unsupported format' do
|
7
|
+
expect do
|
8
|
+
Qonfig::DataSet.build do
|
9
|
+
values_file :self
|
10
|
+
end
|
11
|
+
end.to raise_error(Qonfig::DynamicLoaderParseError)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe 'Instance method' do
|
16
|
+
specify 'fails on unsupported format' do
|
17
|
+
expect do
|
18
|
+
Qonfig::DataSet.build.load_from_self
|
19
|
+
end.to raise_error(Qonfig::DynamicLoaderParseError)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
__END__
|
26
|
+
|
27
|
+
user: 0exp
|
28
|
+
ASDF|"asSDF"
|
29
|
+
[test]
|
30
|
+
<xml>
|
31
|
+
<data>
|
32
|
+
<key>123</key>
|
33
|
+
</data>
|
34
|
+
</xml>
|
@@ -0,0 +1,149 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe 'Plugins(toml): Save to .toml (TOML)', plugin: :toml 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 :cost, 123.456
|
16
|
+
setting :enabled, true
|
17
|
+
|
18
|
+
setting :sub_configurations, [
|
19
|
+
{ 'server' => 'google', 'ping' => false },
|
20
|
+
{ 'server' => 'shoklude', 'ping' => true }
|
21
|
+
]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
let(:config) { config_klass.new }
|
25
|
+
|
26
|
+
before do
|
27
|
+
config.save_to_toml(path: config_file_path) do |value|
|
28
|
+
value.is_a?(Proc) ? value.call : value
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
specify 'correctly represents config as YAML' do
|
33
|
+
file_data = File.read(config_file_path)
|
34
|
+
|
35
|
+
expect(file_data).to eq(<<~TOML.strip << "\n")
|
36
|
+
cost = 123.456
|
37
|
+
enabled = true
|
38
|
+
server_port = 123
|
39
|
+
[sentry]
|
40
|
+
callback = "loaded"
|
41
|
+
user = "D@iVeR"
|
42
|
+
[[sub_configurations]]
|
43
|
+
ping = false
|
44
|
+
server = "google"
|
45
|
+
[[sub_configurations]]
|
46
|
+
ping = true
|
47
|
+
server = "shoklude"
|
48
|
+
TOML
|
49
|
+
end
|
50
|
+
|
51
|
+
specify 'rewrites existing file' do
|
52
|
+
config_a = Class.new(Qonfig::DataSet) do
|
53
|
+
setting :kek, 'kek'
|
54
|
+
end.new
|
55
|
+
|
56
|
+
config_b = Class.new(Qonfig::DataSet) do
|
57
|
+
setting :pek, 'pek'
|
58
|
+
end.new
|
59
|
+
|
60
|
+
# first save (initial write)
|
61
|
+
config_a.save_to_toml(path: config_file_path)
|
62
|
+
file_data = File.read(config_file_path) # NOTE: initial path
|
63
|
+
expect(file_data).to eq(<<~TOML.strip << "\n")
|
64
|
+
kek = "kek"
|
65
|
+
TOML
|
66
|
+
|
67
|
+
# subsequent save (rewrite)
|
68
|
+
config_b.save_to_toml(path: config_file_path)
|
69
|
+
file_data = File.read(config_file_path) # NOTE: same path
|
70
|
+
expect(file_data).to eq(<<~TOML.strip << "\n")
|
71
|
+
pek = "pek"
|
72
|
+
TOML
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe 'data representation' do
|
77
|
+
let(:config_file_name) { "#{SecureRandom.uuid}.yml" }
|
78
|
+
let(:config_file_path) { SpecSupport.artifact_path(config_file_name) }
|
79
|
+
|
80
|
+
context 'config with supported toml types' do
|
81
|
+
let(:config) do
|
82
|
+
Class.new(Qonfig::DataSet) do
|
83
|
+
setting :true_boolean, true
|
84
|
+
setting :false_boolean, false
|
85
|
+
setting :empty_object, {}
|
86
|
+
setting :filled_object, { a: 1, b: nil, 'c' => true, d: '1', e: false }
|
87
|
+
setting :null_data, nil
|
88
|
+
setting :float_value, 123.456
|
89
|
+
setting :collection, [%w[1 2], [3, 4], [true, false], []]
|
90
|
+
setting :time, Time.utc(2031, 0o5, 27, 0o7, 32, 0)
|
91
|
+
end.new
|
92
|
+
end
|
93
|
+
|
94
|
+
specify 'correctly represents YAML data types' do
|
95
|
+
# NOTE: step 1) save config
|
96
|
+
config.save_to_toml(path: config_file_path)
|
97
|
+
|
98
|
+
# NOTE: step 2) read saved file
|
99
|
+
file_data = File.read(config_file_path)
|
100
|
+
|
101
|
+
expect(file_data).to eq(<<~TOML.strip << "\n")
|
102
|
+
collection = [["1", "2"], [3, 4], [true, false], []]
|
103
|
+
false_boolean = false
|
104
|
+
float_value = 123.456
|
105
|
+
time = 2031-05-27T07:32:00Z
|
106
|
+
true_boolean = true
|
107
|
+
[empty_object]
|
108
|
+
[filled_object]
|
109
|
+
a = 1
|
110
|
+
c = true
|
111
|
+
d = "1"
|
112
|
+
e = false
|
113
|
+
TOML
|
114
|
+
end
|
115
|
+
|
116
|
+
specify 'support for Pathname in filepath' do
|
117
|
+
config.save_to_toml(path: Pathname.new(config_file_path))
|
118
|
+
|
119
|
+
file_data = File.read(config_file_path)
|
120
|
+
|
121
|
+
expect(file_data).to eq(<<~TOML.strip << "\n")
|
122
|
+
collection = [["1", "2"], [3, 4], [true, false], []]
|
123
|
+
false_boolean = false
|
124
|
+
float_value = 123.456
|
125
|
+
time = 2031-05-27T07:32:00Z
|
126
|
+
true_boolean = true
|
127
|
+
[empty_object]
|
128
|
+
[filled_object]
|
129
|
+
a = 1
|
130
|
+
c = true
|
131
|
+
d = "1"
|
132
|
+
e = false
|
133
|
+
TOML
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
context 'config with unsupported toml types' do
|
138
|
+
let(:config) do
|
139
|
+
Class.new(Qonfig::DataSet) do
|
140
|
+
setting :collection, [[3, 4], %w[6 4], nil]
|
141
|
+
end.new
|
142
|
+
end
|
143
|
+
|
144
|
+
specify 'fails with parser error' do
|
145
|
+
expect { config.save_to_toml(path: config_file_path) }.to raise_error(::TomlRB::ParseError)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|