configliere 0.3.4 → 0.4.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +3 -0
- data/.watchr +20 -0
- data/CHANGELOG.textile +99 -3
- data/Gemfile +26 -0
- data/Gemfile.lock +54 -0
- data/README.textile +162 -138
- data/Rakefile +30 -21
- data/VERSION +1 -1
- data/bin/configliere +77 -77
- data/bin/configliere-decrypt +85 -0
- data/bin/configliere-delete +85 -0
- data/bin/configliere-dump +85 -0
- data/bin/configliere-encrypt +85 -0
- data/bin/configliere-list +85 -0
- data/bin/configliere-set +85 -0
- data/configliere.gemspec +53 -23
- data/examples/config_block_script.rb +9 -2
- data/examples/encrypted_script.rb +28 -16
- data/examples/env_var_script.rb +2 -2
- data/examples/help_message_demo.rb +16 -0
- data/examples/independent_config.rb +28 -0
- data/examples/prompt.rb +23 -0
- data/examples/simple_script.rb +28 -15
- data/examples/simple_script.yaml +1 -1
- data/lib/configliere.rb +22 -24
- data/lib/configliere/commandline.rb +135 -116
- data/lib/configliere/commands.rb +38 -54
- data/lib/configliere/config_block.rb +4 -2
- data/lib/configliere/config_file.rb +30 -52
- data/lib/configliere/crypter.rb +8 -5
- data/lib/configliere/deep_hash.rb +368 -0
- data/lib/configliere/define.rb +83 -89
- data/lib/configliere/encrypted.rb +17 -18
- data/lib/configliere/env_var.rb +5 -7
- data/lib/configliere/param.rb +37 -64
- data/lib/configliere/prompt.rb +23 -0
- data/spec/configliere/commandline_spec.rb +156 -57
- data/spec/configliere/commands_spec.rb +75 -30
- data/spec/configliere/config_block_spec.rb +10 -1
- data/spec/configliere/config_file_spec.rb +83 -55
- data/spec/configliere/crypter_spec.rb +3 -2
- data/spec/configliere/deep_hash_spec.rb +401 -0
- data/spec/configliere/define_spec.rb +121 -42
- data/spec/configliere/encrypted_spec.rb +53 -20
- data/spec/configliere/env_var_spec.rb +24 -4
- data/spec/configliere/param_spec.rb +25 -27
- data/spec/configliere/prompt_spec.rb +50 -0
- data/spec/configliere_spec.rb +3 -9
- data/spec/spec_helper.rb +17 -6
- metadata +110 -35
- data/lib/configliere/core_ext.rb +0 -2
- data/lib/configliere/core_ext/blank.rb +0 -93
- data/lib/configliere/core_ext/hash.rb +0 -108
- data/lib/configliere/core_ext/sash.rb +0 -170
- data/spec/configliere/core_ext/hash_spec.rb +0 -78
- data/spec/configliere/core_ext/sash_spec.rb +0 -312
@@ -1,49 +1,68 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
-
Configliere.use :define
|
3
2
|
|
4
3
|
describe "Configliere::Define" do
|
5
4
|
before do
|
6
5
|
@config = Configliere::Param.new :normal_param => 'normal'
|
7
6
|
end
|
7
|
+
|
8
8
|
describe 'defining any aspect of a param' do
|
9
9
|
it 'adopts values' do
|
10
|
-
@config.define :
|
11
|
-
@config.
|
10
|
+
@config.define :simple, :description => 'desc'
|
11
|
+
@config.definition_of(:simple).should == { :description => 'desc'}
|
12
12
|
end
|
13
|
+
|
13
14
|
it 'merges new definitions' do
|
14
|
-
@config.define :
|
15
|
-
@config.define :
|
16
|
-
@config.
|
17
|
-
@config.define :
|
18
|
-
@config.
|
15
|
+
@config.define :described_in_steps, :description => 'desc 1'
|
16
|
+
@config.define :described_in_steps, :description => 'desc 2'
|
17
|
+
@config.definition_of(:described_in_steps).should == { :description => 'desc 2'}
|
18
|
+
@config.define :described_in_steps, :encrypted => true
|
19
|
+
@config.definition_of(:described_in_steps).should == { :encrypted => true, :description => 'desc 2'}
|
19
20
|
end
|
21
|
+
|
20
22
|
it 'lists params defined as the given aspect' do
|
21
|
-
@config.define :
|
22
|
-
@config.define :
|
23
|
-
@config.define :
|
24
|
-
@config.
|
25
|
-
@config.
|
23
|
+
@config.define :has_description, :description => 'desc 1'
|
24
|
+
@config.define :also_has_description, :description => 'desc 2'
|
25
|
+
@config.define :no_description, :something_else => 'foo'
|
26
|
+
@config.params_with(:description).should include(:has_description)
|
27
|
+
@config.params_with(:description).should include(:also_has_description)
|
28
|
+
@config.params_with(:description).should_not include(:no_description)
|
26
29
|
end
|
27
30
|
end
|
28
31
|
|
29
|
-
describe '
|
30
|
-
|
31
|
-
@config.define :
|
32
|
-
@config.
|
32
|
+
describe 'definition_of' do
|
33
|
+
it 'with a param, gives me the description hash' do
|
34
|
+
@config.define :has_description, :description => 'desc 1'
|
35
|
+
@config.definition_of(:has_description).should == { :description => 'desc 1' }
|
33
36
|
end
|
34
|
-
it '
|
35
|
-
@config.
|
37
|
+
it 'with a param and attr, gives me the description hash' do
|
38
|
+
@config.define :has_description, :description => 'desc 1'
|
39
|
+
@config.definition_of(:has_description, :description).should == 'desc 1'
|
40
|
+
end
|
41
|
+
it 'symbolizes the param' do
|
42
|
+
@config.define :has_description, :description => 'desc 1'
|
43
|
+
@config.definition_of('has_description').should == { :description => 'desc 1' }
|
44
|
+
@config.definition_of('has_description', 'description').should be_nil
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe 'has_definition?' do
|
49
|
+
before do
|
50
|
+
@config.define :i_am_defined, :description => 'desc 1'
|
36
51
|
end
|
37
|
-
it '
|
38
|
-
@config.
|
52
|
+
it 'is true if defined' do
|
53
|
+
@config.has_definition?(:i_am_defined).should == true
|
39
54
|
end
|
40
|
-
it '
|
41
|
-
@config.
|
42
|
-
@config.described_params.should include(:param_2)
|
55
|
+
it 'is false if not defined' do
|
56
|
+
@config.has_definition?(:i_am_not_defined).should == false
|
43
57
|
end
|
44
58
|
end
|
45
59
|
|
46
|
-
|
60
|
+
it 'takes a description' do
|
61
|
+
@config.define :has_description, :description => 'desc 1'
|
62
|
+
@config.define :also_has_description, :description => 'desc 2'
|
63
|
+
@config.definition_of(:has_description, :description).should == 'desc 1'
|
64
|
+
end
|
65
|
+
|
47
66
|
describe 'type coercion' do
|
48
67
|
[
|
49
68
|
[:boolean, '0', false], [:boolean, 0, false], [:boolean, '', false], [:boolean, [], true], [:boolean, nil, nil],
|
@@ -52,26 +71,48 @@ describe "Configliere::Define" do
|
|
52
71
|
[Integer, '5', 5], [Integer, 5, 5], [Integer, nil, nil], [Integer, '', nil],
|
53
72
|
[Float, '5.2', 5.2], [Float, 5.2, 5.2], [Float, nil, nil], [Float, '', nil],
|
54
73
|
[Symbol, 'foo', :foo], [Symbol, :foo, :foo], [Symbol, nil, nil], [Symbol, '', nil],
|
55
|
-
[Date, '1985-11-05',
|
74
|
+
[Date, '1985-11-05', Date.parse('1985-11-05')], [Date, nil, nil], [Date, '', nil], [Date, 'blah', nil],
|
56
75
|
[DateTime, '1985-11-05 11:00:00', DateTime.parse('1985-11-05 11:00:00')], [DateTime, nil, nil], [DateTime, '', nil], [DateTime, 'blah', nil],
|
57
76
|
[Array, ['this', 'that', 'thother'], ['this', 'that', 'thother']],
|
58
77
|
[Array, 'this,that,thother', ['this', 'that', 'thother']],
|
59
78
|
[Array, 'alone', ['alone'] ],
|
60
79
|
[Array, '', [] ],
|
61
80
|
[Array, nil, nil ],
|
81
|
+
['other', '5', '5'], ['other', 5, 5], ['other', nil, nil], ['other', '', nil],
|
62
82
|
].each do |type, orig, desired|
|
63
83
|
it "for #{type} converts #{orig.inspect} to #{desired.inspect}" do
|
64
|
-
@config.define :
|
65
|
-
@config[:
|
84
|
+
@config.define :has_type, :type => type
|
85
|
+
@config[:has_type] = orig ; @config.resolve! ; @config[:has_type].should == desired
|
66
86
|
end
|
67
87
|
end
|
68
|
-
it 'converts :now to the current moment' do
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
88
|
+
# it 'converts :now to the current moment' do
|
89
|
+
# @config.define :has_type, :type => DateTime
|
90
|
+
# @config[:has_type] = 'now' ; @config.resolve! ; @config[:has_type].should be_within(4).of(DateTime.now, 4)
|
91
|
+
# @config[:has_type] = :now ; @config.resolve! ; @config[:has_type].should be_within(4).of(DateTime.now, 4)
|
92
|
+
# @config.define :has_type, :type => Date
|
93
|
+
# @config[:has_type] = :now ; @config.resolve! ; @config[:has_type].should be_within(4).of(Date.today, 4)
|
94
|
+
# @config[:has_type] = 'now' ; @config.resolve! ; @config[:has_type].should be_within(4).of(Date.today, 4)
|
95
|
+
# end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe 'creates magical methods' do
|
99
|
+
before do
|
100
|
+
@config.define :has_magic_method, :default => 'val1'
|
101
|
+
@config[:no_magic_method] = 'val2'
|
102
|
+
end
|
103
|
+
it 'answers to a getter if the param is defined' do
|
104
|
+
@config.has_magic_method.should == 'val1'
|
105
|
+
end
|
106
|
+
it 'answers to a setter if the param is defined' do
|
107
|
+
@config.has_magic_method = 'new_val1'
|
108
|
+
@config.has_magic_method.should == 'new_val1'
|
109
|
+
@config[:has_magic_method].should == 'new_val1'
|
110
|
+
end
|
111
|
+
it 'does not answer to a getter if the param is not defined' do
|
112
|
+
lambda{ @config.no_magic_method }.should raise_error(NoMethodError)
|
113
|
+
end
|
114
|
+
it 'does not answer to a setter if the param is not defined' do
|
115
|
+
lambda{ @config.no_magic_method = 3 }.should raise_error(NoMethodError)
|
75
116
|
end
|
76
117
|
end
|
77
118
|
|
@@ -83,12 +124,12 @@ describe "Configliere::Define" do
|
|
83
124
|
@config.define :optional_2
|
84
125
|
end
|
85
126
|
it 'lists required params' do
|
86
|
-
@config.
|
87
|
-
@config.
|
127
|
+
@config.params_with(:required).should include(:param_1)
|
128
|
+
@config.params_with(:required).should include(:param_2)
|
88
129
|
end
|
89
|
-
it 'counts false values as
|
130
|
+
it 'counts false values as present' do
|
90
131
|
@config.defaults :param_1 => true, :param_2 => false
|
91
|
-
@config.validate!.should
|
132
|
+
@config.validate!.should equal(@config)
|
92
133
|
end
|
93
134
|
it 'counts nil-but-set values as missing' do
|
94
135
|
@config.defaults :param_1 => true, :param_2 => nil
|
@@ -98,10 +139,48 @@ describe "Configliere::Define" do
|
|
98
139
|
lambda{ @config.validate! }.should raise_error(RuntimeError)
|
99
140
|
end
|
100
141
|
it 'lists all missing values when it raises' do
|
101
|
-
|
102
|
-
lambda{ @config.validate! }.should raise_error(RuntimeError)
|
142
|
+
lambda{ @config.validate! }.should raise_error(RuntimeError, "Missing values for: param_1, param_2")
|
103
143
|
end
|
104
144
|
end
|
105
|
-
end
|
106
145
|
|
146
|
+
describe 'defining deep keys' do
|
147
|
+
it 'allows required params' do
|
148
|
+
@config.define 'delorean.power_supply', :required => true
|
149
|
+
@config[:'delorean.power_supply'] = 'household waste'
|
150
|
+
@config.params_with(:required).should include(:'delorean.power_supply')
|
151
|
+
@config.should == { :normal_param=>"normal", :delorean => { :power_supply => 'household waste' } }
|
152
|
+
lambda{ @config.validate! }.should_not raise_error
|
153
|
+
end
|
154
|
+
|
155
|
+
it 'allows flags' do
|
156
|
+
@config.define 'delorean.power_supply', :flag => 'p'
|
157
|
+
@config.use :commandline
|
158
|
+
ARGV.replace ['-p', 'household waste']
|
159
|
+
@config.params_with(:flag).should include(:'delorean.power_supply')
|
160
|
+
@config.resolve!
|
161
|
+
@config.should == { :normal_param=>"normal", :delorean => { :power_supply => 'household waste' } }
|
162
|
+
ARGV.replace []
|
163
|
+
end
|
164
|
+
|
165
|
+
it 'type converts' do
|
166
|
+
@config.define 'delorean.power_supply', :type => Array
|
167
|
+
@config.use :commandline
|
168
|
+
ARGV.replace ['--delorean.power_supply=household waste,plutonium,lightning']
|
169
|
+
@config.definition_of('delorean.power_supply', :type).should == Array
|
170
|
+
@config.resolve!
|
171
|
+
@config.should == { :normal_param=>"normal", :delorean => { :power_supply => ['household waste', 'plutonium', 'lightning'] } }
|
172
|
+
ARGV.replace []
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
describe '#resolve!' do
|
177
|
+
it 'calls super and returns self' do
|
178
|
+
Configliere::ParamParent.class_eval do def resolve!() dummy ; end ; end
|
179
|
+
@config.should_receive(:dummy)
|
180
|
+
@config.resolve!.should equal(@config)
|
181
|
+
Configliere::ParamParent.class_eval do def resolve!() self ; end ; end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
end
|
107
186
|
|
@@ -1,60 +1,76 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
-
Configliere.use :encrypted
|
3
2
|
|
4
3
|
describe "Configliere::Encrypted" do
|
5
4
|
before do
|
6
5
|
@config = Configliere::Param.new :secret => 'encrypt_me', :normal_param => 'normal'
|
6
|
+
@config.use :encrypted
|
7
7
|
@config.define :secret, :encrypted => true
|
8
|
-
@config
|
8
|
+
@config[:encrypt_pass] = 'pass'
|
9
9
|
end
|
10
10
|
|
11
|
-
describe '
|
12
|
-
it '
|
11
|
+
describe 'defines encrypted params' do
|
12
|
+
it 'with :encrypted => true' do
|
13
13
|
@config.send(:encrypted_params).should include(:secret)
|
14
14
|
end
|
15
|
-
it '
|
15
|
+
it 'but not if :encrypted => false' do
|
16
16
|
@config.define :another_param, :encrypted => false
|
17
17
|
@config.send(:encrypted_params).should_not include(:another_param)
|
18
18
|
@config.send(:encrypted_params).should include(:secret)
|
19
19
|
end
|
20
|
-
it '
|
20
|
+
it 'only if :encrypted is given' do
|
21
21
|
@config.send(:encrypted_params).should_not include(:missing_param)
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
describe '
|
26
|
-
it '
|
27
|
-
|
28
|
-
|
25
|
+
describe 'the encrypt_pass' do
|
26
|
+
it 'will take an environment variable if any exists' do
|
27
|
+
@config[:encrypt_pass] = nil
|
28
|
+
ENV.should_receive(:[]).with('ENCRYPT_PASS').at_least(:once).and_return('monkey')
|
29
|
+
@config.send(:export)
|
30
|
+
@config.send(:instance_variable_get, "@encrypt_pass").should == 'monkey'
|
29
31
|
end
|
30
|
-
it '
|
32
|
+
it 'will take an internal value if given, and remove it' do
|
33
|
+
@config[:encrypt_pass] = 'hello'
|
34
|
+
@config.send(:export)
|
35
|
+
@config.send(:instance_variable_get, "@encrypt_pass").should == 'hello'
|
36
|
+
@config[:encrypt_pass].should be_nil
|
37
|
+
@config.has_key?(:encrypt_pass).should_not be_true
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe 'encrypts' do
|
42
|
+
it 'all params with :encrypted' do
|
31
43
|
Configliere::Crypter.should_receive(:encrypt).with('encrypt_me', 'pass').and_return('ok_encrypted')
|
32
|
-
@config.send(:
|
44
|
+
@config.send(:export).should == { :normal_param => 'normal', :encrypted_secret => 'ok_encrypted'}
|
33
45
|
end
|
34
|
-
|
46
|
+
|
47
|
+
it 'fails unless encrypt_pass is set' do
|
35
48
|
# create the config but don't set an encrypt_pass
|
36
49
|
@config = Configliere::Param.new :secret => 'encrypt_me', :normal_param => 'normal'
|
37
|
-
|
50
|
+
@config.use :encrypted
|
51
|
+
lambda{ @config.send(:encrypted, @config[:secret]) }.should raise_error('Missing encryption password!')
|
38
52
|
end
|
39
53
|
end
|
40
54
|
|
41
|
-
describe '
|
42
|
-
it '
|
55
|
+
describe 'decrypts' do
|
56
|
+
it 'all params marked encrypted' do
|
43
57
|
@config.delete :secret
|
44
58
|
@config.defaults :encrypted_secret => 'decrypt_me'
|
45
59
|
Configliere::Crypter.should_receive(:decrypt).with('decrypt_me', 'pass').and_return('ok_decrypted')
|
46
60
|
@config.send(:resolve_encrypted!)
|
47
|
-
@config.should == { :normal_param => 'normal', :secret => 'ok_decrypted'}
|
61
|
+
@config.should == { :normal_param => 'normal', :secret => 'ok_decrypted' }
|
48
62
|
end
|
49
63
|
end
|
50
64
|
|
51
65
|
describe 'loading a file' do
|
52
66
|
before do
|
53
|
-
@encrypted_str = "
|
67
|
+
@encrypted_str = "KohCTcXr1aAulopntmZ8f5Gqa7PzsBmz+R2vFGYrAeg=\n"
|
54
68
|
end
|
55
69
|
it 'encrypts' do
|
56
70
|
Configliere::Crypter.should_receive(:encrypt).and_return(@encrypted_str)
|
57
|
-
|
71
|
+
FileUtils.stub(:mkdir_p)
|
72
|
+
File.should_receive(:open).and_yield([])
|
73
|
+
YAML.should_receive(:dump).with({ :normal_param => "normal", :encrypted_secret => @encrypted_str })
|
58
74
|
@config.save! '/fake/file'
|
59
75
|
end
|
60
76
|
it 'decrypts' do
|
@@ -63,9 +79,26 @@ describe "Configliere::Encrypted" do
|
|
63
79
|
YAML.should_receive(:load).and_return(@hsh)
|
64
80
|
@config.read 'file.yaml'
|
65
81
|
@config.resolve!
|
82
|
+
@config.should_not include(:encrypted_secret)
|
66
83
|
@config.should == { :loaded_param => "loaded", :secret => 'decrypt_me', :normal_param => 'normal' }
|
67
84
|
end
|
68
85
|
end
|
69
|
-
end
|
70
86
|
|
87
|
+
describe '#resolve!' do
|
88
|
+
it 'calls super and returns self' do
|
89
|
+
Configliere::ParamParent.class_eval do def resolve!() dummy ; end ; end
|
90
|
+
@config.should_receive(:dummy)
|
91
|
+
@config.resolve!.should equal(@config)
|
92
|
+
Configliere::ParamParent.class_eval do def resolve!() self ; end ; end
|
93
|
+
end
|
71
94
|
|
95
|
+
it 'removes the encrypt_pass from sight' do
|
96
|
+
@config[:encrypt_pass] = 'hello'
|
97
|
+
@config.resolve!
|
98
|
+
@config.send(:instance_variable_get, "@encrypt_pass").should == 'hello'
|
99
|
+
@config[:encrypt_pass].should be_nil
|
100
|
+
@config.has_key?(:encrypt_pass).should_not be_true
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
@@ -1,24 +1,44 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
-
Configliere.use :env_var
|
3
2
|
|
4
3
|
describe "Configliere::EnvVar" do
|
5
4
|
before do
|
6
5
|
@config = Configliere::Param.new
|
6
|
+
@config.use :env_var
|
7
7
|
end
|
8
8
|
|
9
|
-
describe '
|
10
|
-
it '
|
9
|
+
describe 'environment variables can be defined' do
|
10
|
+
it 'with #env_vars, a simple value like "HOME" uses the corresponding key :home' do
|
11
11
|
ENV.should_receive(:[]).with('HOME').and_return('/fake/path')
|
12
12
|
@config.env_vars 'HOME'
|
13
13
|
@config[:home].should == '/fake/path'
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
|
+
it 'with #env_vars, a hash pairs environment variables into the individual params' do
|
16
17
|
ENV.should_receive(:[]).with('HOME').and_return('/fake/path')
|
17
18
|
ENV.should_receive(:[]).with('POWER_SUPPLY').and_return('1.21 jigawatts')
|
18
19
|
@config.env_vars :home => 'HOME', 'delorean.power_supply' => 'POWER_SUPPLY'
|
19
20
|
@config[:home].should == '/fake/path'
|
20
21
|
@config[:delorean][:power_supply].should == '1.21 jigawatts'
|
21
22
|
end
|
23
|
+
|
24
|
+
it 'with #define' do
|
25
|
+
ENV.should_receive(:[]).with('HOME').and_return('/fake/path')
|
26
|
+
ENV.should_receive(:[]).with('POWER_SUPPLY').and_return('1.21 jigawatts')
|
27
|
+
@config.define :home, :env_var => 'HOME'
|
28
|
+
@config.define 'delorean.power_supply', :env_var => 'POWER_SUPPLY'
|
29
|
+
@config[:home].should == '/fake/path'
|
30
|
+
@config[:delorean][:power_supply].should == '1.21 jigawatts'
|
31
|
+
end
|
22
32
|
end
|
33
|
+
|
34
|
+
describe '#resolve!' do
|
35
|
+
it 'calls super and returns self' do
|
36
|
+
Configliere::ParamParent.class_eval do def resolve!() dummy ; end ; end
|
37
|
+
@config.should_receive(:dummy)
|
38
|
+
@config.resolve!.should equal(@config)
|
39
|
+
Configliere::ParamParent.class_eval do def resolve!() self ; end ; end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
23
43
|
end
|
24
44
|
|
@@ -5,45 +5,43 @@ describe "Configliere::Param" do
|
|
5
5
|
@config = Configliere::Param.new :hat => :cat, :basket => :lotion, :moon => { :man => :smiling }
|
6
6
|
end
|
7
7
|
|
8
|
-
describe '#defaults' do
|
8
|
+
describe 'calling #defaults' do
|
9
9
|
it 'deep_merges new params' do
|
10
10
|
@config.defaults :basket => :tasket, :moon => { :cow => :jumping }
|
11
11
|
@config.should == { :hat => :cat, :basket => :tasket, :moon => { :man => :smiling, :cow => :jumping } }
|
12
12
|
end
|
13
|
+
it 'returns self, to allow chaining' do
|
14
|
+
obj = @config.defaults(:basket => :ball)
|
15
|
+
obj.should equal(@config)
|
16
|
+
end
|
13
17
|
end
|
14
18
|
|
15
|
-
describe '#
|
16
|
-
|
17
|
-
|
18
|
-
@config['new'] = :unseen
|
19
|
-
# @config.should == { :hat => :fedora, :basket => :lotion, :new => :unseen, :moon => { :man => :smiling } }
|
19
|
+
describe 'adding plugins with #use' do
|
20
|
+
before do
|
21
|
+
Configliere.should_receive(:use).with(:foobar)
|
20
22
|
end
|
21
|
-
it '
|
22
|
-
@config
|
23
|
-
@config[:moon][:man].should == :cheesy
|
23
|
+
it 'requires the corresponding library' do
|
24
|
+
obj = @config.use(:foobar)
|
24
25
|
end
|
25
|
-
it '
|
26
|
-
@config
|
27
|
-
|
26
|
+
it 'returns self, to allow chaining' do
|
27
|
+
obj = @config.use(:foobar)
|
28
|
+
obj.should equal(@config)
|
28
29
|
end
|
29
|
-
it '
|
30
|
-
|
31
|
-
|
30
|
+
it 'invokes the on_use handler' do
|
31
|
+
Configliere::Param.on_use(:foobar) do
|
32
|
+
method_on_config(:param)
|
33
|
+
end
|
34
|
+
@config.should_receive(:method_on_config).with(:param)
|
35
|
+
@config.use(:foobar)
|
32
36
|
end
|
33
37
|
end
|
34
38
|
|
35
|
-
describe '#
|
36
|
-
it '
|
37
|
-
|
38
|
-
@config
|
39
|
-
@config
|
40
|
-
|
41
|
-
@config['moon.cheese.smell'].should be_nil
|
42
|
-
@config['moon.non.existent.interim.values'].should be_nil
|
43
|
-
@config['moon.non'].should be_nil
|
44
|
-
if (RUBY_VERSION >= '1.9') then lambda{ @config['hat.cat'] }.should raise_error(TypeError)
|
45
|
-
else lambda{ @config['hat.cat'] }.should raise_error(NoMethodError, 'undefined method `[]\' for :cat:Symbol') end
|
46
|
-
@config.should == hsh # shouldn't change from reading (specifically, shouldn't autovivify)
|
39
|
+
describe '#resolve!' do
|
40
|
+
it 'calls super and returns self' do
|
41
|
+
Configliere::ParamParent.class_eval do def resolve!() dummy ; end ; end
|
42
|
+
@config.should_receive(:dummy)
|
43
|
+
@config.resolve!.should equal(@config)
|
44
|
+
Configliere::ParamParent.class_eval do def resolve!() self ; end ; end
|
47
45
|
end
|
48
46
|
end
|
49
47
|
|