mixlib-config 2.2.2 → 2.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/NOTICE +7 -7
- data/README.md +18 -17
- data/lib/mixlib/config.rb +13 -9
- data/lib/mixlib/config/configurable.rb +2 -2
- data/lib/mixlib/config/reopened_config_context_with_configurable_error.rb +2 -2
- data/lib/mixlib/config/reopened_configurable_with_config_context_error.rb +2 -2
- data/lib/mixlib/config/unknown_config_option_error.rb +2 -2
- data/lib/mixlib/config/version.rb +3 -3
- data/mixlib-config.gemspec +1 -1
- data/spec/mixlib/config_spec.rb +290 -267
- data/spec/spec_helper.rb +0 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ebf0bd30e24aaeef0c7f79e0e4ce25adc6bef352
|
4
|
+
data.tar.gz: 800fd90f845685bd25aedc76fa6a5fc93bd0b485
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db587efec382225f4f1f8655b7f0d364825c34b3897913b516f8398e0b2b18a94d025e85f0f4ee83d3237f5b5f94c498b80036262f11a9036ff75bae12be2ef6
|
7
|
+
data.tar.gz: 6d06502f5e374fe48227ac4f82eba7dd330ecdfeba2becfadf5f078c3fa3a25eec7043a736dd23279d656eec13108507d4ece022beba8e002e0d404821022fd2
|
data/NOTICE
CHANGED
@@ -1,25 +1,25 @@
|
|
1
|
-
|
1
|
+
Mixlib::Config NOTICE
|
2
2
|
=================
|
3
3
|
|
4
|
-
Developed at
|
4
|
+
Developed at Chef (http://www.chef.io).
|
5
5
|
|
6
|
-
* Copyright 2009,
|
6
|
+
* Copyright 2009-2016, Chef Software, Inc. <legal@chef.io>
|
7
7
|
|
8
|
-
|
8
|
+
Mixlib::Config incorporates code from Chef. The Chef notice file follows:
|
9
9
|
|
10
10
|
Chef NOTICE
|
11
11
|
===========
|
12
12
|
|
13
|
-
Developed at
|
13
|
+
Developed at Chef (http://www.chef.io).
|
14
14
|
|
15
15
|
Contributors and Copyright holders:
|
16
16
|
|
17
|
-
* Copyright 2008, Adam Jacob <adam@
|
17
|
+
* Copyright 2008, Adam Jacob <adam@chef.io>
|
18
18
|
* Copyright 2008, Arjuna Christensen <aj@hjksolutions.com>
|
19
19
|
* Copyright 2008, Bryan McLellan <btm@loftninjas.org>
|
20
20
|
* Copyright 2008, Ezra Zygmuntowicz <ezra@engineyard.com>
|
21
21
|
* Copyright 2009, Sean Cribbs <seancribbs@gmail.com>
|
22
|
-
* Copyright 2009, Christopher Brown <cb@
|
22
|
+
* Copyright 2009, Christopher Brown <cb@chef.io>
|
23
23
|
* Copyright 2009, Thom May <thom@clearairturbulence.org>
|
24
24
|
|
25
25
|
Chef incorporates code modified from Open4 (http://www.codeforpeople.com/lib/ruby/open4/), which was written by Ara T. Howard.
|
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
-
# Mixlib::Config
|
1
|
+
# Mixlib::Config
|
2
2
|
|
3
|
-
|
3
|
+
[![Build Status](https://travis-ci.org/chef/mixlib-config.svg?branch=master)](https://travis-ci.org/chef/mixlib-config)[![Gem Version](https://badge.fury.io/rb/mixlib-config.svg)](https://badge.fury.io/rb/mixlib-config)
|
4
|
+
|
5
|
+
Mixlib::Config provides a class-based configuration object, as used in Chef. To use in your project:
|
4
6
|
|
5
7
|
```ruby
|
6
8
|
require 'mixlib/config'
|
@@ -13,7 +15,7 @@ Mixlib::Config provides a class-based configuration object, as used in Chef. To
|
|
13
15
|
end
|
14
16
|
```
|
15
17
|
|
16
|
-
You can use this to provide a configuration file for a user.
|
18
|
+
You can use this to provide a configuration file for a user. For example, if you do this:
|
17
19
|
|
18
20
|
```ruby
|
19
21
|
MyConfig.from_file('~/.myconfig.rb')
|
@@ -32,6 +34,7 @@ Inside your app, you can check configuration values with this syntax:
|
|
32
34
|
MyConfig.first_value # returns 'something'
|
33
35
|
MyConfig[:first_value] # returns 'something'
|
34
36
|
```
|
37
|
+
|
35
38
|
And you can modify configuration values with this syntax:
|
36
39
|
|
37
40
|
```ruby
|
@@ -40,9 +43,9 @@ And you can modify configuration values with this syntax:
|
|
40
43
|
MyConfig[:first_value] = 'foobar' # sets first_value to 'foobar'
|
41
44
|
```
|
42
45
|
|
43
|
-
## Nested Configuration
|
46
|
+
## Nested Configuration
|
44
47
|
|
45
|
-
Often you want to be able to group configuration options to provide a common context.
|
48
|
+
Often you want to be able to group configuration options to provide a common context. Mixlib::Config supports this thus:
|
46
49
|
|
47
50
|
```ruby
|
48
51
|
require 'mixlib/config'
|
@@ -70,9 +73,9 @@ You can access these variables thus:
|
|
70
73
|
MyConfig[:logging][:max_log_files]
|
71
74
|
```
|
72
75
|
|
73
|
-
## Default Values
|
76
|
+
## Default Values
|
74
77
|
|
75
|
-
Mixlib::Config has a powerful default value facility.
|
78
|
+
Mixlib::Config has a powerful default value facility. In addition to being able to specify explicit default values, you can even specify Ruby code blocks that will run if the config value is not set. This can allow you to build options whose values are based on other options.
|
76
79
|
|
77
80
|
```ruby
|
78
81
|
require 'mixlib/config'
|
@@ -93,9 +96,9 @@ This allows the user to quickly specify a number of values with one default, whi
|
|
93
96
|
print_network_requests false
|
94
97
|
```
|
95
98
|
|
96
|
-
## Strict Mode
|
99
|
+
## Strict Mode
|
97
100
|
|
98
|
-
Misspellings are a common configuration problem, and Mixlib::Config has an
|
101
|
+
Misspellings are a common configuration problem, and Mixlib::Config has an answer: `config_strict_mode`. Setting `config_strict_mode` to `true` will cause any misspelled or incorrect configuration option references to throw `Mixlib::Config::UnknownConfigOptionError`.
|
99
102
|
|
100
103
|
```ruby
|
101
104
|
require 'mixlib/config'
|
@@ -112,18 +115,16 @@ Misspellings are a common configuration problem, and Mixlib::Config has an answ
|
|
112
115
|
end
|
113
116
|
```
|
114
117
|
|
115
|
-
Now if a user types `fielname "~/output-mine.txt"` in their configuration file, it will toss an exception telling them that the option "fielname" is unknown.
|
116
|
-
|
117
|
-
Different config_contexts can have different strict modes; but they inherit the strict mode of their parent if you don't explicitly set it. So setting it once at the top level is sufficient. In the above example, `logging.base_naem 'mylog'` will raise an error.
|
118
|
+
Now if a user types `fielname "~/output-mine.txt"` in their configuration file, it will toss an exception telling them that the option "fielname" is unknown. If you do not set config_strict_mode, the fielname option will be merrily set and the application just won't know about it.
|
118
119
|
|
119
|
-
|
120
|
+
Different config_contexts can have different strict modes; but they inherit the strict mode of their parent if you don't explicitly set it. So setting it once at the top level is sufficient. In the above example, `logging.base_naem 'mylog'` will raise an error.
|
120
121
|
|
121
|
-
|
122
|
+
In conclusion: _always set config_strict_mode to true_. You know you want to.
|
122
123
|
|
123
|
-
Testing
|
124
|
+
## Testing and Reset
|
124
125
|
|
125
|
-
|
126
|
+
Testing your application with different sets of arguments can by simplified with `reset`. Call `MyConfig.reset` before each test and all configuration will be reset to its default value. There's no need to explicitly unset all your options between each run.
|
126
127
|
|
127
|
-
|
128
|
+
NOTE: if you have arrays of arrays, or other deep nesting, we suggest you use code blocks to set up your default values (`default(:option) { [ [ 1, 2 ], [ 3, 4 ] ] }`). Deep children will not always be reset to their default values.
|
128
129
|
|
129
130
|
Enjoy!
|
data/lib/mixlib/config.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
#
|
2
|
-
# Author:: Adam Jacob (<adam@
|
3
|
-
# Author:: Nuo Yan (<nuo@
|
4
|
-
# Author:: Christopher Brown (<cb@
|
5
|
-
# Copyright:: Copyright (c) 2008
|
2
|
+
# Author:: Adam Jacob (<adam@chef.io>)
|
3
|
+
# Author:: Nuo Yan (<nuo@chef.io>)
|
4
|
+
# Author:: Christopher Brown (<cb@chef.io>)
|
5
|
+
# Copyright:: Copyright (c) 2008-2016 Chef Software, Inc.
|
6
6
|
# License:: Apache License, Version 2.0
|
7
7
|
#
|
8
8
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -177,16 +177,20 @@ module Mixlib
|
|
177
177
|
|
178
178
|
# Restore non-default values from the given hash.
|
179
179
|
#
|
180
|
-
# This method is the equivalent of +reset+ followed by +merge!(hash)+.
|
181
|
-
#
|
182
180
|
# === Parameters
|
183
181
|
# hash<Hash>: a hash in the same format as output by save.
|
184
|
-
#
|
182
|
+
#
|
185
183
|
# === Returns
|
186
184
|
# self
|
187
185
|
def restore(hash)
|
188
|
-
|
189
|
-
|
186
|
+
self.configuration = hash.reject { |key, value| config_contexts.has_key?(key) }
|
187
|
+
config_contexts.each do |key, config_context|
|
188
|
+
if hash.has_key?(key)
|
189
|
+
config_context.restore(hash[key])
|
190
|
+
else
|
191
|
+
config_context.reset
|
192
|
+
end
|
193
|
+
end
|
190
194
|
end
|
191
195
|
|
192
196
|
# Merge an incoming hash with our config options
|
@@ -1,6 +1,6 @@
|
|
1
1
|
#
|
2
|
-
# Author:: John Keiser (<jkeiser@
|
3
|
-
# Copyright:: Copyright (c) 2013
|
2
|
+
# Author:: John Keiser (<jkeiser@chef.io>)
|
3
|
+
# Copyright:: Copyright (c) 2013-2016 Chef Software, Inc.
|
4
4
|
# License:: Apache License, Version 2.0
|
5
5
|
#
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -1,6 +1,6 @@
|
|
1
1
|
#
|
2
|
-
# Author:: John Keiser (<jkeiser@
|
3
|
-
# Copyright:: Copyright (c) 2013
|
2
|
+
# Author:: John Keiser (<jkeiser@chef.io>)
|
3
|
+
# Copyright:: Copyright (c) 2013-2016 Chef Software, Inc.
|
4
4
|
# License:: Apache License, Version 2.0
|
5
5
|
#
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -1,6 +1,6 @@
|
|
1
1
|
#
|
2
|
-
# Author:: John Keiser (<jkeiser@
|
3
|
-
# Copyright:: Copyright (c) 2013
|
2
|
+
# Author:: John Keiser (<jkeiser@chef.io>)
|
3
|
+
# Copyright:: Copyright (c) 2013-2016 Chef Software, Inc.
|
4
4
|
# License:: Apache License, Version 2.0
|
5
5
|
#
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -1,6 +1,6 @@
|
|
1
1
|
#
|
2
|
-
# Author:: John Keiser (<jkeiser@
|
3
|
-
# Copyright:: Copyright (c) 2013
|
2
|
+
# Author:: John Keiser (<jkeiser@chef.io>)
|
3
|
+
# Copyright:: Copyright (c) 2013-2016 Chef Software, Inc.
|
4
4
|
# License:: Apache License, Version 2.0
|
5
5
|
#
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -1,6 +1,6 @@
|
|
1
1
|
#
|
2
|
-
# Author:: Daniel DeLeo (<dan@
|
3
|
-
# Copyright:: Copyright (c) 2013
|
2
|
+
# Author:: Daniel DeLeo (<dan@chef.io>)
|
3
|
+
# Copyright:: Copyright (c) 2013-2016 Chef Software, Inc.
|
4
4
|
# License:: Apache License, Version 2.0
|
5
5
|
#
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -19,7 +19,7 @@
|
|
19
19
|
module Mixlib
|
20
20
|
module Config
|
21
21
|
|
22
|
-
VERSION = "2.2.
|
22
|
+
VERSION = "2.2.3"
|
23
23
|
|
24
24
|
end
|
25
25
|
end
|
data/mixlib-config.gemspec
CHANGED
data/spec/mixlib/config_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#
|
2
|
-
# Author:: Adam Jacob (<adam@
|
3
|
-
# Copyright:: Copyright (c) 2008
|
2
|
+
# Author:: Adam Jacob (<adam@chef.io>)
|
3
|
+
# Copyright:: Copyright (c) 2008-2016 Chef Software, Inc.
|
4
4
|
# License:: Apache License, Version 2.0
|
5
5
|
#
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -26,62 +26,62 @@ describe Mixlib::Config do
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
it "
|
30
|
-
File.
|
31
|
-
File.
|
32
|
-
IO.
|
33
|
-
lambda {
|
29
|
+
it "loads a config file" do
|
30
|
+
allow(File).to receive(:exists?).and_return(true)
|
31
|
+
allow(File).to receive(:readable?).and_return(true)
|
32
|
+
allow(IO).to receive(:read).with("config.rb").and_return("alpha = 'omega'\nfoo = 'bar'")
|
33
|
+
expect(lambda {
|
34
34
|
ConfigIt.from_file("config.rb")
|
35
|
-
}.
|
35
|
+
}).to_not raise_error
|
36
36
|
end
|
37
37
|
|
38
|
-
it "
|
39
|
-
lambda {
|
38
|
+
it "doesn't raise an ArgumentError with an explanation if you try and set a non-existent variable" do
|
39
|
+
expect(lambda {
|
40
40
|
ConfigIt[:foobar] = "blah"
|
41
|
-
}.
|
41
|
+
}).to_not raise_error
|
42
42
|
end
|
43
43
|
|
44
|
-
it "
|
45
|
-
lambda {
|
44
|
+
it "raises an Errno::ENOENT if it can't find the file" do
|
45
|
+
expect(lambda {
|
46
46
|
ConfigIt.from_file("/tmp/timmytimmytimmy")
|
47
|
-
}.
|
47
|
+
}).to raise_error(Errno::ENOENT)
|
48
48
|
end
|
49
49
|
|
50
|
-
it "
|
51
|
-
IO.
|
52
|
-
lambda {
|
50
|
+
it "allows the error to bubble up when it's anything other than IOError" do
|
51
|
+
allow(IO).to receive(:read).with("config.rb").and_return("@#asdf")
|
52
|
+
expect(lambda {
|
53
53
|
ConfigIt.from_file("config.rb")
|
54
|
-
}.
|
54
|
+
}).to raise_error(SyntaxError)
|
55
55
|
end
|
56
56
|
|
57
|
-
it "
|
58
|
-
ConfigIt[:alpha].
|
57
|
+
it "allows you to reference a value by index" do
|
58
|
+
expect(ConfigIt[:alpha]).to eql("omega")
|
59
59
|
end
|
60
60
|
|
61
|
-
it "
|
62
|
-
ConfigIt["alpha"].
|
61
|
+
it "allows you to reference a value by string index" do
|
62
|
+
expect(ConfigIt["alpha"]).to eql("omega")
|
63
63
|
end
|
64
64
|
|
65
|
-
it "
|
65
|
+
it "allows you to set a value by index" do
|
66
66
|
ConfigIt[:alpha] = "one"
|
67
|
-
ConfigIt[:alpha].
|
67
|
+
expect(ConfigIt[:alpha]).to eql("one")
|
68
68
|
end
|
69
69
|
|
70
|
-
it "
|
70
|
+
it "allows you to set a value by string index" do
|
71
71
|
ConfigIt["alpha"] = "one"
|
72
|
-
ConfigIt[:alpha].
|
72
|
+
expect(ConfigIt[:alpha]).to eql("one")
|
73
73
|
end
|
74
74
|
|
75
|
-
it "
|
75
|
+
it "allows setting a value with attribute form" do
|
76
76
|
ConfigIt.arbitrary_value = 50
|
77
|
-
ConfigIt.arbitrary_value.
|
78
|
-
ConfigIt[:arbitrary_value].
|
77
|
+
expect(ConfigIt.arbitrary_value).to eql(50)
|
78
|
+
expect(ConfigIt[:arbitrary_value]).to eql(50)
|
79
79
|
end
|
80
80
|
|
81
|
-
it "
|
81
|
+
it "allows setting a value with method form" do
|
82
82
|
ConfigIt.arbitrary_value 50
|
83
|
-
ConfigIt.arbitrary_value.
|
84
|
-
ConfigIt[:arbitrary_value].
|
83
|
+
expect(ConfigIt.arbitrary_value).to eql(50)
|
84
|
+
expect(ConfigIt[:arbitrary_value]).to eql(50)
|
85
85
|
end
|
86
86
|
|
87
87
|
describe "when strict mode is on" do
|
@@ -97,23 +97,23 @@ describe Mixlib::Config do
|
|
97
97
|
end
|
98
98
|
|
99
99
|
it "raises an error when you get an arbitrary config option with .y" do
|
100
|
-
lambda { StrictClass.y }.
|
100
|
+
expect(lambda { StrictClass.y }).to raise_error(Mixlib::Config::UnknownConfigOptionError, "Reading unsupported config value y.")
|
101
101
|
end
|
102
102
|
|
103
103
|
it "raises an error when you get an arbitrary config option with [:y]" do
|
104
|
-
lambda { StrictClass[:y] }.
|
104
|
+
expect(lambda { StrictClass[:y] }).to raise_error(Mixlib::Config::UnknownConfigOptionError, "Reading unsupported config value y.")
|
105
105
|
end
|
106
106
|
|
107
107
|
it "raises an error when you set an arbitrary config option with .y = 10" do
|
108
|
-
lambda { StrictClass.y = 10 }.
|
108
|
+
expect(lambda { StrictClass.y = 10 }).to raise_error(Mixlib::Config::UnknownConfigOptionError, "Cannot set unsupported config value y.")
|
109
109
|
end
|
110
110
|
|
111
111
|
it "raises an error when you set an arbitrary config option with .y 10" do
|
112
|
-
lambda { StrictClass.y 10 }.
|
112
|
+
expect(lambda { StrictClass.y 10 }).to raise_error(Mixlib::Config::UnknownConfigOptionError, "Cannot set unsupported config value y.")
|
113
113
|
end
|
114
114
|
|
115
115
|
it "raises an error when you set an arbitrary config option with [:y] = 10" do
|
116
|
-
lambda { StrictClass[:y] = 10 }.
|
116
|
+
expect(lambda { StrictClass[:y] = 10 }).to raise_error(Mixlib::Config::UnknownConfigOptionError, "Cannot set unsupported config value y.")
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
@@ -123,23 +123,23 @@ describe Mixlib::Config do
|
|
123
123
|
end
|
124
124
|
|
125
125
|
{ :cookbook_path => "monkey_rabbit", :otherthing => "boo" }.each do |k, v|
|
126
|
-
it "
|
127
|
-
ConfigIt[k].
|
126
|
+
it "allows you to retrieve the config value for #{k} via []" do
|
127
|
+
expect(ConfigIt[k]).to eql(v)
|
128
128
|
end
|
129
|
-
it "
|
130
|
-
ConfigIt.send(k).
|
129
|
+
it "allows you to retrieve the config value for #{k} via method_missing" do
|
130
|
+
expect(ConfigIt.send(k)).to eql(v)
|
131
131
|
end
|
132
132
|
end
|
133
133
|
end
|
134
134
|
|
135
|
-
it "
|
136
|
-
lambda { ConfigIt[:snob_hobbery] }.
|
135
|
+
it "doesn't raise an ArgumentError if you access a config option that does not exist" do
|
136
|
+
expect(lambda { ConfigIt[:snob_hobbery] }).to_not raise_error
|
137
137
|
end
|
138
138
|
|
139
|
-
it "
|
140
|
-
ConfigIt.has_key?(:monkey).
|
139
|
+
it "returns true or false with has_key?" do
|
140
|
+
expect(ConfigIt.has_key?(:monkey)).to be false
|
141
141
|
ConfigIt[:monkey] = "gotcha"
|
142
|
-
ConfigIt.has_key?(:monkey).
|
142
|
+
expect(ConfigIt.has_key?(:monkey)).to be true
|
143
143
|
end
|
144
144
|
|
145
145
|
describe "when a class method override writer exists" do
|
@@ -153,29 +153,29 @@ describe Mixlib::Config do
|
|
153
153
|
end
|
154
154
|
end
|
155
155
|
|
156
|
-
it "
|
156
|
+
it "multiplies an integer by 1000" do
|
157
157
|
@klass[:test_method] = 53
|
158
|
-
@klass[:test_method].
|
158
|
+
expect(@klass[:test_method]).to eql(53000)
|
159
159
|
end
|
160
160
|
|
161
|
-
it "
|
161
|
+
it "multiplies an integer by 1000 with the method_missing form" do
|
162
162
|
@klass.test_method = 63
|
163
|
-
@klass.test_method.
|
163
|
+
expect(@klass.test_method).to eql(63000)
|
164
164
|
end
|
165
165
|
|
166
|
-
it "
|
166
|
+
it "multiplies an integer by 1000 with the instance_eval DSL form" do
|
167
167
|
@klass.instance_eval("test_method 73")
|
168
|
-
@klass.test_method.
|
168
|
+
expect(@klass.test_method).to eql(73000)
|
169
169
|
end
|
170
170
|
|
171
|
-
it "
|
172
|
-
IO.
|
171
|
+
it "multiplies an integer by 1000 via from-file, too" do
|
172
|
+
allow(IO).to receive(:read).with("config.rb").and_return("test_method 99")
|
173
173
|
@klass.from_file("config.rb")
|
174
|
-
@klass.test_method.
|
174
|
+
expect(@klass.test_method).to eql(99000)
|
175
175
|
end
|
176
176
|
|
177
|
-
it "
|
178
|
-
@klass.
|
177
|
+
it "receives internal_set with the method name and config value" do
|
178
|
+
expect(@klass).to receive(:internal_set).with(:test_method, 53).and_return(true)
|
179
179
|
@klass[:test_method] = 53
|
180
180
|
end
|
181
181
|
|
@@ -194,19 +194,19 @@ describe Mixlib::Config do
|
|
194
194
|
end
|
195
195
|
|
196
196
|
it "Getter methods are created for the configurable" do
|
197
|
-
@klass.respond_to?(:daemonizeme).
|
198
|
-
@klass.respond_to?(:a).
|
199
|
-
@klass.respond_to?(:b).
|
200
|
-
@klass.respond_to?(:c).
|
201
|
-
@klass.respond_to?(:z).
|
197
|
+
expect(@klass.respond_to?(:daemonizeme)).to be true
|
198
|
+
expect(@klass.respond_to?(:a)).to be true
|
199
|
+
expect(@klass.respond_to?(:b)).to be true
|
200
|
+
expect(@klass.respond_to?(:c)).to be true
|
201
|
+
expect(@klass.respond_to?(:z)).to be false
|
202
202
|
end
|
203
203
|
|
204
204
|
it "Setter methods are created for the configurable" do
|
205
|
-
@klass.respond_to?("daemonizeme=".to_sym).
|
206
|
-
@klass.respond_to?("a=".to_sym).
|
207
|
-
@klass.respond_to?("b=".to_sym).
|
208
|
-
@klass.respond_to?("c=".to_sym).
|
209
|
-
@klass.respond_to?("z=".to_sym).
|
205
|
+
expect(@klass.respond_to?("daemonizeme=".to_sym)).to be true
|
206
|
+
expect(@klass.respond_to?("a=".to_sym)).to be true
|
207
|
+
expect(@klass.respond_to?("b=".to_sym)).to be true
|
208
|
+
expect(@klass.respond_to?("c=".to_sym)).to be true
|
209
|
+
expect(@klass.respond_to?("z=".to_sym)).to be false
|
210
210
|
end
|
211
211
|
|
212
212
|
describe "and extra methods have been dumped into Object" do
|
@@ -229,17 +229,17 @@ describe Mixlib::Config do
|
|
229
229
|
it "Normal classes call the extra method" do
|
230
230
|
normal_class = Class.new
|
231
231
|
normal_class.extend(::Mixlib::Config)
|
232
|
-
lambda { normal_class.daemonizeme }.
|
232
|
+
expect(lambda { normal_class.daemonizeme }).to raise_error(NopeError)
|
233
233
|
end
|
234
234
|
|
235
235
|
it "Configurables with the same name as the extra method can be set" do
|
236
236
|
@klass.daemonizeme = 10
|
237
|
-
@klass[:daemonizeme].
|
237
|
+
expect(@klass[:daemonizeme]).to eql(10)
|
238
238
|
end
|
239
239
|
|
240
240
|
it "Configurables with the same name as the extra method can be retrieved" do
|
241
241
|
@klass[:daemonizeme] = 10
|
242
|
-
@klass.daemonizeme.
|
242
|
+
expect(@klass.daemonizeme).to eql(10)
|
243
243
|
end
|
244
244
|
end
|
245
245
|
end
|
@@ -251,55 +251,55 @@ describe Mixlib::Config do
|
|
251
251
|
@klass.class_eval { default :attr, 4 }
|
252
252
|
end
|
253
253
|
|
254
|
-
it "
|
255
|
-
@klass.attr.
|
254
|
+
it "defaults to that value" do
|
255
|
+
expect(@klass.attr).to eql(4)
|
256
256
|
end
|
257
257
|
|
258
|
-
it "
|
259
|
-
@klass[:attr].
|
258
|
+
it "defaults to that value when retrieved as a hash" do
|
259
|
+
expect(@klass[:attr]).to eql(4)
|
260
260
|
end
|
261
261
|
|
262
|
-
it "
|
262
|
+
it "is settable to another value" do
|
263
263
|
@klass.attr 5
|
264
|
-
@klass.attr.
|
264
|
+
expect(@klass.attr).to eql(5)
|
265
265
|
end
|
266
266
|
|
267
|
-
it "
|
267
|
+
it "still defaults to that value after delete" do
|
268
268
|
@klass.attr 5
|
269
269
|
@klass.delete(:attr)
|
270
|
-
@klass.attr.
|
270
|
+
expect(@klass.attr).to eql(4)
|
271
271
|
end
|
272
272
|
|
273
|
-
it "
|
273
|
+
it "still defaults to that value after reset" do
|
274
274
|
@klass.attr 5
|
275
275
|
@klass.reset
|
276
|
-
@klass.attr.
|
276
|
+
expect(@klass.attr).to eql(4)
|
277
277
|
end
|
278
278
|
|
279
279
|
it "save should not save anything for it" do
|
280
|
-
@klass.save.
|
280
|
+
expect(@klass.save).to eql({})
|
281
281
|
end
|
282
282
|
|
283
283
|
it "save with include_defaults should save all defaults" do
|
284
|
-
@klass.save(true).
|
284
|
+
expect(@klass.save(true)).to eql({ :attr => 4 })
|
285
285
|
end
|
286
286
|
|
287
|
-
it "
|
287
|
+
it "saves the new value if it gets set" do
|
288
288
|
@klass.attr 5
|
289
|
-
(saved = @klass.save).
|
289
|
+
expect((saved = @klass.save)).to eql({ :attr => 5 })
|
290
290
|
@klass.reset
|
291
|
-
@klass.attr.
|
291
|
+
expect(@klass.attr).to eql(4)
|
292
292
|
@klass.restore(saved)
|
293
|
-
@klass.attr.
|
293
|
+
expect(@klass.attr).to eql(5)
|
294
294
|
end
|
295
295
|
|
296
|
-
it "
|
296
|
+
it "saves the new value even if it is set to its default value" do
|
297
297
|
@klass.attr 4
|
298
|
-
(saved = @klass.save).
|
298
|
+
expect((saved = @klass.save)).to eql({ :attr => 4 })
|
299
299
|
@klass.reset
|
300
|
-
@klass.save.
|
300
|
+
expect(@klass.save).to eql({})
|
301
301
|
@klass.restore(saved)
|
302
|
-
@klass.save.
|
302
|
+
expect(@klass.save).to eql({ :attr => 4 })
|
303
303
|
end
|
304
304
|
end
|
305
305
|
|
@@ -313,61 +313,61 @@ describe Mixlib::Config do
|
|
313
313
|
end
|
314
314
|
end
|
315
315
|
|
316
|
-
it "
|
317
|
-
@klass.attr.
|
316
|
+
it "defaults to that value" do
|
317
|
+
expect(@klass.attr).to eql(8)
|
318
318
|
end
|
319
319
|
|
320
|
-
it "
|
321
|
-
@klass.attr.
|
320
|
+
it "is recalculated each time it is retrieved" do
|
321
|
+
expect(@klass.attr).to eql(8)
|
322
322
|
@klass.x = 2
|
323
|
-
@klass.attr.
|
323
|
+
expect(@klass.attr).to eql(4)
|
324
324
|
end
|
325
325
|
|
326
|
-
it "
|
327
|
-
@klass[:attr].
|
326
|
+
it "defaults to that value when retrieved as a hash" do
|
327
|
+
expect(@klass[:attr]).to eql(8)
|
328
328
|
end
|
329
329
|
|
330
|
-
it "
|
330
|
+
it "is settable to another value" do
|
331
331
|
@klass.attr 5
|
332
|
-
@klass.attr.
|
332
|
+
expect(@klass.attr).to eql(5)
|
333
333
|
end
|
334
334
|
|
335
|
-
it "
|
335
|
+
it "still defaults to that value after delete" do
|
336
336
|
@klass.attr 5
|
337
337
|
@klass.delete(:attr)
|
338
|
-
@klass.attr.
|
338
|
+
expect(@klass.attr).to eql(8)
|
339
339
|
end
|
340
340
|
|
341
|
-
it "
|
341
|
+
it "still defaults to that value after reset" do
|
342
342
|
@klass.attr 5
|
343
343
|
@klass.reset
|
344
|
-
@klass.attr.
|
344
|
+
expect(@klass.attr).to eql(8)
|
345
345
|
end
|
346
346
|
|
347
347
|
it "save should not save anything for it" do
|
348
|
-
@klass.save.
|
348
|
+
expect(@klass.save).to eql({})
|
349
349
|
end
|
350
350
|
|
351
351
|
it "save with include_defaults should save all defaults" do
|
352
|
-
@klass.save(true).
|
352
|
+
expect(@klass.save(true)).to eql({ :attr => 8, :x => 4 })
|
353
353
|
end
|
354
354
|
|
355
|
-
it "
|
355
|
+
it "saves the new value if it gets set" do
|
356
356
|
@klass.attr 5
|
357
|
-
(saved = @klass.save).
|
357
|
+
expect((saved = @klass.save)).to eql({ :attr => 5 })
|
358
358
|
@klass.reset
|
359
|
-
@klass.attr.
|
359
|
+
expect(@klass.attr).to eql(8)
|
360
360
|
@klass.restore(saved)
|
361
|
-
@klass.attr.
|
361
|
+
expect(@klass.attr).to eql(5)
|
362
362
|
end
|
363
363
|
|
364
|
-
it "
|
364
|
+
it "saves the new value even if it is set to its default value" do
|
365
365
|
@klass.attr 8
|
366
|
-
(saved = @klass.save).
|
366
|
+
expect((saved = @klass.save)).to eql({ :attr => 8 })
|
367
367
|
@klass.reset
|
368
|
-
@klass.save.
|
368
|
+
expect(@klass.save).to eql({})
|
369
369
|
@klass.restore(saved)
|
370
|
-
@klass.save.
|
370
|
+
expect(@klass.save).to eql({ :attr => 8 })
|
371
371
|
end
|
372
372
|
end
|
373
373
|
|
@@ -380,35 +380,35 @@ describe Mixlib::Config do
|
|
380
380
|
|
381
381
|
it "reset clears it to its default" do
|
382
382
|
@klass.attr << "x"
|
383
|
-
@klass.attr.
|
383
|
+
expect(@klass.attr).to eql([ "x" ])
|
384
384
|
@klass.reset
|
385
|
-
@klass.attr.
|
385
|
+
expect(@klass.attr).to eql([])
|
386
386
|
end
|
387
387
|
|
388
388
|
it "save should not save anything for it" do
|
389
|
-
@klass.save.
|
389
|
+
expect(@klass.save).to eql({})
|
390
390
|
end
|
391
391
|
|
392
392
|
it "save with include_defaults should save all defaults" do
|
393
|
-
@klass.save(true).
|
393
|
+
expect(@klass.save(true)).to eql({ :attr => [] })
|
394
394
|
end
|
395
395
|
|
396
|
-
it "
|
396
|
+
it "saves the new value if it gets set" do
|
397
397
|
@klass.attr << "x"
|
398
|
-
(saved = @klass.save).
|
398
|
+
expect((saved = @klass.save)).to eql({ :attr => [ "x" ] })
|
399
399
|
@klass.reset
|
400
|
-
@klass.attr.
|
400
|
+
expect(@klass.attr).to eql([])
|
401
401
|
@klass.restore(saved)
|
402
|
-
@klass.attr.
|
402
|
+
expect(@klass.attr).to eql([ "x" ])
|
403
403
|
end
|
404
404
|
|
405
|
-
it "
|
405
|
+
it "saves the new value even if it is set to its default value" do
|
406
406
|
@klass.attr = []
|
407
|
-
(saved = @klass.save).
|
407
|
+
expect((saved = @klass.save)).to eql({ :attr => [] })
|
408
408
|
@klass.reset
|
409
|
-
@klass.save.
|
409
|
+
expect(@klass.save).to eql({})
|
410
410
|
@klass.restore(saved)
|
411
|
-
@klass.save.
|
411
|
+
expect(@klass.save).to eql({ :attr => [] })
|
412
412
|
end
|
413
413
|
end
|
414
414
|
|
@@ -421,35 +421,35 @@ describe Mixlib::Config do
|
|
421
421
|
|
422
422
|
it "reset clears it to its default" do
|
423
423
|
@klass.attr[:x] = 10
|
424
|
-
@klass.attr[:x].
|
424
|
+
expect(@klass.attr[:x]).to eql(10)
|
425
425
|
@klass.reset
|
426
|
-
@klass.attr[:x].
|
426
|
+
expect(@klass.attr[:x]).to be_nil
|
427
427
|
end
|
428
428
|
|
429
429
|
it "save should not save anything for it" do
|
430
|
-
@klass.save.
|
430
|
+
expect(@klass.save).to eql({})
|
431
431
|
end
|
432
432
|
|
433
433
|
it "save with include_defaults should save all defaults" do
|
434
|
-
@klass.save(true).
|
434
|
+
expect(@klass.save(true)).to eql({ :attr => {} })
|
435
435
|
end
|
436
436
|
|
437
|
-
it "
|
437
|
+
it "saves the new value if it gets set" do
|
438
438
|
@klass.attr[:hi] = "lo"
|
439
|
-
(saved = @klass.save).
|
439
|
+
expect((saved = @klass.save)).to eql({ :attr => { :hi => "lo" } })
|
440
440
|
@klass.reset
|
441
|
-
@klass.attr.
|
441
|
+
expect(@klass.attr).to eql({})
|
442
442
|
@klass.restore(saved)
|
443
|
-
@klass.save.
|
443
|
+
expect(@klass.save).to eql({ :attr => { :hi => "lo" } })
|
444
444
|
end
|
445
445
|
|
446
|
-
it "
|
446
|
+
it "saves the new value even if it is set to its default value" do
|
447
447
|
@klass.attr = {}
|
448
|
-
(saved = @klass.save).
|
448
|
+
expect((saved = @klass.save)).to eql({ :attr => {} })
|
449
449
|
@klass.reset
|
450
|
-
@klass.save.
|
450
|
+
expect(@klass.save).to eql({})
|
451
451
|
@klass.restore(saved)
|
452
|
-
@klass.save.
|
452
|
+
expect(@klass.save).to eql({ :attr => {} })
|
453
453
|
end
|
454
454
|
end
|
455
455
|
|
@@ -462,35 +462,35 @@ describe Mixlib::Config do
|
|
462
462
|
|
463
463
|
it "reset clears it to its default" do
|
464
464
|
@klass.attr << " world"
|
465
|
-
@klass.attr.
|
465
|
+
expect(@klass.attr).to eql("hello world")
|
466
466
|
@klass.reset
|
467
|
-
@klass.attr.
|
467
|
+
expect(@klass.attr).to eql("hello")
|
468
468
|
end
|
469
469
|
|
470
470
|
it "save should not save anything for it" do
|
471
|
-
@klass.save.
|
471
|
+
expect(@klass.save).to eql({})
|
472
472
|
end
|
473
473
|
|
474
474
|
it "save with include_defaults should save all defaults" do
|
475
|
-
@klass.save(true).
|
475
|
+
expect(@klass.save(true)).to eql({ :attr => "hello" })
|
476
476
|
end
|
477
477
|
|
478
|
-
it "
|
478
|
+
it "saves the new value if it gets set" do
|
479
479
|
@klass.attr << " world"
|
480
|
-
(saved = @klass.save).
|
480
|
+
expect((saved = @klass.save)).to eql({ :attr => "hello world" })
|
481
481
|
@klass.reset
|
482
|
-
@klass.attr.
|
482
|
+
expect(@klass.attr).to eql("hello")
|
483
483
|
@klass.restore(saved)
|
484
|
-
@klass.attr.
|
484
|
+
expect(@klass.attr).to eql("hello world")
|
485
485
|
end
|
486
486
|
|
487
|
-
it "
|
487
|
+
it "saves the new value even if it is set to its default value" do
|
488
488
|
@klass.attr "hello world"
|
489
|
-
(saved = @klass.save).
|
489
|
+
expect((saved = @klass.save)).to eql({ :attr => "hello world" })
|
490
490
|
@klass.reset
|
491
|
-
@klass.save.
|
491
|
+
expect(@klass.save).to eql({})
|
492
492
|
@klass.restore(saved)
|
493
|
-
@klass.save.
|
493
|
+
expect(@klass.save).to eql({ :attr => "hello world" })
|
494
494
|
end
|
495
495
|
end
|
496
496
|
|
@@ -503,56 +503,56 @@ describe Mixlib::Config do
|
|
503
503
|
end
|
504
504
|
end
|
505
505
|
|
506
|
-
it "
|
507
|
-
@klass.attr.
|
506
|
+
it "defaults to that value" do
|
507
|
+
expect(@klass.attr).to eql(4)
|
508
508
|
end
|
509
509
|
|
510
|
-
it "
|
511
|
-
@klass[:attr].
|
510
|
+
it "defaults to that value when retrieved as a hash" do
|
511
|
+
expect(@klass[:attr]).to eql(4)
|
512
512
|
end
|
513
513
|
|
514
|
-
it "
|
514
|
+
it "is settable to another value" do
|
515
515
|
@klass.attr 5
|
516
|
-
@klass.attr.
|
517
|
-
@klass[:attr].
|
516
|
+
expect(@klass.attr).to eql(5)
|
517
|
+
expect(@klass[:attr]).to eql(5)
|
518
518
|
end
|
519
519
|
|
520
|
-
it "
|
520
|
+
it "still defaults to that value after delete" do
|
521
521
|
@klass.attr 5
|
522
522
|
@klass.delete(:attr)
|
523
|
-
@klass.attr.
|
523
|
+
expect(@klass.attr).to eql(4)
|
524
524
|
end
|
525
525
|
|
526
|
-
it "
|
526
|
+
it "still defaults to that value after reset" do
|
527
527
|
@klass.attr 5
|
528
528
|
@klass.reset
|
529
|
-
@klass.attr.
|
529
|
+
expect(@klass.attr).to eql(4)
|
530
530
|
end
|
531
531
|
|
532
532
|
it "save should not save anything for it" do
|
533
|
-
@klass.save.
|
533
|
+
expect(@klass.save).to eql({})
|
534
534
|
end
|
535
535
|
|
536
536
|
it "save with include_defaults should save all defaults" do
|
537
|
-
@klass.save(true).
|
537
|
+
expect(@klass.save(true)).to eql({ :attr => 4 })
|
538
538
|
end
|
539
539
|
|
540
|
-
it "
|
540
|
+
it "saves the new value if it gets set" do
|
541
541
|
@klass.attr 5
|
542
|
-
(saved = @klass.save).
|
542
|
+
expect((saved = @klass.save)).to eql({ :attr => 5 })
|
543
543
|
@klass.reset
|
544
|
-
@klass.attr.
|
544
|
+
expect(@klass.attr).to eql(4)
|
545
545
|
@klass.restore(saved)
|
546
|
-
@klass.attr.
|
546
|
+
expect(@klass.attr).to eql(5)
|
547
547
|
end
|
548
548
|
|
549
|
-
it "
|
549
|
+
it "saves the new value even if it is set to its default value" do
|
550
550
|
@klass.attr 4
|
551
|
-
(saved = @klass.save).
|
551
|
+
expect((saved = @klass.save)).to eql({ :attr => 4 })
|
552
552
|
@klass.reset
|
553
|
-
@klass.save.
|
553
|
+
expect(@klass.save).to eql({})
|
554
554
|
@klass.restore(saved)
|
555
|
-
@klass.save.
|
555
|
+
expect(@klass.save).to eql({ :attr => 4 })
|
556
556
|
end
|
557
557
|
end
|
558
558
|
|
@@ -568,68 +568,68 @@ describe Mixlib::Config do
|
|
568
568
|
end
|
569
569
|
end
|
570
570
|
|
571
|
-
it "
|
572
|
-
@klass.attr.
|
571
|
+
it "defaults to that value" do
|
572
|
+
expect(@klass.attr).to eql(4)
|
573
573
|
end
|
574
574
|
|
575
|
-
it "
|
576
|
-
@klass[:attr].
|
575
|
+
it "defaults to that value when retrieved as a hash" do
|
576
|
+
expect(@klass[:attr]).to eql(4)
|
577
577
|
end
|
578
578
|
|
579
|
-
it "
|
579
|
+
it "is settable to another value" do
|
580
580
|
@klass.attr 5
|
581
|
-
@klass.attr.
|
582
|
-
@klass[:attr].
|
581
|
+
expect(@klass.attr).to eql(10)
|
582
|
+
expect(@klass[:attr]).to eql(10)
|
583
583
|
end
|
584
584
|
|
585
|
-
it "
|
585
|
+
it "is settable to another value with attr=" do
|
586
586
|
@klass.attr = 5
|
587
|
-
@klass.attr.
|
588
|
-
@klass[:attr].
|
587
|
+
expect(@klass.attr).to eql(10)
|
588
|
+
expect(@klass[:attr]).to eql(10)
|
589
589
|
end
|
590
590
|
|
591
|
-
it "
|
591
|
+
it "is settable to another value with [:attr]=" do
|
592
592
|
@klass[:attr] = 5
|
593
|
-
@klass.attr.
|
594
|
-
@klass[:attr].
|
593
|
+
expect(@klass.attr).to eql(10)
|
594
|
+
expect(@klass[:attr]).to eql(10)
|
595
595
|
end
|
596
596
|
|
597
|
-
it "
|
597
|
+
it "still defaults to that value after delete" do
|
598
598
|
@klass.attr 5
|
599
599
|
@klass.delete(:attr)
|
600
|
-
@klass.attr.
|
600
|
+
expect(@klass.attr).to eql(4)
|
601
601
|
end
|
602
602
|
|
603
|
-
it "
|
603
|
+
it "still defaults to that value after reset" do
|
604
604
|
@klass.attr 5
|
605
605
|
@klass.reset
|
606
|
-
@klass.attr.
|
606
|
+
expect(@klass.attr).to eql(4)
|
607
607
|
end
|
608
608
|
|
609
609
|
it "save should not save anything for it" do
|
610
|
-
@klass.save.
|
610
|
+
expect(@klass.save).to eql({})
|
611
611
|
end
|
612
612
|
|
613
613
|
it "save with include_defaults should save all defaults" do
|
614
|
-
@klass.save(true).
|
614
|
+
expect(@klass.save(true)).to eql({ :attr => 4 })
|
615
615
|
end
|
616
616
|
|
617
|
-
it "
|
617
|
+
it "saves the new value if it gets set" do
|
618
618
|
@klass.attr 5
|
619
|
-
(saved = @klass.save).
|
619
|
+
expect((saved = @klass.save)).to eql({ :attr => 10 })
|
620
620
|
@klass.reset
|
621
|
-
@klass.attr.
|
621
|
+
expect(@klass.attr).to eql(4)
|
622
622
|
@klass.restore(saved)
|
623
|
-
@klass.attr.
|
623
|
+
expect(@klass.attr).to eql(10)
|
624
624
|
end
|
625
625
|
|
626
|
-
it "
|
626
|
+
it "saves the new value even if it is set to its default value" do
|
627
627
|
@klass.attr 4
|
628
|
-
(saved = @klass.save).
|
628
|
+
expect((saved = @klass.save)).to eql({ :attr => 8 })
|
629
629
|
@klass.reset
|
630
|
-
@klass.save.
|
630
|
+
expect(@klass.save).to eql({})
|
631
631
|
@klass.restore(saved)
|
632
|
-
@klass.save.
|
632
|
+
expect(@klass.save).to eql({ :attr => 8 })
|
633
633
|
end
|
634
634
|
end
|
635
635
|
|
@@ -642,68 +642,68 @@ describe Mixlib::Config do
|
|
642
642
|
end
|
643
643
|
end
|
644
644
|
|
645
|
-
it "
|
646
|
-
@klass.attr.
|
645
|
+
it "defaults to that value" do
|
646
|
+
expect(@klass.attr).to eql(4)
|
647
647
|
end
|
648
648
|
|
649
|
-
it "
|
650
|
-
@klass[:attr].
|
649
|
+
it "defaults to that value when retrieved as a hash" do
|
650
|
+
expect(@klass[:attr]).to eql(4)
|
651
651
|
end
|
652
652
|
|
653
|
-
it "
|
653
|
+
it "is settable to another value" do
|
654
654
|
@klass.attr 5
|
655
|
-
@klass.attr.
|
656
|
-
@klass[:attr].
|
655
|
+
expect(@klass.attr).to eql(10)
|
656
|
+
expect(@klass[:attr]).to eql(10)
|
657
657
|
end
|
658
658
|
|
659
|
-
it "
|
659
|
+
it "is settable to another value with attr=" do
|
660
660
|
@klass.attr = 5
|
661
|
-
@klass.attr.
|
662
|
-
@klass[:attr].
|
661
|
+
expect(@klass.attr).to eql(10)
|
662
|
+
expect(@klass[:attr]).to eql(10)
|
663
663
|
end
|
664
664
|
|
665
|
-
it "
|
665
|
+
it "is settable to another value with [:attr]=" do
|
666
666
|
@klass[:attr] = 5
|
667
|
-
@klass.attr.
|
668
|
-
@klass[:attr].
|
667
|
+
expect(@klass.attr).to eql(10)
|
668
|
+
expect(@klass[:attr]).to eql(10)
|
669
669
|
end
|
670
670
|
|
671
|
-
it "
|
671
|
+
it "still defaults to that value after delete" do
|
672
672
|
@klass.attr 5
|
673
673
|
@klass.delete(:attr)
|
674
|
-
@klass.attr.
|
674
|
+
expect(@klass.attr).to eql(4)
|
675
675
|
end
|
676
676
|
|
677
|
-
it "
|
677
|
+
it "still defaults to that value after reset" do
|
678
678
|
@klass.attr 5
|
679
679
|
@klass.reset
|
680
|
-
@klass.attr.
|
680
|
+
expect(@klass.attr).to eql(4)
|
681
681
|
end
|
682
682
|
|
683
683
|
it "save should not save anything for it" do
|
684
|
-
@klass.save.
|
684
|
+
expect(@klass.save).to eql({})
|
685
685
|
end
|
686
686
|
|
687
687
|
it "save with include_defaults should save all defaults" do
|
688
|
-
@klass.save(true).
|
688
|
+
expect(@klass.save(true)).to eql({ :attr => 4 })
|
689
689
|
end
|
690
690
|
|
691
|
-
it "
|
691
|
+
it "saves the new value if it gets set" do
|
692
692
|
@klass.attr 5
|
693
|
-
(saved = @klass.save).
|
693
|
+
expect((saved = @klass.save)).to eql({ :attr => 10 })
|
694
694
|
@klass.reset
|
695
|
-
@klass.attr.
|
695
|
+
expect(@klass.attr).to eql(4)
|
696
696
|
@klass.restore(saved)
|
697
|
-
@klass.attr.
|
697
|
+
expect(@klass.attr).to eql(10)
|
698
698
|
end
|
699
699
|
|
700
|
-
it "
|
700
|
+
it "saves the new value even if it is set to its default value" do
|
701
701
|
@klass.attr 2
|
702
|
-
(saved = @klass.save).
|
702
|
+
expect((saved = @klass.save)).to eql({ :attr => 4 })
|
703
703
|
@klass.reset
|
704
|
-
@klass.save.
|
704
|
+
expect(@klass.save).to eql({})
|
705
705
|
@klass.restore(saved)
|
706
|
-
@klass.save.
|
706
|
+
expect(@klass.save).to eql({ :attr => 4 })
|
707
707
|
end
|
708
708
|
end
|
709
709
|
|
@@ -720,63 +720,63 @@ describe Mixlib::Config do
|
|
720
720
|
end
|
721
721
|
|
722
722
|
it "configurable defaults in that context work" do
|
723
|
-
@klass.blah.x.
|
723
|
+
expect(@klass.blah.x).to eql(5)
|
724
724
|
end
|
725
725
|
|
726
726
|
it "after setting values in the context, the values remain set" do
|
727
727
|
@klass.blah.x = 10
|
728
|
-
@klass.blah.x.
|
728
|
+
expect(@klass.blah.x).to eql(10)
|
729
729
|
end
|
730
730
|
|
731
731
|
it "setting values with the same name in the parent context do not affect the child context" do
|
732
732
|
@klass.x = 10
|
733
|
-
@klass.x.
|
734
|
-
@klass.blah.x.
|
733
|
+
expect(@klass.x).to eql(10)
|
734
|
+
expect(@klass.blah.x).to eql(5)
|
735
735
|
end
|
736
736
|
|
737
737
|
it "setting the entire context to a hash with default value overridden sets the value" do
|
738
738
|
@klass.blah = { :x => 10 }
|
739
|
-
@klass.blah.x.
|
739
|
+
expect(@klass.blah.x).to eql(10)
|
740
740
|
end
|
741
741
|
|
742
742
|
it "setting the entire context to a hash sets non-default values" do
|
743
743
|
@klass.blah = { :y => 10 }
|
744
|
-
@klass.blah.x.
|
745
|
-
@klass.blah.y.
|
744
|
+
expect(@klass.blah.x).to eql(5)
|
745
|
+
expect(@klass.blah.y).to eql(10)
|
746
746
|
end
|
747
747
|
|
748
748
|
it "setting the entire context to a hash deletes any non-default values and resets default values" do
|
749
749
|
@klass.blah.x = 10
|
750
750
|
@klass.blah.y = 10
|
751
751
|
@klass.blah = { :z => 10 }
|
752
|
-
@klass.blah.x.
|
753
|
-
@klass.blah.y.
|
754
|
-
@klass.blah.z.
|
752
|
+
expect(@klass.blah.x).to eql(5)
|
753
|
+
expect(@klass.blah.y).to be_nil
|
754
|
+
expect(@klass.blah.z).to eql(10)
|
755
755
|
end
|
756
756
|
|
757
757
|
it "after reset of the parent class, children are reset" do
|
758
758
|
@klass.blah.x = 10
|
759
|
-
@klass.blah.x.
|
759
|
+
expect(@klass.blah.x).to eql(10)
|
760
760
|
@klass.reset
|
761
|
-
@klass.blah.x.
|
761
|
+
expect(@klass.blah.x).to eql(5)
|
762
762
|
end
|
763
763
|
|
764
764
|
it "save should not save anything for it by default" do
|
765
|
-
@klass.save.
|
765
|
+
expect(@klass.save).to eql({})
|
766
766
|
end
|
767
767
|
|
768
768
|
it "save with include_defaults should save all defaults" do
|
769
|
-
@klass.save(true).
|
769
|
+
expect(@klass.save(true)).to eql({ :blah => { :x => 5 } })
|
770
770
|
end
|
771
771
|
|
772
|
-
it "
|
772
|
+
it "saves any new values that are set in the context" do
|
773
773
|
@klass.blah.x = 10
|
774
|
-
(saved = @klass.save).
|
774
|
+
expect((saved = @klass.save)).to eql({ :blah => { :x => 10 } })
|
775
775
|
@klass.reset
|
776
|
-
@klass.blah.x.
|
776
|
+
expect(@klass.blah.x).to eql(5)
|
777
777
|
@klass.restore(saved)
|
778
|
-
@klass.blah.x.
|
779
|
-
@klass.save.
|
778
|
+
expect(@klass.blah.x).to eql(10)
|
779
|
+
expect(@klass.save).to eql({ :blah => { :x => 10 } })
|
780
780
|
end
|
781
781
|
end
|
782
782
|
|
@@ -788,6 +788,7 @@ describe Mixlib::Config do
|
|
788
788
|
config_context(:blah) do
|
789
789
|
config_context(:yarr) do
|
790
790
|
default :x, 5
|
791
|
+
default :y, 6
|
791
792
|
end
|
792
793
|
end
|
793
794
|
configurable :x
|
@@ -795,43 +796,65 @@ describe Mixlib::Config do
|
|
795
796
|
end
|
796
797
|
|
797
798
|
it "configurable defaults in that context work" do
|
798
|
-
@klass.blah.yarr.x.
|
799
|
+
expect(@klass.blah.yarr.x).to eql(5)
|
800
|
+
expect(@klass.blah.yarr.y).to eql(6)
|
799
801
|
end
|
800
802
|
|
801
803
|
it "after setting values in the context, the values remain set" do
|
802
804
|
@klass.blah.yarr.x = 10
|
803
|
-
@klass.blah.yarr.
|
805
|
+
@klass.blah.yarr.y = 11
|
806
|
+
expect(@klass.blah.yarr.x).to eql(10)
|
807
|
+
expect(@klass.blah.yarr.y).to eql(11)
|
804
808
|
end
|
805
809
|
|
806
810
|
it "setting values with the same name in the parent context do not affect the child context" do
|
807
811
|
@klass.x = 10
|
808
|
-
@klass.x.
|
809
|
-
@klass.blah.yarr.x.
|
812
|
+
expect(@klass.x).to eql(10)
|
813
|
+
expect(@klass.blah.yarr.x).to eql(5)
|
810
814
|
end
|
811
815
|
|
812
816
|
it "after reset of the parent class, children are reset" do
|
813
817
|
@klass.blah.yarr.x = 10
|
814
|
-
@klass.blah.yarr.
|
818
|
+
@klass.blah.yarr.y = 11
|
819
|
+
expect(@klass.blah.yarr.x).to eql(10)
|
820
|
+
expect(@klass.blah.yarr.y).to eql(11)
|
815
821
|
@klass.reset
|
816
|
-
@klass.blah.yarr.x.
|
822
|
+
expect(@klass.blah.yarr.x).to eql(5)
|
823
|
+
expect(@klass.blah.yarr.y).to eql(6)
|
817
824
|
end
|
818
825
|
|
819
826
|
it "save should not save anything for it by default" do
|
820
|
-
@klass.save.
|
827
|
+
expect(@klass.save).to eql({})
|
821
828
|
end
|
822
829
|
|
823
830
|
it "save with include_defaults should save all defaults" do
|
824
|
-
@klass.save(true).
|
831
|
+
expect(@klass.save(true)).to eql({ :blah => { :yarr => { :x => 5, :y => 6 } } })
|
825
832
|
end
|
826
833
|
|
827
|
-
it "
|
834
|
+
it "saves any new values that are set in the context" do
|
828
835
|
@klass.blah.yarr.x = 10
|
829
|
-
|
836
|
+
@klass.blah.yarr.y = 11
|
837
|
+
expect((saved = @klass.save)).to eql({ :blah => { :yarr => { :x => 10, :y => 11 } } })
|
830
838
|
@klass.reset
|
831
|
-
@klass.blah.yarr.x.
|
839
|
+
expect(@klass.blah.yarr.x).to eql(5)
|
840
|
+
expect(@klass.blah.yarr.y).to eql(6)
|
832
841
|
@klass.restore(saved)
|
833
|
-
@klass.blah.yarr.x.
|
834
|
-
@klass.
|
842
|
+
expect(@klass.blah.yarr.x).to eql(10)
|
843
|
+
expect(@klass.blah.yarr.y).to eql(11)
|
844
|
+
expect(@klass.save).to eql({ :blah => { :yarr => { :x => 10, :y => 11 } } })
|
845
|
+
end
|
846
|
+
|
847
|
+
it "restores defaults not included in saved data" do
|
848
|
+
@klass.restore( :blah => { :yarr => { :x => 10 } } )
|
849
|
+
expect(@klass.blah.yarr.x).to eql(10)
|
850
|
+
expect(@klass.blah.yarr.y).to eql(6)
|
851
|
+
end
|
852
|
+
|
853
|
+
it "resmoves added properties not included in saved state" do
|
854
|
+
@klass.blah.yarr.z = 12
|
855
|
+
@klass.restore( :blah => { :yarr => { :x => 10 } } )
|
856
|
+
expect(@klass.blah.yarr.x).to eql(10)
|
857
|
+
expect(@klass.blah.yarr.z).to eql(nil)
|
835
858
|
end
|
836
859
|
end
|
837
860
|
|
@@ -847,11 +870,11 @@ describe Mixlib::Config do
|
|
847
870
|
end
|
848
871
|
|
849
872
|
it "save does not save the hash for the config_context" do
|
850
|
-
@klass.save.
|
873
|
+
expect(@klass.save).to eql({})
|
851
874
|
end
|
852
875
|
|
853
876
|
it "save with defaults saves the hash for the config_context" do
|
854
|
-
@klass.save(true).
|
877
|
+
expect(@klass.save(true)).to eql({ :blah => {} })
|
855
878
|
end
|
856
879
|
end
|
857
880
|
|
@@ -865,11 +888,11 @@ describe Mixlib::Config do
|
|
865
888
|
end
|
866
889
|
|
867
890
|
it "save does not save the hash for the config_context" do
|
868
|
-
@klass.save.
|
891
|
+
expect(@klass.save).to eql({})
|
869
892
|
end
|
870
893
|
|
871
894
|
it "save with defaults saves the hash for the config_context" do
|
872
|
-
@klass.save(true).
|
895
|
+
expect(@klass.save(true)).to eql({ :blah => {} })
|
873
896
|
end
|
874
897
|
end
|
875
898
|
|
@@ -887,7 +910,7 @@ describe Mixlib::Config do
|
|
887
910
|
end
|
888
911
|
|
889
912
|
it "The nested class does not allow you to set arbitrary config options" do
|
890
|
-
lambda { StrictClass2.c.y = 10 }.
|
913
|
+
expect(lambda { StrictClass2.c.y = 10 }).to raise_error(Mixlib::Config::UnknownConfigOptionError, "Cannot set unsupported config value y.")
|
891
914
|
end
|
892
915
|
end
|
893
916
|
|
@@ -900,11 +923,11 @@ describe Mixlib::Config do
|
|
900
923
|
end
|
901
924
|
|
902
925
|
it "The parent class does not allow you to set arbitrary config options" do
|
903
|
-
lambda { StrictClass3.y = 10 }.
|
926
|
+
expect(lambda { StrictClass3.y = 10 }).to raise_error(Mixlib::Config::UnknownConfigOptionError, "Cannot set unsupported config value y.")
|
904
927
|
end
|
905
928
|
|
906
929
|
it "The nested class does not allow you to set arbitrary config options" do
|
907
|
-
lambda { StrictClass3.y = 10 }.
|
930
|
+
expect(lambda { StrictClass3.y = 10 }).to raise_error(Mixlib::Config::UnknownConfigOptionError, "Cannot set unsupported config value y.")
|
908
931
|
end
|
909
932
|
end
|
910
933
|
|
@@ -931,27 +954,27 @@ describe Mixlib::Config do
|
|
931
954
|
it "When a config_context is opened in place of a regular configurable, an error is raised" do
|
932
955
|
klass = Class.new
|
933
956
|
klass.extend(::Mixlib::Config)
|
934
|
-
lambda do
|
957
|
+
expect(lambda do
|
935
958
|
klass.class_eval do
|
936
959
|
default :blah, 10
|
937
960
|
config_context(:blah) do
|
938
961
|
default :y, 20
|
939
962
|
end
|
940
963
|
end
|
941
|
-
end.
|
964
|
+
end).to raise_error(Mixlib::Config::ReopenedConfigurableWithConfigContextError)
|
942
965
|
end
|
943
966
|
|
944
967
|
it "When a config_context is opened in place of a regular configurable, an error is raised" do
|
945
968
|
klass = Class.new
|
946
969
|
klass.extend(::Mixlib::Config)
|
947
|
-
lambda do
|
970
|
+
expect(lambda do
|
948
971
|
klass.class_eval do
|
949
972
|
config_context(:blah) do
|
950
973
|
default :y, 20
|
951
974
|
end
|
952
975
|
default :blah, 10
|
953
976
|
end
|
954
|
-
end.
|
977
|
+
end).to raise_error(Mixlib::Config::ReopenedConfigContextWithConfigurableError)
|
955
978
|
end
|
956
979
|
|
957
980
|
end
|