chamber 2.8.0 → 2.9.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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +1 -0
- data/LICENSE.txt +19 -0
- data/Rakefile +1 -0
- data/bin/chamber +1 -0
- data/lib/chamber.rb +1 -0
- data/lib/chamber/binary/heroku.rb +1 -0
- data/lib/chamber/binary/runner.rb +1 -0
- data/lib/chamber/binary/travis.rb +1 -0
- data/lib/chamber/commands/base.rb +1 -0
- data/lib/chamber/commands/comparable.rb +1 -0
- data/lib/chamber/commands/compare.rb +1 -0
- data/lib/chamber/commands/files.rb +1 -0
- data/lib/chamber/commands/heroku.rb +1 -0
- data/lib/chamber/commands/heroku/clear.rb +1 -0
- data/lib/chamber/commands/heroku/compare.rb +1 -0
- data/lib/chamber/commands/heroku/pull.rb +1 -0
- data/lib/chamber/commands/heroku/push.rb +1 -0
- data/lib/chamber/commands/initialize.rb +5 -3
- data/lib/chamber/commands/securable.rb +1 -0
- data/lib/chamber/commands/secure.rb +1 -0
- data/lib/chamber/commands/show.rb +1 -0
- data/lib/chamber/commands/travis.rb +1 -0
- data/lib/chamber/commands/travis/secure.rb +1 -0
- data/lib/chamber/configuration.rb +1 -0
- data/lib/chamber/context_resolver.rb +10 -7
- data/lib/chamber/decryption_key.rb +1 -0
- data/lib/chamber/encryption_methods/none.rb +17 -0
- data/lib/chamber/encryption_methods/public_key.rb +27 -0
- data/lib/chamber/encryption_methods/ssl.rb +60 -0
- data/lib/chamber/environmentable.rb +1 -0
- data/lib/chamber/errors/decryption_failure.rb +1 -0
- data/lib/chamber/file.rb +9 -1
- data/lib/chamber/file_set.rb +4 -3
- data/lib/chamber/filters/boolean_conversion_filter.rb +2 -1
- data/lib/chamber/filters/decryption_filter.rb +20 -29
- data/lib/chamber/filters/encryption_filter.rb +29 -14
- data/lib/chamber/filters/environment_filter.rb +2 -1
- data/lib/chamber/filters/failed_decryption_filter.rb +3 -2
- data/lib/chamber/filters/insecure_filter.rb +1 -0
- data/lib/chamber/filters/namespace_filter.rb +2 -1
- data/lib/chamber/filters/secure_filter.rb +2 -1
- data/lib/chamber/filters/translate_secure_keys_filter.rb +2 -1
- data/lib/chamber/instance.rb +1 -0
- data/lib/chamber/namespace_set.rb +4 -3
- data/lib/chamber/rails.rb +1 -0
- data/lib/chamber/rails/railtie.rb +3 -1
- data/lib/chamber/rubinius_fix.rb +1 -0
- data/lib/chamber/settings.rb +23 -18
- data/lib/chamber/version.rb +2 -1
- data/spec/lib/chamber/commands/files_spec.rb +5 -2
- data/spec/lib/chamber/commands/heroku/clear_spec.rb +1 -0
- data/spec/lib/chamber/commands/heroku/compare_spec.rb +1 -0
- data/spec/lib/chamber/commands/heroku/pull_spec.rb +1 -0
- data/spec/lib/chamber/commands/heroku/push_spec.rb +1 -0
- data/spec/lib/chamber/commands/secure_spec.rb +5 -2
- data/spec/lib/chamber/commands/show_spec.rb +1 -0
- data/spec/lib/chamber/context_resolver_spec.rb +8 -5
- data/spec/lib/chamber/file_set_spec.rb +55 -52
- data/spec/lib/chamber/file_spec.rb +43 -9
- data/spec/lib/chamber/filters/boolean_conversion_filter_spec.rb +14 -5
- data/spec/lib/chamber/filters/decryption_filter_spec.rb +85 -9
- data/spec/lib/chamber/filters/encryption_filter_spec.rb +76 -10
- data/spec/lib/chamber/filters/environment_filter_spec.rb +9 -2
- data/spec/lib/chamber/filters/failed_decryption_filter_spec.rb +7 -6
- data/spec/lib/chamber/filters/insecure_filter_spec.rb +12 -4
- data/spec/lib/chamber/filters/namespace_filter_spec.rb +33 -14
- data/spec/lib/chamber/filters/secure_filter_spec.rb +8 -3
- data/spec/lib/chamber/filters/translate_secure_keys_filter_spec.rb +10 -3
- data/spec/lib/chamber/namespace_set_spec.rb +6 -3
- data/spec/lib/chamber/settings_spec.rb +36 -25
- data/spec/lib/chamber_spec.rb +25 -10
- data/spec/rails-2-test/config/application.rb +1 -0
- data/spec/rails-3-test/config/application.rb +1 -0
- data/spec/rails-4-test/config/application.rb +1 -0
- metadata +35 -9
- metadata.gz.sig +0 -0
- data/LICENSE +0 -22
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'rspectacular'
|
2
3
|
require 'chamber/filters/failed_decryption_filter'
|
3
4
|
|
@@ -5,7 +6,7 @@ module Chamber
|
|
5
6
|
module Filters
|
6
7
|
describe FailedDecryptionFilter do
|
7
8
|
it 'raises an exception if any of the settings are not decrypted' do
|
8
|
-
expect
|
9
|
+
expect {
|
9
10
|
FailedDecryptionFilter.execute(
|
10
11
|
data: {
|
11
12
|
_secure_my_secure_setting: 'cJbFe0NI5wknmsp2fVgpC/YeBD2pvcdVD+p0pUdnMoYThaV4m' \
|
@@ -17,12 +18,12 @@ describe FailedDecryptionFilter do
|
|
17
18
|
'TcdgbE9NcAhNr1+WfNxMnz84XzmUp2Y0H1jPgGkBKQJKArfQ==',
|
18
19
|
},
|
19
20
|
)
|
20
|
-
|
21
|
+
}.
|
21
22
|
to raise_error Chamber::Errors::DecryptionFailure
|
22
23
|
end
|
23
24
|
|
24
25
|
it 'does not raise an exception if it is not a secure key' do
|
25
|
-
expect
|
26
|
+
expect {
|
26
27
|
FailedDecryptionFilter.execute(
|
27
28
|
data: {
|
28
29
|
my_secure_setting: 'cJbFe0NI5wknmsp2fVgpC/YeBD2pvcdVD+p0pUdnMoYThaV4m' \
|
@@ -34,18 +35,18 @@ describe FailedDecryptionFilter do
|
|
34
35
|
'TcdgbE9NcAhNr1+WfNxMnz84XzmUp2Y0H1jPgGkBKQJKArfQ==',
|
35
36
|
},
|
36
37
|
)
|
37
|
-
|
38
|
+
}.
|
38
39
|
not_to raise_error
|
39
40
|
end
|
40
41
|
|
41
42
|
it 'does not raise an exception if it is not a secure value' do
|
42
|
-
expect
|
43
|
+
expect {
|
43
44
|
FailedDecryptionFilter.execute(
|
44
45
|
data: {
|
45
46
|
_secure_my_secure_setting: 'hello',
|
46
47
|
},
|
47
48
|
)
|
48
|
-
|
49
|
+
}.
|
49
50
|
not_to raise_error
|
50
51
|
end
|
51
52
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'rspectacular'
|
2
3
|
require 'chamber/filters/insecure_filter'
|
3
4
|
|
@@ -6,14 +7,16 @@ module Filters
|
|
6
7
|
describe InsecureFilter do
|
7
8
|
it 'will return values which are marked as "secure" if they are unencrypted' do
|
8
9
|
filtered_settings = InsecureFilter.execute(data: {
|
9
|
-
_secure_my_secure_setting: 'hello'
|
10
|
+
_secure_my_secure_setting: 'hello',
|
11
|
+
})
|
10
12
|
|
11
13
|
expect(filtered_settings._secure_my_secure_setting).to match 'hello'
|
12
14
|
end
|
13
15
|
|
14
16
|
it 'will not return values which are not marked as "secure"' do
|
15
17
|
filtered_settings = InsecureFilter.execute(data: {
|
16
|
-
my_secure_setting: 'hello'
|
18
|
+
my_secure_setting: 'hello',
|
19
|
+
})
|
17
20
|
|
18
21
|
expect(filtered_settings.my_secure_setting).to be_nil
|
19
22
|
end
|
@@ -24,7 +27,9 @@ describe InsecureFilter do
|
|
24
27
|
secure_setting: 'goodbye',
|
25
28
|
secure_group: {
|
26
29
|
_secure_nested_setting: 'movie',
|
27
|
-
insecure_nested_setting: 'dinner'
|
30
|
+
insecure_nested_setting: 'dinner',
|
31
|
+
},
|
32
|
+
})
|
28
33
|
|
29
34
|
expect(filtered_settings._secure_setting).to eql 'hello'
|
30
35
|
expect(filtered_settings.secure_setting).to be_nil
|
@@ -60,7 +65,10 @@ describe InsecureFilter do
|
|
60
65
|
'gfXc86wdgUKc8aaoX8OQA1kKTcdgbE9NcAhNr1+WfNxMn' \
|
61
66
|
'z84XzmUp2Y0H1jPgGkBKQJKArfQ==',
|
62
67
|
_secure_other_nested_setting: 'goodbye',
|
63
|
-
insecure_nested_setting: 'dinner'
|
68
|
+
insecure_nested_setting: 'dinner',
|
69
|
+
},
|
70
|
+
},
|
71
|
+
)
|
64
72
|
|
65
73
|
expect(filtered_settings._secure_setting?).to eql false
|
66
74
|
expect(filtered_settings.secure_setting?).to eql false
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'rspectacular'
|
2
3
|
require 'chamber/filters/namespace_filter'
|
3
4
|
require 'chamber/namespace_set'
|
@@ -9,10 +10,14 @@ describe NamespaceFilter do
|
|
9
10
|
filtered_settings = NamespaceFilter.execute(
|
10
11
|
data: {
|
11
12
|
namespace_value: {
|
12
|
-
namespace_setting: 'value 1'
|
13
|
+
namespace_setting: 'value 1',
|
14
|
+
},
|
13
15
|
other_namespace_value: {
|
14
|
-
other_namespace_setting: 'value 2'
|
15
|
-
|
16
|
+
other_namespace_setting: 'value 2',
|
17
|
+
},
|
18
|
+
},
|
19
|
+
namespaces: %w{namespace_value other_namespace_value},
|
20
|
+
)
|
16
21
|
|
17
22
|
expect(filtered_settings.namespace_setting).to eql 'value 1'
|
18
23
|
expect(filtered_settings.other_namespace_setting).to eql 'value 2'
|
@@ -22,11 +27,16 @@ describe NamespaceFilter do
|
|
22
27
|
filtered_settings = NamespaceFilter.execute(
|
23
28
|
data: {
|
24
29
|
namespace_value: {
|
25
|
-
namespace_setting: 'value 1'
|
30
|
+
namespace_setting: 'value 1',
|
31
|
+
},
|
26
32
|
non_namespaced_value: {
|
27
|
-
non_namespaced_setting: 'value 2'
|
33
|
+
non_namespaced_setting: 'value 2',
|
34
|
+
},
|
35
|
+
},
|
28
36
|
namespaces: [
|
29
|
-
|
37
|
+
'namespace_value',
|
38
|
+
],
|
39
|
+
)
|
30
40
|
|
31
41
|
expect(filtered_settings.namespace_setting).to eql 'value 1'
|
32
42
|
expect(filtered_settings.non_namespaced_setting).to be_nil
|
@@ -36,8 +46,11 @@ describe NamespaceFilter do
|
|
36
46
|
filtered_settings = NamespaceFilter.execute(
|
37
47
|
data: {
|
38
48
|
namespace_value: {
|
39
|
-
namespace_setting: 'value 1'
|
40
|
-
|
49
|
+
namespace_setting: 'value 1',
|
50
|
+
},
|
51
|
+
},
|
52
|
+
namespaces: %w{namespace_value other_namespace_value},
|
53
|
+
)
|
41
54
|
|
42
55
|
expect(filtered_settings.namespace_setting).to eql 'value 1'
|
43
56
|
end
|
@@ -45,8 +58,10 @@ describe NamespaceFilter do
|
|
45
58
|
it 'does not filter data if it does not include any namespaces' do
|
46
59
|
filtered_settings = NamespaceFilter.execute(
|
47
60
|
data: {
|
48
|
-
non_namespaced_setting: 'value 1'
|
49
|
-
|
61
|
+
non_namespaced_setting: 'value 1',
|
62
|
+
},
|
63
|
+
namespaces: [],
|
64
|
+
)
|
50
65
|
|
51
66
|
expect(filtered_settings.non_namespaced_setting).to eql 'value 1'
|
52
67
|
end
|
@@ -56,12 +71,16 @@ describe NamespaceFilter do
|
|
56
71
|
data: {
|
57
72
|
namespace_value: {
|
58
73
|
namespace_setting: 'value 1',
|
59
|
-
another_namespace_setting: 'value 2'
|
74
|
+
another_namespace_setting: 'value 2',
|
75
|
+
},
|
60
76
|
other_namespace_value: {
|
61
77
|
namespace_setting_1: 'value 1',
|
62
|
-
another_namespace_setting_2: 'value 2'
|
63
|
-
|
64
|
-
|
78
|
+
another_namespace_setting_2: 'value 2',
|
79
|
+
},
|
80
|
+
non_namespaced_value: 'value 3',
|
81
|
+
},
|
82
|
+
namespaces: NamespaceSet.new(%w{namespace_value other_namespace_value}),
|
83
|
+
)
|
65
84
|
|
66
85
|
expect(filtered_settings.to_hash).to eql('namespace_setting' => 'value 1',
|
67
86
|
'another_namespace_setting' => 'value 2',
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'rspectacular'
|
2
3
|
require 'chamber/filters/secure_filter'
|
3
4
|
|
@@ -6,14 +7,16 @@ module Filters
|
|
6
7
|
describe SecureFilter do
|
7
8
|
it 'will return values which are marked as "secure"' do
|
8
9
|
filtered_settings = SecureFilter.execute(data: {
|
9
|
-
_secure_my_secure_setting: 'hello'
|
10
|
+
_secure_my_secure_setting: 'hello',
|
11
|
+
})
|
10
12
|
|
11
13
|
expect(filtered_settings._secure_my_secure_setting).to match 'hello'
|
12
14
|
end
|
13
15
|
|
14
16
|
it 'will not return values which are not marked as "secure"' do
|
15
17
|
filtered_settings = SecureFilter.execute(data: {
|
16
|
-
my_secure_setting: 'hello'
|
18
|
+
my_secure_setting: 'hello',
|
19
|
+
})
|
17
20
|
|
18
21
|
expect(filtered_settings.my_secure_setting).to be_nil
|
19
22
|
end
|
@@ -24,7 +27,9 @@ describe SecureFilter do
|
|
24
27
|
secure_setting: 'goodbye',
|
25
28
|
secure_group: {
|
26
29
|
_secure_nested_setting: 'movie',
|
27
|
-
insecure_nested_setting: 'dinner'
|
30
|
+
insecure_nested_setting: 'dinner',
|
31
|
+
},
|
32
|
+
})
|
28
33
|
|
29
34
|
expect(filtered_settings._secure_setting).to eql 'hello'
|
30
35
|
expect(filtered_settings.secure_setting).to be_nil
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'rspectacular'
|
2
3
|
require 'chamber/filters/translate_secure_keys_filter'
|
3
4
|
|
@@ -7,7 +8,9 @@ describe TranslateSecureKeysFilter do
|
|
7
8
|
it 'will translate keys if they start with "_secure_"' do
|
8
9
|
filtered_settings = TranslateSecureKeysFilter.execute(
|
9
10
|
data: {
|
10
|
-
_secure_my_secure_setting: 'hello'
|
11
|
+
_secure_my_secure_setting: 'hello',
|
12
|
+
},
|
13
|
+
)
|
11
14
|
|
12
15
|
expect(filtered_settings.my_secure_setting).to eql 'hello'
|
13
16
|
end
|
@@ -15,7 +18,9 @@ describe TranslateSecureKeysFilter do
|
|
15
18
|
it 'will not translate keys if they do not start with "_secure_"' do
|
16
19
|
filtered_settings = TranslateSecureKeysFilter.execute(
|
17
20
|
data: {
|
18
|
-
my_secure_setting: 'hello'
|
21
|
+
my_secure_setting: 'hello',
|
22
|
+
},
|
23
|
+
)
|
19
24
|
|
20
25
|
expect(filtered_settings.my_secure_setting).to eql 'hello'
|
21
26
|
end
|
@@ -23,7 +28,9 @@ describe TranslateSecureKeysFilter do
|
|
23
28
|
it 'will not translate the key if it starts with "secure"' do
|
24
29
|
filtered_settings = TranslateSecureKeysFilter.execute(
|
25
30
|
data: {
|
26
|
-
secure_setting: 'hello'
|
31
|
+
secure_setting: 'hello',
|
32
|
+
},
|
33
|
+
)
|
27
34
|
|
28
35
|
expect(filtered_settings.secure_setting).to eql 'hello'
|
29
36
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'rspectacular'
|
2
3
|
require 'chamber/namespace_set'
|
3
4
|
|
@@ -11,8 +12,10 @@ describe NamespaceSet do
|
|
11
12
|
end
|
12
13
|
|
13
14
|
it 'can create a set from an array' do
|
14
|
-
namespace_set = NamespaceSet.new([
|
15
|
-
|
15
|
+
namespace_set = NamespaceSet.new([
|
16
|
+
:development,
|
17
|
+
'my host',
|
18
|
+
])
|
16
19
|
|
17
20
|
expect(namespace_set).to eq ['development', 'my host']
|
18
21
|
end
|
@@ -56,7 +59,7 @@ describe NamespaceSet do
|
|
56
59
|
original_set = NamespaceSet[:development, 'my host']
|
57
60
|
namespace_set = NamespaceSet.new(original_set)
|
58
61
|
|
59
|
-
expect(namespace_set.
|
62
|
+
expect(namespace_set.__send__(:raw_namespaces)).not_to be_a NamespaceSet
|
60
63
|
end
|
61
64
|
|
62
65
|
it 'can turn itself into an array' do
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'rspectacular'
|
2
3
|
require 'chamber/settings'
|
3
4
|
|
@@ -55,17 +56,21 @@ describe Settings do
|
|
55
56
|
it 'sorts environment variables by name when converted to an environment hash so ' \
|
56
57
|
'that they are easier to parse for humans' do
|
57
58
|
|
58
|
-
settings = Settings.new(settings: {
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
59
|
+
settings = Settings.new(settings: {
|
60
|
+
'C' => 'value',
|
61
|
+
'D' => 'value',
|
62
|
+
'A' => 'value',
|
63
|
+
'E' => 'value',
|
64
|
+
'B' => 'value',
|
65
|
+
})
|
66
|
+
|
67
|
+
expect(settings.to_environment.to_a).to eql([
|
68
|
+
%w{A value},
|
69
|
+
%w{B value},
|
70
|
+
%w{C value},
|
71
|
+
%w{D value},
|
72
|
+
%w{E value},
|
73
|
+
])
|
69
74
|
end
|
70
75
|
|
71
76
|
it 'can convert itself into a string' do
|
@@ -82,12 +87,12 @@ describe Settings do
|
|
82
87
|
})
|
83
88
|
|
84
89
|
expect(settings.to_s).to eql %w{
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
90
|
+
LEVEL_1_BODY="gracias"
|
91
|
+
LEVEL_1_LEVEL_2_ANOTHER="goodbye"
|
92
|
+
LEVEL_1_LEVEL_2_SOME_SETTING="hello"
|
93
|
+
MY_SETTING="value"
|
94
|
+
THERE="was not that easy?"
|
95
|
+
}.join(' ')
|
91
96
|
end
|
92
97
|
|
93
98
|
it 'can convert itself into a string with custom options' do
|
@@ -137,7 +142,8 @@ HEREDOC
|
|
137
142
|
|
138
143
|
expect(merged_settings).to eql Settings.new(settings: {
|
139
144
|
setting: 'value',
|
140
|
-
other_setting: 'another value'
|
145
|
+
other_setting: 'another value',
|
146
|
+
},
|
141
147
|
namespaces: %w{good bad})
|
142
148
|
end
|
143
149
|
|
@@ -172,7 +178,7 @@ HEREDOC
|
|
172
178
|
there: 'was not that easy?',
|
173
179
|
})
|
174
180
|
|
175
|
-
expect(settings.to_flattened_name_hash).to
|
181
|
+
expect(settings.to_flattened_name_hash).to eql(
|
176
182
|
%w{my_setting} => 'value',
|
177
183
|
%w{level_1 level_2 some_setting} => 'hello',
|
178
184
|
%w{level_1 level_2 another} => 'goodbye',
|
@@ -191,7 +197,7 @@ HEREDOC
|
|
191
197
|
settings_hash = settings.to_hash
|
192
198
|
settings_hash['setting'] = 'foo'
|
193
199
|
|
194
|
-
expect(settings.
|
200
|
+
expect(settings.__send__(:data).object_id).not_to eql settings_hash.object_id
|
195
201
|
expect(settings.setting).to eql 'value'
|
196
202
|
end
|
197
203
|
|
@@ -216,9 +222,11 @@ HEREDOC
|
|
216
222
|
it 'only includes namespaced data if any exists' do
|
217
223
|
settings = Settings.new(settings: {
|
218
224
|
namespace_value: {
|
219
|
-
namespace_setting: 'value'
|
225
|
+
namespace_setting: 'value',
|
226
|
+
},
|
220
227
|
other_namespace_value: {
|
221
|
-
other_namespace_setting: 'value'
|
228
|
+
other_namespace_setting: 'value',
|
229
|
+
},
|
222
230
|
non_namespace_setting: 'other value',
|
223
231
|
},
|
224
232
|
namespaces: %w{namespace_value other_namespace_value})
|
@@ -239,7 +247,8 @@ HEREDOC
|
|
239
247
|
'wdgUKc8aaoX8OQA1kKTcdgbE9NcAhNr1+WfNxMnz84XzmU' \
|
240
248
|
'p2Y0H1jPgGkBKQJKArfQ==',
|
241
249
|
},
|
242
|
-
decryption_key: './spec/spec_key'
|
250
|
+
decryption_key: './spec/spec_key',
|
251
|
+
)
|
243
252
|
|
244
253
|
expect(settings).to eq('my_encrypted_setting' => 'hello')
|
245
254
|
end
|
@@ -291,7 +300,8 @@ HEREDOC
|
|
291
300
|
_secure_my_unencrypted_setting: 'nifty',
|
292
301
|
my_insecure_setting: 'goodbye',
|
293
302
|
},
|
294
|
-
decryption_key: './spec/spec_key'
|
303
|
+
decryption_key: './spec/spec_key',
|
304
|
+
)
|
295
305
|
|
296
306
|
secured_settings = settings.securable
|
297
307
|
|
@@ -314,7 +324,8 @@ HEREDOC
|
|
314
324
|
_secure_my_unencrypted_setting: 'nifty',
|
315
325
|
my_insecure_setting: 'goodbye',
|
316
326
|
},
|
317
|
-
decryption_key: './spec/spec_key'
|
327
|
+
decryption_key: './spec/spec_key',
|
328
|
+
)
|
318
329
|
|
319
330
|
secured_settings = settings.insecure
|
320
331
|
|
data/spec/lib/chamber_spec.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'rspectacular'
|
2
3
|
require 'chamber'
|
3
4
|
require 'fileutils'
|
@@ -118,7 +119,8 @@ describe 'Chamber' do
|
|
118
119
|
it 'can load files based on the namespace passed in' do
|
119
120
|
Chamber.load(basepath: '/tmp/chamber',
|
120
121
|
namespaces: {
|
121
|
-
my_namespace: -> { 'blue' }
|
122
|
+
my_namespace: -> { 'blue' },
|
123
|
+
})
|
122
124
|
|
123
125
|
expect(Chamber.other.everything).to eql 'works'
|
124
126
|
expect(Chamber.test.my_dynamic_setting).to eql 2
|
@@ -128,24 +130,29 @@ describe 'Chamber' do
|
|
128
130
|
Chamber.load(basepath: '/tmp/chamber',
|
129
131
|
namespaces: {
|
130
132
|
first_namespace_call: -> { :first },
|
131
|
-
second_namespace_call: -> { :second }
|
133
|
+
second_namespace_call: -> { :second },
|
134
|
+
})
|
132
135
|
|
133
136
|
expect(Chamber.namespaces.to_a).to eql %w{first second}
|
134
137
|
end
|
135
138
|
|
139
|
+
# rubocop:disable Lint/DuplicatedKey
|
136
140
|
it 'does not load the same namespace twice' do
|
137
141
|
Chamber.load(basepath: '/tmp/chamber',
|
138
142
|
namespaces: {
|
139
143
|
first_namespace_call: -> { :first },
|
140
|
-
first_namespace_call: -> { :first }
|
144
|
+
first_namespace_call: -> { :first },
|
145
|
+
})
|
141
146
|
|
142
147
|
expect(Chamber.namespaces.to_a).to eql ['first']
|
143
148
|
end
|
149
|
+
# rubocop:enable Lint/DuplicatedKey
|
144
150
|
|
145
151
|
it 'will load settings files which are only namespaced' do
|
146
152
|
Chamber.load(basepath: '/tmp/chamber',
|
147
153
|
namespaces: {
|
148
|
-
my_namespace: -> { 'blue' }
|
154
|
+
my_namespace: -> { 'blue' },
|
155
|
+
})
|
149
156
|
|
150
157
|
expect(Chamber[:only_namespaced_sub_settings][:another_sub_setting]).to eql 'namespaced'
|
151
158
|
end
|
@@ -153,7 +160,8 @@ describe 'Chamber' do
|
|
153
160
|
it 'clears all settings each time the settings are loaded' do
|
154
161
|
Chamber.load(basepath: '/tmp/chamber',
|
155
162
|
namespaces: {
|
156
|
-
my_namespace: -> { 'blue' }
|
163
|
+
my_namespace: -> { 'blue' },
|
164
|
+
})
|
157
165
|
|
158
166
|
expect(Chamber[:only_namespaced_sub_settings][:another_sub_setting]).to eql 'namespaced'
|
159
167
|
|
@@ -171,7 +179,8 @@ describe 'Chamber' do
|
|
171
179
|
it 'does not raise an exception if a namespaced file does not exist' do
|
172
180
|
Chamber.load(basepath: '/tmp/chamber',
|
173
181
|
namespaces: {
|
174
|
-
non_existant_namespace: -> { false }
|
182
|
+
non_existant_namespace: -> { false },
|
183
|
+
})
|
175
184
|
|
176
185
|
expect { Chamber.load(basepath: '/tmp/chamber') }.not_to raise_error
|
177
186
|
end
|
@@ -179,7 +188,8 @@ describe 'Chamber' do
|
|
179
188
|
it 'merges (not overrides) subsequent settings' do
|
180
189
|
Chamber.load(basepath: '/tmp/chamber',
|
181
190
|
namespaces: {
|
182
|
-
my_namespace: -> { 'blue' }
|
191
|
+
my_namespace: -> { 'blue' },
|
192
|
+
})
|
183
193
|
|
184
194
|
expect(Chamber.test.my_setting).to eql 'my_value'
|
185
195
|
expect(Chamber.test.my_other_setting).to eql 'my_other_value'
|
@@ -201,7 +211,8 @@ describe 'Chamber' do
|
|
201
211
|
|
202
212
|
Chamber.load(basepath: '/tmp/chamber',
|
203
213
|
namespaces: {
|
204
|
-
my_namespace: -> { 'blue' }
|
214
|
+
my_namespace: -> { 'blue' },
|
215
|
+
})
|
205
216
|
|
206
217
|
expect(Chamber['sub_settings']['my_namespaced_sub_setting']).to eql 'my_namespaced_sub_setting_value'
|
207
218
|
end
|
@@ -209,7 +220,8 @@ describe 'Chamber' do
|
|
209
220
|
it 'loads namespaced settings if they are inline in a non-namespaced filename' do
|
210
221
|
Chamber.load(basepath: '/tmp/chamber',
|
211
222
|
namespaces: {
|
212
|
-
my_namespace: -> { 'blue' }
|
223
|
+
my_namespace: -> { 'blue' },
|
224
|
+
})
|
213
225
|
|
214
226
|
expect(Chamber['my_settings_for_inline_namespace']).to eql 'my_value_for_inline_namespace'
|
215
227
|
end
|
@@ -217,7 +229,8 @@ describe 'Chamber' do
|
|
217
229
|
it 'does not load non-namespaced data from a file if inline namespaces are found' do
|
218
230
|
Chamber.load(basepath: '/tmp/chamber',
|
219
231
|
namespaces: {
|
220
|
-
my_namespace: -> { 'blue' }
|
232
|
+
my_namespace: -> { 'blue' },
|
233
|
+
})
|
221
234
|
|
222
235
|
expect(Chamber['my_non_inline_namespaced_setting']).not_to eql 'my_value_for_non_inline_namespace'
|
223
236
|
end
|
@@ -231,6 +244,7 @@ describe 'Chamber' do
|
|
231
244
|
expect(Chamber['my_non_inline_namespaced_setting']).to eql 'my_value_for_non_inline_namespace'
|
232
245
|
end
|
233
246
|
|
247
|
+
# rubocop:disable Lint/DuplicatedKey
|
234
248
|
it 'can convert the settings to their environment variable versions' do
|
235
249
|
Chamber.load(basepath: '/tmp/chamber')
|
236
250
|
|
@@ -249,6 +263,7 @@ describe 'Chamber' do
|
|
249
263
|
'MY_NON_INLINE_NAMESPACED_SETTING' => 'my_value_for_non_inline_namespace',
|
250
264
|
)
|
251
265
|
end
|
266
|
+
# rubocop:enable Lint/DuplicatedKey
|
252
267
|
|
253
268
|
it 'can convert boolean-like strings to actual booleans' do
|
254
269
|
expect(Chamber[:test][:my_boolean]).to be_a FalseClass
|