global 0.2.2 → 2.1.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 +5 -5
- data/.github/workflows/tests.yml +24 -0
- data/.rubocop.yml +110 -0
- data/.ruby-version +1 -1
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +3 -6
- data/README.md +275 -66
- data/Rakefile +10 -2
- data/bin/console +15 -0
- data/global.gemspec +20 -22
- data/lib/global/backend/aws_parameter_store.rb +110 -0
- data/lib/global/backend/filesystem.rb +91 -0
- data/lib/global/backend/gcp_secret_manager.rb +137 -0
- data/lib/global/base.rb +40 -60
- data/lib/global/configuration.rb +25 -18
- data/lib/global/version.rb +4 -2
- data/lib/global.rb +5 -2
- data/spec/files/aws.test.yml +3 -0
- data/spec/files/aws.yml +6 -0
- data/spec/global/backend/aws_parameter_store_spec.rb +48 -0
- data/spec/global/backend/gcp_secret_manager_spec.rb +39 -0
- data/spec/global/configuration_spec.rb +88 -74
- data/spec/global_spec.rb +53 -70
- data/spec/merge_backends_spec.rb +23 -0
- data/spec/spec_helper.rb +9 -6
- metadata +68 -30
- data/.travis.yml +0 -30
- data/app/assets/javascripts/global-js.js.erb +0 -2
- data/lib/global/engine.rb +0 -78
- data/spec/global/global_js_spec.rb +0 -114
- data/spec/support/javascript_helper.rb +0 -24
data/spec/files/aws.yml
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
require 'aws-sdk-ssm'
|
|
5
|
+
require 'global/backend/aws_parameter_store'
|
|
6
|
+
|
|
7
|
+
RSpec.describe Global::Backend::AwsParameterStore do
|
|
8
|
+
let(:client) do
|
|
9
|
+
Aws::SSM::Client.new(stub_responses: true)
|
|
10
|
+
end
|
|
11
|
+
subject do
|
|
12
|
+
described_class.new(prefix: '/testapp/', client: client)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it 'reads parameters from the parameter store' do
|
|
16
|
+
client.stub_responses(
|
|
17
|
+
:get_parameters_by_path,
|
|
18
|
+
[
|
|
19
|
+
lambda { |req_context|
|
|
20
|
+
expect(req_context.params[:next_token]).to be_nil
|
|
21
|
+
{
|
|
22
|
+
parameters: [
|
|
23
|
+
{ name: '/testapp/foo', value: 'foo-value' },
|
|
24
|
+
{ name: '/testapp/bar/baz', value: 'baz-value' }
|
|
25
|
+
],
|
|
26
|
+
next_token: 'next-token'
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
lambda { |req_context|
|
|
30
|
+
expect(req_context.params[:next_token]).to eq('next-token')
|
|
31
|
+
{
|
|
32
|
+
parameters: [
|
|
33
|
+
{ name: '/testapp/bar/qux', value: 'qux-value' }
|
|
34
|
+
],
|
|
35
|
+
next_token: nil
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
]
|
|
39
|
+
)
|
|
40
|
+
expect(subject.load).to eq(
|
|
41
|
+
foo: 'foo-value',
|
|
42
|
+
bar: {
|
|
43
|
+
baz: 'baz-value',
|
|
44
|
+
qux: 'qux-value'
|
|
45
|
+
}
|
|
46
|
+
)
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
require 'google/cloud/secret_manager'
|
|
5
|
+
require 'global/backend/gcp_secret_manager'
|
|
6
|
+
|
|
7
|
+
RSpec.describe Global::Backend::GcpSecretManager do
|
|
8
|
+
let(:client) { double }
|
|
9
|
+
|
|
10
|
+
subject do
|
|
11
|
+
described_class.new(prefix: 'prod-myapp-', client: client, project_id: 'example')
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
before do
|
|
15
|
+
@match_item = double
|
|
16
|
+
allow(@match_item).to receive(:name).and_return('prod-myapp-example-test_key')
|
|
17
|
+
|
|
18
|
+
@secret_data = double
|
|
19
|
+
allow(@secret_data).to receive_message_chain(:payload, :data).and_return('secret value')
|
|
20
|
+
|
|
21
|
+
@not_match_item = double
|
|
22
|
+
allow(@not_match_item).to receive(:name).and_return('different_key')
|
|
23
|
+
|
|
24
|
+
@list = double
|
|
25
|
+
allow(@list).to receive(:next_page_token).and_return('')
|
|
26
|
+
allow(@list).to receive(:each).and_yield(@match_item).and_yield(@not_match_item)
|
|
27
|
+
|
|
28
|
+
allow(client).to receive(:project_path).and_return('projects/example')
|
|
29
|
+
allow(client).to receive(:secret_version_path)
|
|
30
|
+
.with(project: 'example', secret: 'prod-myapp-example-test_key', secret_version: 'latest')
|
|
31
|
+
.and_return('some_key_path')
|
|
32
|
+
allow(client).to receive(:access_secret_version).with(name: 'some_key_path').and_return(@secret_data)
|
|
33
|
+
allow(client).to receive(:list_secrets).and_return(@list)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it 'reads parameters from the secret manager' do
|
|
37
|
+
expect(subject.load).to eq({ example: { test_key: 'secret value' }})
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -1,149 +1,163 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
2
4
|
|
|
3
5
|
RSpec.describe Global::Configuration do
|
|
4
|
-
let(:hash){ {
|
|
5
|
-
let(:configuration){ described_class.new hash }
|
|
6
|
+
let(:hash) { { 'key' => 'value', 'boolean_key' => true, 'nested' => { 'key' => 'value' }} }
|
|
7
|
+
let(:configuration) { described_class.new hash }
|
|
6
8
|
|
|
7
|
-
describe
|
|
8
|
-
subject{ configuration.hash }
|
|
9
|
+
describe '#hash' do
|
|
10
|
+
subject { configuration.hash }
|
|
9
11
|
|
|
10
|
-
it{ is_expected.to eq(hash) }
|
|
12
|
+
it { is_expected.to eq(hash) }
|
|
11
13
|
end
|
|
12
14
|
|
|
13
|
-
describe
|
|
14
|
-
subject{ configuration.to_hash }
|
|
15
|
+
describe '#to_hash' do
|
|
16
|
+
subject { configuration.to_hash }
|
|
15
17
|
|
|
16
|
-
it{ is_expected.to eq(hash) }
|
|
18
|
+
it { is_expected.to eq(hash) }
|
|
17
19
|
end
|
|
18
20
|
|
|
19
|
-
describe
|
|
20
|
-
subject{ configuration.key?(:key) }
|
|
21
|
+
describe 'key?' do
|
|
22
|
+
subject { configuration.key?(:key) }
|
|
21
23
|
|
|
22
|
-
it{ is_expected.to be_truthy }
|
|
24
|
+
it { is_expected.to be_truthy }
|
|
23
25
|
end
|
|
24
26
|
|
|
25
|
-
describe
|
|
26
|
-
subject{ configuration.
|
|
27
|
+
describe 'has_key?' do
|
|
28
|
+
subject { configuration.key?(:key) }
|
|
27
29
|
|
|
28
|
-
it{ is_expected.to be_truthy }
|
|
30
|
+
it { is_expected.to be_truthy }
|
|
29
31
|
end
|
|
30
32
|
|
|
31
|
-
describe
|
|
32
|
-
subject{ configuration.include?(:key) }
|
|
33
|
+
describe 'include?' do
|
|
34
|
+
subject { configuration.include?(:key) }
|
|
33
35
|
|
|
34
|
-
it{ is_expected.to be_truthy }
|
|
36
|
+
it { is_expected.to be_truthy }
|
|
35
37
|
end
|
|
36
38
|
|
|
37
|
-
describe
|
|
38
|
-
subject{ configuration.member?(:key) }
|
|
39
|
+
describe 'member?' do
|
|
40
|
+
subject { configuration.member?(:key) }
|
|
39
41
|
|
|
40
|
-
it{ is_expected.to be_truthy }
|
|
42
|
+
it { is_expected.to be_truthy }
|
|
41
43
|
end
|
|
42
44
|
|
|
43
|
-
describe
|
|
44
|
-
subject{ configuration[:key] }
|
|
45
|
+
describe '#[]' do
|
|
46
|
+
subject { configuration[:key] }
|
|
45
47
|
|
|
46
|
-
it{ is_expected.to eq(
|
|
48
|
+
it { is_expected.to eq('value') }
|
|
47
49
|
end
|
|
48
50
|
|
|
49
|
-
describe
|
|
50
|
-
subject{ configuration[:new_key] }
|
|
51
|
+
describe '#[]=' do
|
|
52
|
+
subject { configuration[:new_key] }
|
|
51
53
|
|
|
52
|
-
before{ configuration[:new_key] =
|
|
54
|
+
before { configuration[:new_key] = 'new_value' }
|
|
53
55
|
|
|
54
|
-
it{ is_expected.to eq(
|
|
56
|
+
it { is_expected.to eq('new_value') }
|
|
55
57
|
end
|
|
56
58
|
|
|
57
|
-
describe
|
|
58
|
-
subject{ configuration.inspect }
|
|
59
|
+
describe '#inspect' do
|
|
60
|
+
subject { configuration.inspect }
|
|
59
61
|
|
|
60
|
-
it{ is_expected.to eq(hash.inspect) }
|
|
62
|
+
it { is_expected.to eq(hash.inspect) }
|
|
61
63
|
end
|
|
62
64
|
|
|
63
|
-
describe
|
|
64
|
-
subject{ configuration.filter(filter_options) }
|
|
65
|
+
describe '#filter' do
|
|
66
|
+
subject { configuration.filter(filter_options) }
|
|
65
67
|
|
|
66
|
-
context
|
|
67
|
-
let(:filter_options){ { only: :all } }
|
|
68
|
+
context 'when include all' do
|
|
69
|
+
let(:filter_options) { { only: :all } }
|
|
68
70
|
|
|
69
|
-
it{ should == {
|
|
71
|
+
it { should == { 'key' => 'value', 'boolean_key' => true, 'nested' => { 'key' => 'value' }} }
|
|
70
72
|
end
|
|
71
73
|
|
|
72
|
-
context
|
|
73
|
-
let(:filter_options){ { except: :all } }
|
|
74
|
+
context 'when except all' do
|
|
75
|
+
let(:filter_options) { { except: :all } }
|
|
74
76
|
|
|
75
|
-
it{ should == {} }
|
|
77
|
+
it { should == {} }
|
|
76
78
|
end
|
|
77
79
|
|
|
78
|
-
context
|
|
79
|
-
let(:filter_options){ { except: %w
|
|
80
|
+
context 'when except present' do
|
|
81
|
+
let(:filter_options) { { except: %w[key] } }
|
|
80
82
|
|
|
81
|
-
it{ should == {
|
|
83
|
+
it { should == { 'boolean_key' => true, 'nested' => { 'key' => 'value' }} }
|
|
82
84
|
end
|
|
83
85
|
|
|
84
|
-
context
|
|
85
|
-
let(:filter_options){ { only: %w
|
|
86
|
+
context 'when include present' do
|
|
87
|
+
let(:filter_options) { { only: %w[key] } }
|
|
86
88
|
|
|
87
|
-
it{ should == {
|
|
89
|
+
it { should == { 'key' => 'value' } }
|
|
88
90
|
end
|
|
89
91
|
|
|
90
|
-
context
|
|
91
|
-
let(:filter_options){ {} }
|
|
92
|
+
context 'when empty options' do
|
|
93
|
+
let(:filter_options) { {} }
|
|
92
94
|
|
|
93
|
-
it{ should == {} }
|
|
95
|
+
it { should == {} }
|
|
94
96
|
end
|
|
95
97
|
end
|
|
96
98
|
|
|
97
|
-
describe
|
|
98
|
-
context
|
|
99
|
-
subject{ configuration.key }
|
|
99
|
+
describe '#method_missing' do
|
|
100
|
+
context 'when key exists' do
|
|
101
|
+
subject { configuration.key }
|
|
102
|
+
|
|
103
|
+
it { is_expected.to eq('value') }
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
context 'when boolean key exists' do
|
|
107
|
+
subject { configuration.boolean_key? }
|
|
108
|
+
|
|
109
|
+
it { is_expected.to eq(true) }
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
context 'when key does not exist' do
|
|
113
|
+
subject { configuration.some_key }
|
|
100
114
|
|
|
101
|
-
it{
|
|
115
|
+
it { expect { subject }.to raise_error(NoMethodError) }
|
|
102
116
|
end
|
|
103
117
|
|
|
104
|
-
context
|
|
105
|
-
subject{ configuration.
|
|
118
|
+
context 'when boolean key does not exist' do
|
|
119
|
+
subject { configuration.some_boolean_key? }
|
|
106
120
|
|
|
107
|
-
it{ expect { subject }.to raise_error(NoMethodError) }
|
|
121
|
+
it { expect { subject }.to raise_error(NoMethodError) }
|
|
108
122
|
end
|
|
109
123
|
|
|
110
|
-
context
|
|
111
|
-
subject{ configuration.nested.key }
|
|
124
|
+
context 'with nested hash' do
|
|
125
|
+
subject { configuration.nested.key }
|
|
112
126
|
|
|
113
|
-
it{ is_expected.to eq(
|
|
127
|
+
it { is_expected.to eq('value') }
|
|
114
128
|
end
|
|
115
129
|
end
|
|
116
130
|
|
|
117
|
-
describe
|
|
118
|
-
context
|
|
119
|
-
subject{ configuration.respond_to?(:key) }
|
|
131
|
+
describe '#respond_to_missing?' do
|
|
132
|
+
context 'when key exist' do
|
|
133
|
+
subject { configuration.respond_to?(:key) }
|
|
120
134
|
|
|
121
|
-
it{ is_expected.to eq(true) }
|
|
135
|
+
it { is_expected.to eq(true) }
|
|
122
136
|
end
|
|
123
137
|
|
|
124
|
-
context
|
|
125
|
-
subject{ configuration.respond_to?(:some_key) }
|
|
138
|
+
context 'when key does not exist' do
|
|
139
|
+
subject { configuration.respond_to?(:some_key) }
|
|
126
140
|
|
|
127
|
-
it{ is_expected.to eq(false) }
|
|
141
|
+
it { is_expected.to eq(false) }
|
|
128
142
|
end
|
|
129
143
|
|
|
130
|
-
context
|
|
131
|
-
subject{ configuration.nested.respond_to?(:key) }
|
|
144
|
+
context 'with nested hash' do
|
|
145
|
+
subject { configuration.nested.respond_to?(:key) }
|
|
132
146
|
|
|
133
|
-
it{ is_expected.to eq(true) }
|
|
147
|
+
it { is_expected.to eq(true) }
|
|
134
148
|
end
|
|
135
149
|
|
|
136
|
-
context
|
|
137
|
-
subject{ configuration.method(:key).call }
|
|
150
|
+
context 'when call it by method' do
|
|
151
|
+
subject { configuration.method(:key).call }
|
|
138
152
|
|
|
139
|
-
it{ is_expected.to eq(
|
|
153
|
+
it { is_expected.to eq('value') }
|
|
140
154
|
end
|
|
141
155
|
|
|
142
|
-
context
|
|
156
|
+
context 'when call it by method, which not exist' do
|
|
143
157
|
it 'raise error' do
|
|
144
|
-
expect{ configuration.method(:some_key) }.to raise_error(NameError)
|
|
158
|
+
expect { configuration.method(:some_key) }.to raise_error(NameError)
|
|
145
159
|
end
|
|
146
160
|
end
|
|
147
161
|
end
|
|
148
162
|
|
|
149
|
-
end
|
|
163
|
+
end
|
data/spec/global_spec.rb
CHANGED
|
@@ -1,132 +1,115 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
2
4
|
|
|
3
5
|
RSpec.describe Global do
|
|
4
6
|
|
|
7
|
+
let(:config_path) { File.join(Dir.pwd, 'spec/files') }
|
|
5
8
|
before(:each) do
|
|
6
9
|
described_class.configure do |config|
|
|
7
|
-
config.environment
|
|
8
|
-
config.config_directory = File.join(Dir.pwd, "spec/files")
|
|
9
|
-
end
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
describe ".environment" do
|
|
13
|
-
subject{ described_class.environment }
|
|
14
|
-
|
|
15
|
-
it{ is_expected.to eq("test") }
|
|
16
|
-
|
|
17
|
-
context "when undefined" do
|
|
18
|
-
before{ described_class.environment = nil }
|
|
19
|
-
|
|
20
|
-
it{ expect{ subject }.to raise_error("environment should be defined") }
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
describe ".config_directory" do
|
|
25
|
-
subject{ described_class.config_directory }
|
|
26
|
-
|
|
27
|
-
it{ is_expected.to eq(File.join(Dir.pwd, "spec/files"))}
|
|
28
|
-
|
|
29
|
-
context "when undefined" do
|
|
30
|
-
before{ described_class.config_directory = nil }
|
|
31
|
-
|
|
32
|
-
it{ expect{ subject }.to raise_error("config_directory should be defined") }
|
|
10
|
+
config.backend :filesystem, path: config_path, environment: 'test'
|
|
33
11
|
end
|
|
34
12
|
end
|
|
35
13
|
|
|
36
|
-
describe
|
|
37
|
-
subject{ described_class.configuration }
|
|
14
|
+
describe '.configuration' do
|
|
15
|
+
subject { described_class.configuration }
|
|
38
16
|
|
|
39
|
-
it{ is_expected.to be_instance_of(Global::Configuration) }
|
|
17
|
+
it { is_expected.to be_instance_of(Global::Configuration) }
|
|
40
18
|
|
|
41
|
-
context
|
|
19
|
+
context 'when load from directory' do
|
|
42
20
|
describe '#rspec_config' do
|
|
43
21
|
subject { super().rspec_config }
|
|
44
22
|
describe '#to_hash' do
|
|
45
23
|
subject { super().to_hash }
|
|
46
|
-
it { is_expected.to eq(
|
|
24
|
+
it { is_expected.to eq('default_value' => 'default value', 'test_value' => 'test value') }
|
|
47
25
|
end
|
|
48
26
|
end
|
|
49
27
|
end
|
|
50
28
|
|
|
51
|
-
context
|
|
52
|
-
|
|
29
|
+
context 'when load from file' do
|
|
30
|
+
let(:config_path) { File.join(Dir.pwd, 'spec/files/rspec_config') }
|
|
53
31
|
|
|
54
32
|
describe '#rspec_config' do
|
|
55
|
-
subject { super().rspec_config }
|
|
56
33
|
describe '#to_hash' do
|
|
57
34
|
subject { super().to_hash }
|
|
58
|
-
it { is_expected.to eq(
|
|
35
|
+
it { is_expected.to eq('default_value' => 'default value', 'test_value' => 'test value') }
|
|
59
36
|
end
|
|
60
37
|
end
|
|
61
38
|
end
|
|
62
39
|
|
|
63
|
-
context
|
|
64
|
-
it{ expect(subject.rspec[
|
|
40
|
+
context 'when nested directories' do
|
|
41
|
+
it { expect(subject.rspec['config'].to_hash).to eq('default_value' => 'default nested value', 'test_value' => 'test nested value') }
|
|
65
42
|
end
|
|
66
43
|
|
|
67
|
-
context
|
|
68
|
-
it{ expect(subject.bool_config.works).to eq(true) }
|
|
69
|
-
it{ expect(subject.bool_config.works?).to eq(true) }
|
|
44
|
+
context 'when boolean' do
|
|
45
|
+
it { expect(subject.bool_config.works).to eq(true) }
|
|
46
|
+
it { expect(subject.bool_config.works?).to eq(true) }
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
context 'environment file' do
|
|
50
|
+
it { expect(subject.aws.activated).to eq(true) }
|
|
51
|
+
it { expect(subject.aws.api_key).to eq('some api key') }
|
|
52
|
+
it { expect(subject.aws.api_secret).to eq('some secret') }
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
context 'skip files with dots in name' do
|
|
56
|
+
it { expect(subject['aws.test']).to eq(nil) }
|
|
57
|
+
it { expect { subject.fetch('aws.test') }.to raise_error(KeyError, /key not found/) }
|
|
70
58
|
end
|
|
71
59
|
end
|
|
72
60
|
|
|
73
|
-
context
|
|
74
|
-
subject{ described_class.reload! }
|
|
61
|
+
context '.reload!' do
|
|
62
|
+
subject { described_class.reload! }
|
|
75
63
|
|
|
76
64
|
before do
|
|
77
65
|
described_class.configuration
|
|
78
|
-
described_class.
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
after do
|
|
82
|
-
described_class.environment = "test"
|
|
83
|
-
described_class.reload!
|
|
66
|
+
described_class.instance_variable_set('@backends', [])
|
|
67
|
+
described_class.backend :filesystem, path: config_path, environment: 'development'
|
|
84
68
|
end
|
|
85
69
|
|
|
86
|
-
it{ is_expected.to be_instance_of(Global::Configuration) }
|
|
70
|
+
it { is_expected.to be_instance_of(Global::Configuration) }
|
|
87
71
|
|
|
88
72
|
describe '#rspec_config' do
|
|
89
73
|
subject { super().rspec_config }
|
|
90
74
|
describe '#to_hash' do
|
|
91
75
|
subject { super().to_hash }
|
|
92
|
-
it { is_expected.to eq(
|
|
76
|
+
it { is_expected.to eq('default_value' => 'default value', 'test_value' => 'development value') }
|
|
93
77
|
end
|
|
94
78
|
end
|
|
95
79
|
end
|
|
96
|
-
|
|
97
|
-
describe ".respond_to_missing?" do
|
|
98
|
-
context "when file exists" do
|
|
99
|
-
subject{ described_class.respond_to?(:rspec_config) }
|
|
100
80
|
|
|
101
|
-
|
|
81
|
+
describe '.respond_to_missing?' do
|
|
82
|
+
context 'when file exists' do
|
|
83
|
+
subject { described_class.respond_to?(:rspec_config) }
|
|
84
|
+
|
|
85
|
+
it { is_expected.to be_truthy }
|
|
102
86
|
end
|
|
103
87
|
|
|
104
|
-
context
|
|
105
|
-
subject{ described_class.respond_to?(:some_file) }
|
|
88
|
+
context 'when file does not exist' do
|
|
89
|
+
subject { described_class.respond_to?(:some_file) }
|
|
106
90
|
|
|
107
|
-
it{ is_expected.to be_falsey }
|
|
91
|
+
it { is_expected.to be_falsey }
|
|
108
92
|
end
|
|
109
93
|
end
|
|
110
94
|
|
|
111
|
-
describe
|
|
112
|
-
context
|
|
113
|
-
subject{ described_class.rspec_config }
|
|
95
|
+
describe '.method_missing' do
|
|
96
|
+
context 'when file exists' do
|
|
97
|
+
subject { described_class.rspec_config }
|
|
114
98
|
|
|
115
|
-
it{ is_expected.to
|
|
99
|
+
it { is_expected.to be_kind_of(Global::Configuration) }
|
|
116
100
|
end
|
|
117
101
|
|
|
118
|
-
context
|
|
119
|
-
subject{ described_class.some_file }
|
|
102
|
+
context 'when file does not exist' do
|
|
103
|
+
subject { described_class.some_file }
|
|
120
104
|
|
|
121
|
-
it{ expect{ subject }.to raise_error(NoMethodError) }
|
|
105
|
+
it { expect { subject }.to raise_error(NoMethodError) }
|
|
122
106
|
end
|
|
123
107
|
|
|
124
|
-
context
|
|
125
|
-
subject{ described_class.nested_config }
|
|
108
|
+
context 'when file with nested hash' do
|
|
109
|
+
subject { described_class.nested_config }
|
|
126
110
|
|
|
127
|
-
it{ is_expected.to be_kind_of(Global::Configuration) }
|
|
111
|
+
it { is_expected.to be_kind_of(Global::Configuration) }
|
|
128
112
|
end
|
|
129
113
|
|
|
130
114
|
end
|
|
131
|
-
|
|
132
115
|
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
RSpec.describe Global do
|
|
6
|
+
describe 'merging backends' do
|
|
7
|
+
it 'merges data from two backends together' do
|
|
8
|
+
backend_alpha = double('backend_alpha')
|
|
9
|
+
allow(backend_alpha).to receive(:load).and_return(foo: 'foo', bar: 'bar-alpha')
|
|
10
|
+
described_class.backend backend_alpha
|
|
11
|
+
|
|
12
|
+
backend_beta = double('backend_beta')
|
|
13
|
+
allow(backend_beta).to receive(:load).and_return('bar' => 'bar-beta', 'baz' => 'baz')
|
|
14
|
+
described_class.backend backend_beta
|
|
15
|
+
|
|
16
|
+
expect(described_class.configuration.to_hash).to eq(
|
|
17
|
+
'foo' => 'foo',
|
|
18
|
+
'bar' => 'bar-beta',
|
|
19
|
+
'baz' => 'baz'
|
|
20
|
+
)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
#
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
4
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
5
5
|
require 'rspec'
|
|
6
6
|
require 'global'
|
|
7
7
|
require 'simplecov'
|
|
8
|
-
require 'support/javascript_helper'
|
|
9
8
|
|
|
10
9
|
SimpleCov.start do
|
|
11
10
|
add_filter '/spec/'
|
|
@@ -39,5 +38,9 @@ RSpec.configure do |config|
|
|
|
39
38
|
config.filter_run :focus
|
|
40
39
|
|
|
41
40
|
config.order = 'random'
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
|
|
42
|
+
config.before do
|
|
43
|
+
Global.remove_instance_variable(:@backends) if Global.instance_variable_defined?(:@backends)
|
|
44
|
+
Global.remove_instance_variable(:@configuration) if Global.instance_variable_defined?(:@configuration)
|
|
45
|
+
end
|
|
46
|
+
end
|