fedux_org-stdlib 0.8.8 → 0.8.9
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
- data/Gemfile +2 -2
- data/Gemfile.lock +1 -1
- data/lib/fedux_org_stdlib/app_config.rb +8 -1
- data/lib/fedux_org_stdlib/directory_finder.rb +1 -3
- data/lib/fedux_org_stdlib/file_finder.rb +1 -3
- data/lib/fedux_org_stdlib/gem_plugins/plugin.rb +1 -1
- data/lib/fedux_org_stdlib/gem_plugins/plugin_manager.rb +4 -4
- data/lib/fedux_org_stdlib/list.rb +1 -1
- data/lib/fedux_org_stdlib/locale_configurator.rb +1 -0
- data/lib/fedux_org_stdlib/version.rb +1 -1
- data/spec/app_config_spec.rb +234 -248
- data/spec/gem_plugins/plugin_manager_spec.rb +2 -2
- data/spec/support/aruba.rb +12 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f62d5a27aedacb625f6f8eb5f6aea8ea4d9a35ee
|
4
|
+
data.tar.gz: f8a311b2d482357f56fda9685b9607429b59a56f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7fbf474910a832397d28f4a1787ca11b9eca0fb99cd72867cb325a1d24e1c983762891d50bfa08d926ba22f3d87d1ab57fcf4976c9046cbc142e8f7d1da603dd
|
7
|
+
data.tar.gz: 885cf2b6525b40e84b82ce9caf57ebe39a724b7cdb6ae06b846356baf48711eab2963f1eba6f4ba2879a545678bfbcd23066e5e245daf06c6543b5bfa68f1b8e
|
data/Gemfile
CHANGED
@@ -41,8 +41,8 @@ group :development, :test do
|
|
41
41
|
gem 'travis-lint'
|
42
42
|
gem 'facter'
|
43
43
|
gem 'hirb'
|
44
|
-
#gem 'tty'
|
44
|
+
# gem 'tty'
|
45
45
|
|
46
46
|
gem 'fedux_org_stdlib-fixtures-plugin_manager-load', require: false, path: File.expand_path('../fixtures/plugin-load-app', __FILE__)
|
47
|
-
# gem 'fedux_org_stdlib-fixtures-plugin_manager-no_load', require: false, path: File.expand_path('../fixtures/plugin-no_load-app', __FILE__)
|
47
|
+
# gem 'fedux_org_stdlib-fixtures-plugin_manager-no_load', require: false, path: File.expand_path('../fixtures/plugin-no_load-app', __FILE__)
|
48
48
|
end
|
data/Gemfile.lock
CHANGED
@@ -259,6 +259,14 @@ module FeduxOrgStdlib
|
|
259
259
|
_allowed_config_file_paths.first
|
260
260
|
end
|
261
261
|
|
262
|
+
# Return configuration resetted to defaults
|
263
|
+
def defaults
|
264
|
+
config = self.dup
|
265
|
+
config.instance_variable_set :'@__config', {}
|
266
|
+
|
267
|
+
config
|
268
|
+
end
|
269
|
+
|
262
270
|
private
|
263
271
|
|
264
272
|
def detect_file
|
@@ -296,7 +304,6 @@ module FeduxOrgStdlib
|
|
296
304
|
end
|
297
305
|
end
|
298
306
|
|
299
|
-
|
300
307
|
# The name of the config file
|
301
308
|
#
|
302
309
|
# @return [String]
|
@@ -71,9 +71,7 @@ module FeduxOrgStdlib
|
|
71
71
|
@working_directory = working_directory
|
72
72
|
@directory ||= (directory || _available_directory)
|
73
73
|
|
74
|
-
unless directory
|
75
|
-
logger.debug "No config directory found at #{_allowed_directory_paths.to_list}, therefor I'm going to use an empty config object instead."
|
76
|
-
end
|
74
|
+
logger.debug "No config directory found at #{_allowed_directory_paths.to_list}, therefor I'm going to use an empty config object instead." unless directory
|
77
75
|
end
|
78
76
|
|
79
77
|
# Return the path to the preferred config file
|
@@ -72,9 +72,7 @@ module FeduxOrgStdlib
|
|
72
72
|
@working_directory = working_directory
|
73
73
|
@file ||= (file || _available_config_file)
|
74
74
|
|
75
|
-
unless file
|
76
|
-
logger.debug "No configuration file found at #{_allowed_config_file_paths.to_list}, therefor I'm going to use an empty config object instead."
|
77
|
-
end
|
75
|
+
logger.debug "No configuration file found at #{_allowed_config_file_paths.to_list}, therefor I'm going to use an empty config object instead." unless file
|
78
76
|
end
|
79
77
|
|
80
78
|
# Return the path to the preferred configuration file
|
@@ -13,7 +13,7 @@ module FeduxOrgStdlib
|
|
13
13
|
|
14
14
|
def initialize(spec:)
|
15
15
|
@name = spec.name
|
16
|
-
@author = Array(spec.authors).zip(Array(spec.email)).map { |a, e| format(
|
16
|
+
@author = Array(spec.authors).zip(Array(spec.email)).map { |a, e| format('%s (%s)', a, e) }.to_list
|
17
17
|
@version = spec.version
|
18
18
|
@homagepage = spec.homepage
|
19
19
|
@active = false
|
@@ -91,15 +91,15 @@ module FeduxOrgStdlib
|
|
91
91
|
|
92
92
|
# String representation
|
93
93
|
def to_s
|
94
|
-
data = plugins.sort.reduce([]) do |a, e|
|
95
|
-
a << {
|
94
|
+
data = plugins.sort.reduce([]) do |a, e|
|
95
|
+
a << {
|
96
96
|
name: e.name,
|
97
97
|
version: e.version,
|
98
98
|
author: e.author,
|
99
99
|
homepage: e.homepage,
|
100
100
|
activated: e.active?,
|
101
|
-
require_file: e.require_file
|
102
|
-
}
|
101
|
+
require_file: e.require_file
|
102
|
+
}
|
103
103
|
end
|
104
104
|
|
105
105
|
List.new(data).to_s(
|
@@ -27,6 +27,7 @@ module FeduxOrgStdlib
|
|
27
27
|
@pattern = File.join(path, '*.yml')
|
28
28
|
@detector = detector
|
29
29
|
@detected_locale = detect_locale(overwrite: default_locale)
|
30
|
+
@logger = logger
|
30
31
|
|
31
32
|
I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks)
|
32
33
|
I18n.load_path = locale_files
|
data/spec/app_config_spec.rb
CHANGED
@@ -6,31 +6,52 @@ RSpec.describe AppConfig do
|
|
6
6
|
|
7
7
|
context 'options' do
|
8
8
|
it 'creates readers and writers' do
|
9
|
-
|
10
|
-
|
11
|
-
option :opt1, nil
|
9
|
+
config_klass = Class.new(AppConfig) do
|
10
|
+
option :opt1, nil
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
def _class_name
|
13
|
+
'TestConfig'
|
14
|
+
end
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
end
|
16
|
+
def _module_name
|
17
|
+
'MyApplication'
|
20
18
|
end
|
19
|
+
end
|
21
20
|
|
22
|
-
|
23
|
-
|
21
|
+
config = config_klass.new
|
22
|
+
expect(config.opt1).to be_nil
|
24
23
|
|
25
|
-
|
26
|
-
|
27
|
-
end
|
24
|
+
config.opt1 = 'blub'
|
25
|
+
expect(config.opt1).to eq 'blub'
|
28
26
|
end
|
29
27
|
|
30
28
|
it 'creates readers' do
|
31
|
-
|
32
|
-
|
33
|
-
|
29
|
+
config_klass = Class.new(AppConfig) do
|
30
|
+
option_reader :opt1, nil
|
31
|
+
|
32
|
+
def _class_name
|
33
|
+
'TestConfig'
|
34
|
+
end
|
35
|
+
|
36
|
+
def _module_name
|
37
|
+
'MyApplication'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
config = config_klass.new
|
42
|
+
expect(config.opt1).to be_nil
|
43
|
+
|
44
|
+
silence :stderr do
|
45
|
+
expect do
|
46
|
+
config.opt1 = 'blub'
|
47
|
+
end.to raise_error NoMethodError
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'checks for reserved key words' do
|
52
|
+
expect do
|
53
|
+
Class.new(AppConfig) do
|
54
|
+
option_reader :_config_file, nil
|
34
55
|
|
35
56
|
def _class_name
|
36
57
|
'TestConfig'
|
@@ -40,222 +61,201 @@ RSpec.describe AppConfig do
|
|
40
61
|
'MyApplication'
|
41
62
|
end
|
42
63
|
end
|
64
|
+
end.to raise_error FeduxOrgStdlib::AppConfig::Exceptions::OptionNameForbidden
|
65
|
+
end
|
43
66
|
|
44
|
-
|
45
|
-
|
67
|
+
it 'output default values' do
|
68
|
+
config_klass = Class.new(AppConfig) do
|
69
|
+
option_reader :opt1, 'foobar'
|
46
70
|
|
47
|
-
|
48
|
-
|
49
|
-
config.opt1 = 'blub'
|
50
|
-
end.to raise_error NoMethodError
|
71
|
+
def _class_name
|
72
|
+
'TestConfig'
|
51
73
|
end
|
52
|
-
end
|
53
|
-
end
|
54
74
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
option_reader :_config_file, nil
|
75
|
+
def _module_name
|
76
|
+
'MyApplication'
|
77
|
+
end
|
78
|
+
end
|
60
79
|
|
61
|
-
|
62
|
-
|
63
|
-
|
80
|
+
write_file '~/.tests.yaml', <<-EOS.strip_heredoc
|
81
|
+
---
|
82
|
+
opt1: hello world
|
83
|
+
EOS
|
64
84
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
end
|
69
|
-
end.to raise_error FeduxOrgStdlib::AppConfig::Exceptions::OptionNameForbidden
|
70
|
-
end
|
85
|
+
config = config_klass.new
|
86
|
+
expect(config.defaults.opt1).to eq 'foobar'
|
87
|
+
expect(config.opt1).to eq 'hello world'
|
71
88
|
end
|
72
89
|
end
|
73
90
|
|
74
91
|
context '#lock' do
|
75
92
|
it 'raises error if config is locked and one tries to modify a config option' do
|
76
|
-
|
77
|
-
|
78
|
-
option :opt1, nil
|
79
|
-
|
80
|
-
def _class_name
|
81
|
-
'TestConfig'
|
82
|
-
end
|
93
|
+
config_klass = Class.new(AppConfig) do
|
94
|
+
option :opt1, nil
|
83
95
|
|
84
|
-
|
85
|
-
|
86
|
-
end
|
96
|
+
def _class_name
|
97
|
+
'TestConfig'
|
87
98
|
end
|
88
99
|
|
89
|
-
|
90
|
-
|
91
|
-
|
100
|
+
def _module_name
|
101
|
+
'MyApplication'
|
102
|
+
end
|
92
103
|
end
|
104
|
+
|
105
|
+
config = config_klass.new
|
106
|
+
config.lock
|
107
|
+
expect { config.opt1 = 1 }.to raise_error FeduxOrgStdlib::AppConfig::Exceptions::ConfigLocked
|
93
108
|
end
|
94
109
|
end
|
95
110
|
|
96
111
|
context '#preferred_configuration_file' do
|
97
112
|
it 'has a default configuration file which is the preferred place to store the configuration' do
|
98
|
-
|
99
|
-
config_klass = Class.new(AppConfig) do
|
100
|
-
|
101
|
-
def _class_name
|
102
|
-
'TestConfig'
|
103
|
-
end
|
113
|
+
config_klass = Class.new(AppConfig) do
|
104
114
|
|
105
|
-
|
106
|
-
|
107
|
-
end
|
115
|
+
def _class_name
|
116
|
+
'TestConfig'
|
108
117
|
end
|
109
118
|
|
110
|
-
|
111
|
-
|
119
|
+
def _module_name
|
120
|
+
'MyApplication'
|
121
|
+
end
|
112
122
|
end
|
123
|
+
|
124
|
+
config = config_klass.new
|
125
|
+
expect(config.preferred_configuration_file).to eq File.expand_path('~/.config/my_application/tests.yaml')
|
113
126
|
end
|
114
127
|
|
115
128
|
it 'works with nested module names' do
|
116
|
-
|
117
|
-
config_klass = Class.new(AppConfig) do
|
118
|
-
|
119
|
-
def _class_name
|
120
|
-
'TestConfig'
|
121
|
-
end
|
129
|
+
config_klass = Class.new(AppConfig) do
|
122
130
|
|
123
|
-
|
124
|
-
|
125
|
-
end
|
131
|
+
def _class_name
|
132
|
+
'TestConfig'
|
126
133
|
end
|
127
134
|
|
128
|
-
|
129
|
-
|
135
|
+
def _module_name
|
136
|
+
'MyApplication::MySub'
|
137
|
+
end
|
130
138
|
end
|
139
|
+
|
140
|
+
config = config_klass.new
|
141
|
+
expect(config.preferred_configuration_file).to eq File.expand_path('~/.config/my_application/my_sub/tests.yaml')
|
131
142
|
end
|
132
143
|
end
|
133
144
|
|
134
145
|
context 'config files' do
|
135
146
|
|
136
147
|
it 'looks at ~/.test.yaml' do
|
137
|
-
|
138
|
-
write_file '.tests.yaml', <<-EOS.strip_heredoc
|
148
|
+
write_file '.tests.yaml', <<-EOS.strip_heredoc
|
139
149
|
---
|
140
150
|
opt1: hello world
|
141
|
-
|
142
|
-
|
143
|
-
config_klass = Class.new(AppConfig) do
|
144
|
-
option_reader :opt1, nil
|
151
|
+
EOS
|
145
152
|
|
146
|
-
|
147
|
-
|
148
|
-
end
|
153
|
+
config_klass = Class.new(AppConfig) do
|
154
|
+
option_reader :opt1, nil
|
149
155
|
|
150
|
-
|
151
|
-
|
152
|
-
end
|
156
|
+
def _class_name
|
157
|
+
'TestConfig'
|
153
158
|
end
|
154
159
|
|
155
|
-
|
156
|
-
|
160
|
+
def _module_name
|
161
|
+
'MyApplication'
|
162
|
+
end
|
157
163
|
end
|
164
|
+
|
165
|
+
config = config_klass.new
|
166
|
+
expect(config.opt1).to eq 'hello world'
|
158
167
|
end
|
159
168
|
|
160
169
|
it 'looks at ~/.config/my_application/tests.yaml' do
|
161
|
-
|
162
|
-
write_file '.config/my_application/tests.yaml', <<-EOS.strip_heredoc
|
170
|
+
write_file '.config/my_application/tests.yaml', <<-EOS.strip_heredoc
|
163
171
|
---
|
164
172
|
opt1: hello world
|
165
|
-
|
166
|
-
|
167
|
-
config_klass = Class.new(AppConfig) do
|
168
|
-
option_reader :opt1, nil
|
173
|
+
EOS
|
169
174
|
|
170
|
-
|
171
|
-
|
172
|
-
end
|
175
|
+
config_klass = Class.new(AppConfig) do
|
176
|
+
option_reader :opt1, nil
|
173
177
|
|
174
|
-
|
175
|
-
|
176
|
-
end
|
178
|
+
def _class_name
|
179
|
+
'TestConfig'
|
177
180
|
end
|
178
181
|
|
179
|
-
|
180
|
-
|
182
|
+
def _module_name
|
183
|
+
'MyApplication'
|
184
|
+
end
|
181
185
|
end
|
186
|
+
|
187
|
+
config = config_klass.new
|
188
|
+
expect(config.opt1).to eq 'hello world'
|
182
189
|
end
|
183
190
|
|
184
191
|
it 'looks at ~/.my_application/tests.yaml' do
|
185
|
-
|
186
|
-
write_file '.my_application/tests.yaml', <<-EOS.strip_heredoc
|
192
|
+
write_file '.my_application/tests.yaml', <<-EOS.strip_heredoc
|
187
193
|
---
|
188
194
|
opt1: hello world
|
189
|
-
|
190
|
-
|
191
|
-
config_klass = Class.new(AppConfig) do
|
192
|
-
option_reader :opt1, nil
|
195
|
+
EOS
|
193
196
|
|
194
|
-
|
195
|
-
|
196
|
-
end
|
197
|
+
config_klass = Class.new(AppConfig) do
|
198
|
+
option_reader :opt1, nil
|
197
199
|
|
198
|
-
|
199
|
-
|
200
|
-
end
|
200
|
+
def _class_name
|
201
|
+
'TestConfig'
|
201
202
|
end
|
202
203
|
|
203
|
-
|
204
|
-
|
204
|
+
def _module_name
|
205
|
+
'MyApplication'
|
206
|
+
end
|
205
207
|
end
|
208
|
+
|
209
|
+
config = config_klass.new
|
210
|
+
expect(config.opt1).to eq 'hello world'
|
206
211
|
end
|
207
212
|
|
208
213
|
it 'looks at ~/.tests.yaml' do
|
209
|
-
|
210
|
-
write_file '.tests.yaml', <<-EOS.strip_heredoc
|
214
|
+
write_file '.tests.yaml', <<-EOS.strip_heredoc
|
211
215
|
---
|
212
216
|
opt1: hello world
|
213
|
-
|
214
|
-
|
215
|
-
config_klass = Class.new(AppConfig) do
|
216
|
-
option_reader :opt1, nil
|
217
|
+
EOS
|
217
218
|
|
218
|
-
|
219
|
-
|
220
|
-
end
|
219
|
+
config_klass = Class.new(AppConfig) do
|
220
|
+
option_reader :opt1, nil
|
221
221
|
|
222
|
-
|
223
|
-
|
224
|
-
end
|
222
|
+
def _class_name
|
223
|
+
'TestConfig'
|
225
224
|
end
|
226
225
|
|
227
|
-
|
228
|
-
|
226
|
+
def _module_name
|
227
|
+
'MyApplication'
|
228
|
+
end
|
229
229
|
end
|
230
|
+
|
231
|
+
config = config_klass.new
|
232
|
+
expect(config.opt1).to eq 'hello world'
|
230
233
|
end
|
231
234
|
|
232
235
|
it 'looks at ~/.testsrc' do
|
233
|
-
|
234
|
-
write_file '.testsrc', <<-EOS.strip_heredoc
|
236
|
+
write_file '.testsrc', <<-EOS.strip_heredoc
|
235
237
|
---
|
236
238
|
opt1: hello world
|
237
|
-
|
238
|
-
|
239
|
-
config_klass = Class.new(AppConfig) do
|
240
|
-
option_reader :opt1, nil
|
239
|
+
EOS
|
241
240
|
|
242
|
-
|
243
|
-
|
244
|
-
end
|
241
|
+
config_klass = Class.new(AppConfig) do
|
242
|
+
option_reader :opt1, nil
|
245
243
|
|
246
|
-
|
247
|
-
|
248
|
-
end
|
244
|
+
def _class_name
|
245
|
+
'TestConfig'
|
249
246
|
end
|
250
247
|
|
251
|
-
|
252
|
-
|
248
|
+
def _module_name
|
249
|
+
'MyApplication'
|
250
|
+
end
|
253
251
|
end
|
252
|
+
|
253
|
+
config = config_klass.new
|
254
|
+
expect(config.opt1).to eq 'hello world'
|
254
255
|
end
|
255
256
|
|
256
257
|
it 'loads yaml files with the following data types' do
|
257
|
-
|
258
|
-
write_file '.testsrc', <<-EOS.strip_heredoc
|
258
|
+
write_file '.testsrc', <<-EOS.strip_heredoc
|
259
259
|
---
|
260
260
|
opt1: hello world
|
261
261
|
opt2: :test
|
@@ -267,131 +267,122 @@ RSpec.describe AppConfig do
|
|
267
267
|
- b
|
268
268
|
opt7:
|
269
269
|
name: berni
|
270
|
-
|
271
|
-
|
272
|
-
config_klass = Class.new(AppConfig) do
|
273
|
-
option_reader :opt1, nil
|
274
|
-
option_reader :opt2, nil
|
275
|
-
option_reader :opt3, nil
|
276
|
-
option_reader :opt4, nil
|
277
|
-
option_reader :opt5, nil
|
278
|
-
option_reader :opt6, nil
|
279
|
-
option_reader :opt7, nil
|
270
|
+
EOS
|
280
271
|
|
281
|
-
|
282
|
-
|
283
|
-
|
272
|
+
config_klass = Class.new(AppConfig) do
|
273
|
+
option_reader :opt1, nil
|
274
|
+
option_reader :opt2, nil
|
275
|
+
option_reader :opt3, nil
|
276
|
+
option_reader :opt4, nil
|
277
|
+
option_reader :opt5, nil
|
278
|
+
option_reader :opt6, nil
|
279
|
+
option_reader :opt7, nil
|
284
280
|
|
285
|
-
|
286
|
-
|
287
|
-
end
|
281
|
+
def _class_name
|
282
|
+
'TestConfig'
|
288
283
|
end
|
289
284
|
|
290
|
-
|
291
|
-
|
285
|
+
def _module_name
|
286
|
+
'MyApplication'
|
287
|
+
end
|
292
288
|
end
|
289
|
+
|
290
|
+
config = config_klass.new
|
291
|
+
expect(config.opt1).to eq 'hello world'
|
293
292
|
end
|
294
293
|
|
295
294
|
it 'raises error on invalid yaml file' do
|
296
|
-
|
297
|
-
write_file '.testsrc', random_binary_string(100)
|
298
|
-
|
299
|
-
config_klass = Class.new(AppConfig) do
|
300
|
-
def _class_name
|
301
|
-
'TestConfig'
|
302
|
-
end
|
295
|
+
write_file '.testsrc', random_binary_string(100)
|
303
296
|
|
304
|
-
|
305
|
-
|
306
|
-
|
297
|
+
config_klass = Class.new(AppConfig) do
|
298
|
+
def _class_name
|
299
|
+
'TestConfig'
|
307
300
|
end
|
308
301
|
|
309
|
-
|
302
|
+
def _module_name
|
303
|
+
'MyApplication'
|
304
|
+
end
|
310
305
|
end
|
306
|
+
|
307
|
+
expect { config_klass.new }.to raise_error FeduxOrgStdlib::AppConfig::Exceptions::ConfigFileNotReadable
|
311
308
|
end
|
312
309
|
|
313
310
|
it 'returns an empty config if data file cannot be transformed to hash' do
|
314
|
-
|
315
|
-
write_file '.testsrc', <<-EOS.strip_heredoc
|
311
|
+
write_file '.testsrc', <<-EOS.strip_heredoc
|
316
312
|
---
|
317
313
|
- hello
|
318
314
|
- world
|
319
|
-
|
320
|
-
|
321
|
-
config_klass = Class.new(AppConfig) do
|
322
|
-
def _class_name
|
323
|
-
'TestConfig'
|
324
|
-
end
|
315
|
+
EOS
|
325
316
|
|
326
|
-
|
327
|
-
|
328
|
-
|
317
|
+
config_klass = Class.new(AppConfig) do
|
318
|
+
def _class_name
|
319
|
+
'TestConfig'
|
329
320
|
end
|
330
321
|
|
331
|
-
|
332
|
-
|
322
|
+
def _module_name
|
323
|
+
'MyApplication'
|
333
324
|
end
|
325
|
+
end
|
334
326
|
|
335
|
-
|
327
|
+
result = capture :stderr do
|
328
|
+
config_klass.new
|
336
329
|
end
|
330
|
+
|
331
|
+
expect(result).to include 'There seems'
|
337
332
|
end
|
338
333
|
end
|
339
334
|
|
340
335
|
context '#to_s' do
|
341
336
|
it 'outputs a list of variables' do
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
option :opt3, opt1: 'test1', opt2: 'test2'
|
337
|
+
config_klass = Class.new(AppConfig) do
|
338
|
+
option :opt1, 'test1'
|
339
|
+
option :opt2, 'test2'
|
340
|
+
option :opt3, opt1: 'test1', opt2: 'test2'
|
347
341
|
|
348
|
-
|
349
|
-
|
350
|
-
|
342
|
+
def _class_name
|
343
|
+
'TestConfig'
|
344
|
+
end
|
351
345
|
|
352
|
-
|
353
|
-
|
354
|
-
end
|
346
|
+
def _module_name
|
347
|
+
'MyApplication'
|
355
348
|
end
|
349
|
+
end
|
356
350
|
|
357
|
-
|
358
|
-
|
351
|
+
config = config_klass.new
|
352
|
+
expect(config.to_s).to eq <<-EOS.strip_heredoc.chomp
|
359
353
|
option | value
|
360
354
|
------ + --------------------------------------------------------------------------------
|
361
355
|
opt1 | "test1"
|
362
356
|
opt2 | "test2"
|
363
357
|
opt3 | "opt1: test1", "opt2: test2"
|
364
|
-
|
365
|
-
end
|
358
|
+
EOS
|
366
359
|
end
|
367
360
|
|
368
361
|
it 'outputs is undefined for blank values (nil, '', ...)' do
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
option :opt4, false
|
362
|
+
config_klass = Class.new(AppConfig) do
|
363
|
+
option :opt1, nil
|
364
|
+
option :opt2, ''
|
365
|
+
option :opt3, 'asdf'
|
366
|
+
option :opt4, false
|
375
367
|
|
376
|
-
|
377
|
-
|
378
|
-
|
368
|
+
def _class_name
|
369
|
+
'TestConfig'
|
370
|
+
end
|
379
371
|
|
380
|
-
|
381
|
-
|
382
|
-
end
|
372
|
+
def _module_name
|
373
|
+
'MyApplication'
|
383
374
|
end
|
375
|
+
end
|
384
376
|
|
385
|
-
|
386
|
-
|
377
|
+
config = config_klass.new
|
378
|
+
expect(config.to_s).to eq <<-EOS.strip_heredoc.chomp
|
387
379
|
option | value
|
388
380
|
------ + --------------------------------------------------------------------------------
|
389
381
|
opt1 | "is undefined"
|
390
382
|
opt2 | "is undefined"
|
391
383
|
opt3 | "asdf"
|
392
384
|
opt4 | "false"
|
393
|
-
|
394
|
-
end
|
385
|
+
EOS
|
395
386
|
end
|
396
387
|
end
|
397
388
|
|
@@ -445,52 +436,47 @@ RSpec.describe AppConfig do
|
|
445
436
|
end
|
446
437
|
end
|
447
438
|
|
448
|
-
|
449
|
-
write_file 'tests.yaml', <<-EOS.strip_heredoc
|
439
|
+
write_file 'tests.yaml', <<-EOS.strip_heredoc
|
450
440
|
---
|
451
441
|
opt1: test2
|
452
|
-
|
442
|
+
EOS
|
453
443
|
|
454
|
-
|
455
|
-
|
456
|
-
|
444
|
+
config = in_current_dir do
|
445
|
+
config_klass.new
|
446
|
+
end
|
457
447
|
|
458
|
-
|
448
|
+
expect(config.opt1).to eq 'test2'
|
459
449
|
|
460
|
-
|
450
|
+
write_file '~/.config/my_application/tests.yaml', <<-EOS.strip_heredoc
|
461
451
|
---
|
462
452
|
opt1: test3
|
463
|
-
|
453
|
+
EOS
|
464
454
|
|
465
|
-
|
455
|
+
config.redetect
|
466
456
|
|
467
|
-
|
468
|
-
end
|
457
|
+
expect(config.opt1).to eq 'test3'
|
469
458
|
end
|
470
|
-
|
471
459
|
end
|
472
460
|
|
473
461
|
context '#known_options' do
|
474
462
|
it 'outputs a list of known options' do
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
option :opt3, opt1: 'test1', opt2: 'test2'
|
480
|
-
|
481
|
-
def _class_name
|
482
|
-
'TestConfig'
|
483
|
-
end
|
463
|
+
config_klass = Class.new(AppConfig) do
|
464
|
+
option :opt1, 'test1'
|
465
|
+
option :opt2, 'test2'
|
466
|
+
option :opt3, opt1: 'test1', opt2: 'test2'
|
484
467
|
|
485
|
-
|
486
|
-
|
487
|
-
end
|
468
|
+
def _class_name
|
469
|
+
'TestConfig'
|
488
470
|
end
|
489
471
|
|
490
|
-
|
491
|
-
|
492
|
-
|
472
|
+
def _module_name
|
473
|
+
'MyApplication'
|
474
|
+
end
|
493
475
|
end
|
476
|
+
|
477
|
+
config = config_klass.new
|
478
|
+
expect(config.known_options).to include :opt1, :opt2, :opt3
|
479
|
+
expect(config.class.known_options).to eq config.known_options
|
494
480
|
end
|
495
481
|
end
|
496
482
|
end
|
@@ -34,12 +34,12 @@ RSpec.describe GemPlugins::PluginManager do
|
|
34
34
|
expect(result).to include 'plugin-blub'
|
35
35
|
end
|
36
36
|
|
37
|
-
#context '#to_s' do
|
37
|
+
# context '#to_s' do
|
38
38
|
# it 'has a string representation' do
|
39
39
|
# manager = FeduxOrgStdlib::Fixtures::PluginManager::Load::PluginManager.new
|
40
40
|
# manager.activate_plugin 'fedux_org_stdlib-fixtures-plugin_manager-load'
|
41
41
|
|
42
42
|
# expect(manager.to_s).to include '1 row in set'
|
43
43
|
# end
|
44
|
-
#end
|
44
|
+
# end
|
45
45
|
end
|
data/spec/support/aruba.rb
CHANGED
@@ -44,8 +44,19 @@ end
|
|
44
44
|
|
45
45
|
RSpec.configure do |c|
|
46
46
|
c.include FeduxOrgStdlib::SpecHelper::Aruba
|
47
|
+
|
47
48
|
c.before :each do
|
48
49
|
clean_current_dir
|
49
|
-
restore_env
|
50
50
|
end
|
51
|
+
|
52
|
+
c.around(:example) do |example|
|
53
|
+
old_env = ENV.to_h
|
54
|
+
|
55
|
+
with_env 'HOME' => absolute_path('.') do
|
56
|
+
example.run
|
57
|
+
end
|
58
|
+
|
59
|
+
ENV.replace old_env
|
60
|
+
end
|
61
|
+
|
51
62
|
end
|