spec/lib/chamber_spec.rb in chamber-2.8.0 vs spec/lib/chamber_spec.rb in chamber-2.9.0
- old
+ new
@@ -1,5 +1,6 @@
+# frozen_string_literal: true
require 'rspectacular'
require 'chamber'
require 'fileutils'
# rubocop:disable Metrics/LineLength
@@ -116,46 +117,53 @@
end
it 'can load files based on the namespace passed in' do
Chamber.load(basepath: '/tmp/chamber',
namespaces: {
- my_namespace: -> { 'blue' } })
+ my_namespace: -> { 'blue' },
+ })
expect(Chamber.other.everything).to eql 'works'
expect(Chamber.test.my_dynamic_setting).to eql 2
end
it 'loads multiple namespaces if it is called twice' do
Chamber.load(basepath: '/tmp/chamber',
namespaces: {
first_namespace_call: -> { :first },
- second_namespace_call: -> { :second } })
+ second_namespace_call: -> { :second },
+ })
expect(Chamber.namespaces.to_a).to eql %w{first second}
end
+ # rubocop:disable Lint/DuplicatedKey
it 'does not load the same namespace twice' do
Chamber.load(basepath: '/tmp/chamber',
namespaces: {
first_namespace_call: -> { :first },
- first_namespace_call: -> { :first } })
+ first_namespace_call: -> { :first },
+ })
expect(Chamber.namespaces.to_a).to eql ['first']
end
+ # rubocop:enable Lint/DuplicatedKey
it 'will load settings files which are only namespaced' do
Chamber.load(basepath: '/tmp/chamber',
namespaces: {
- my_namespace: -> { 'blue' } })
+ my_namespace: -> { 'blue' },
+ })
expect(Chamber[:only_namespaced_sub_settings][:another_sub_setting]).to eql 'namespaced'
end
it 'clears all settings each time the settings are loaded' do
Chamber.load(basepath: '/tmp/chamber',
namespaces: {
- my_namespace: -> { 'blue' } })
+ my_namespace: -> { 'blue' },
+ })
expect(Chamber[:only_namespaced_sub_settings][:another_sub_setting]).to eql 'namespaced'
Chamber.load(basepath: '/tmp/chamber')
@@ -169,19 +177,21 @@
end
it 'does not raise an exception if a namespaced file does not exist' do
Chamber.load(basepath: '/tmp/chamber',
namespaces: {
- non_existant_namespace: -> { false } })
+ non_existant_namespace: -> { false },
+ })
expect { Chamber.load(basepath: '/tmp/chamber') }.not_to raise_error
end
it 'merges (not overrides) subsequent settings' do
Chamber.load(basepath: '/tmp/chamber',
namespaces: {
- my_namespace: -> { 'blue' } })
+ my_namespace: -> { 'blue' },
+ })
expect(Chamber.test.my_setting).to eql 'my_value'
expect(Chamber.test.my_other_setting).to eql 'my_other_value'
expect(Chamber.test.another_level.setting_one).to eql 3
end
@@ -199,27 +209,30 @@
it 'loads namespaced YAML files in the "settings" directory if they correspond to ' \
'a value namespace' do
Chamber.load(basepath: '/tmp/chamber',
namespaces: {
- my_namespace: -> { 'blue' } })
+ my_namespace: -> { 'blue' },
+ })
expect(Chamber['sub_settings']['my_namespaced_sub_setting']).to eql 'my_namespaced_sub_setting_value'
end
it 'loads namespaced settings if they are inline in a non-namespaced filename' do
Chamber.load(basepath: '/tmp/chamber',
namespaces: {
- my_namespace: -> { 'blue' } })
+ my_namespace: -> { 'blue' },
+ })
expect(Chamber['my_settings_for_inline_namespace']).to eql 'my_value_for_inline_namespace'
end
it 'does not load non-namespaced data from a file if inline namespaces are found' do
Chamber.load(basepath: '/tmp/chamber',
namespaces: {
- my_namespace: -> { 'blue' } })
+ my_namespace: -> { 'blue' },
+ })
expect(Chamber['my_non_inline_namespaced_setting']).not_to eql 'my_value_for_non_inline_namespace'
end
it 'loads the entire inline namespaced file if no namespaces are passed in since ' \
@@ -229,10 +242,11 @@
expect(Chamber['blue']['my_settings_for_inline_namespace']).to eql 'my_value_for_inline_namespace'
expect(Chamber['my_non_inline_namespaced_setting']).to eql 'my_value_for_non_inline_namespace'
end
+ # rubocop:disable Lint/DuplicatedKey
it 'can convert the settings to their environment variable versions' do
Chamber.load(basepath: '/tmp/chamber')
expect(Chamber.to_environment).to eql(
'SUB_SETTINGS_MY_SUB_SETTING' => 'my_sub_setting_value',
@@ -247,9 +261,10 @@
'TEST_MY_BOOLEAN' => 'false',
'BLUE_MY_SETTINGS_FOR_INLINE_NAMESPACE' => 'my_value_for_inline_namespace',
'MY_NON_INLINE_NAMESPACED_SETTING' => 'my_value_for_non_inline_namespace',
)
end
+ # rubocop:enable Lint/DuplicatedKey
it 'can convert boolean-like strings to actual booleans' do
expect(Chamber[:test][:my_boolean]).to be_a FalseClass
end