whiskey_disk 0.0.7 → 0.3.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.
- data/.gitignore +0 -1
- data/README +152 -108
- data/TODO.txt +32 -12
- data/VERSION +1 -1
- data/bin/wd +36 -0
- data/lib/whiskey_disk/config.rb +79 -38
- data/lib/whiskey_disk/rake.rb +36 -0
- data/lib/whiskey_disk.rb +24 -11
- data/spec/wd_command_spec.rb +421 -0
- data/spec/whiskey_disk/config_spec.rb +356 -221
- data/spec/whiskey_disk/rake_spec.rb +255 -0
- data/spec/whiskey_disk_spec.rb +85 -19
- data/tasks/deploy.rake +1 -1
- data/whiskey_disk.gemspec +76 -0
- metadata +35 -15
- data/lib/tasks/deploy.rb +0 -37
- data/spec/tasks/deploy_spec.rb +0 -295
@@ -2,283 +2,418 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper.rb
|
|
2
2
|
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'lib', 'whiskey_disk', 'config'))
|
3
3
|
require 'yaml'
|
4
4
|
|
5
|
-
|
5
|
+
CURRENT_FILE = File.expand_path(__FILE__) # Bacon evidently mucks around with __FILE__ or something related :-/
|
6
|
+
CURRENT = File.expand_path(File.dirname(__FILE__)) # Bacon evidently mucks around with __FILE__ or something related :-/
|
6
7
|
|
7
8
|
describe WhiskeyDisk::Config do
|
9
|
+
describe 'when computing the environment name' do
|
10
|
+
it 'should return false when there is no ENV["to"] setting' do
|
11
|
+
ENV['to'] = nil
|
12
|
+
WhiskeyDisk::Config.environment_name.should == false
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should return false when the ENV["to"] setting is blank' do
|
16
|
+
ENV['to'] = ''
|
17
|
+
WhiskeyDisk::Config.environment_name.should == false
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should return the ENV["to"] setting when it is non-blank' do
|
21
|
+
ENV['to'] = 'staging'
|
22
|
+
WhiskeyDisk::Config.environment_name.should == 'staging'
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should return the environment portion of the ENV["to"] setting when a project is specified' do
|
26
|
+
ENV['to'] = 'project:staging'
|
27
|
+
WhiskeyDisk::Config.environment_name.should == 'staging'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
8
31
|
describe 'when fetching configuration' do
|
32
|
+
before do
|
33
|
+
ENV['to'] = @env = 'foo:staging'
|
34
|
+
end
|
35
|
+
|
9
36
|
it 'should fail if the current environment cannot be determined' do
|
10
37
|
ENV['to'] = nil
|
11
38
|
lambda { WhiskeyDisk::Config.fetch }.should.raise
|
12
39
|
end
|
13
40
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
it 'should return the main configuration yaml file data for this environment as a hash' do
|
41
|
-
staging = { 'foo' => 'bar', 'baz' => 'xyzzy' }
|
42
|
-
WhiskeyDisk::Config.stub!(:main_configuration_data).and_return(YAML.dump({ 'production' => { 'a' => 'b'}, 'staging' => staging }))
|
43
|
-
result = WhiskeyDisk::Config.fetch
|
44
|
-
staging.each_pair do |k,v|
|
45
|
-
result[k].should == v
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'should not include configuration information for other environments in the returned hash' do
|
50
|
-
staging = { 'foo' => 'bar', 'baz' => 'xyzzy' }
|
51
|
-
WhiskeyDisk::Config.stub!(:main_configuration_data).and_return(YAML.dump({ 'production' => { 'a' => 'b'}, 'staging' => staging }))
|
52
|
-
WhiskeyDisk::Config.fetch['a'].should.be.nil
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'should include the environment in the hash' do
|
56
|
-
staging = { 'foo' => 'bar', 'baz' => 'xyzzy' }
|
57
|
-
WhiskeyDisk::Config.stub!(:main_configuration_data).and_return(YAML.dump({ 'production' => { 'a' => 'b'}, 'staging' => staging }))
|
58
|
-
WhiskeyDisk::Config.fetch['environment'].should == 'staging'
|
59
|
-
end
|
60
|
-
|
61
|
-
it 'should not allow overriding the environment in the configuration file' do
|
62
|
-
staging = { 'foo' => 'bar', 'baz' => 'xyzzy', 'environment' => 'production' }
|
63
|
-
WhiskeyDisk::Config.stub!(:main_configuration_data).and_return(YAML.dump({ 'production' => { 'a' => 'b'}, 'staging' => staging }))
|
64
|
-
WhiskeyDisk::Config.fetch['environment'].should == 'staging'
|
65
|
-
end
|
66
|
-
|
67
|
-
it 'should include the project handle in the hash' do
|
68
|
-
staging = { 'foo' => 'bar', 'baz' => 'xyzzy' }
|
69
|
-
WhiskeyDisk::Config.stub!(:project_name).and_return('whiskey_disk')
|
70
|
-
WhiskeyDisk::Config.stub!(:main_configuration_data).and_return(YAML.dump({ 'production' => { 'a' => 'b'}, 'staging' => staging }))
|
71
|
-
WhiskeyDisk::Config.fetch['project'].should == 'whiskey_disk'
|
41
|
+
it 'should fail if the configuration file does not exist' do
|
42
|
+
WhiskeyDisk::Config.stub!(:configuration_file).and_return(__FILE__ + "_.crap")
|
43
|
+
lambda { WhiskeyDisk::Config.fetch }.should.raise
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should fail if the configuration file cannot be read' do
|
47
|
+
WhiskeyDisk::Config.stub!(:configuration_file).and_return("/tmp")
|
48
|
+
lambda { WhiskeyDisk::Config.fetch }.should.raise
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should fail if the configuration file is invalid' do
|
52
|
+
YAML.stub!(:load).and_raise
|
53
|
+
lambda { WhiskeyDisk::Config.fetch }.should.raise
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'should fail if the configuration file does not define data for this environment' do
|
57
|
+
WhiskeyDisk::Config.stub!(:configuration_data).and_return(YAML.dump({'foo' => { 'production' => { 'a' => 'b'}}}))
|
58
|
+
lambda { WhiskeyDisk::Config.fetch }.should.raise
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'should return the configuration yaml file data for this environment as a hash' do
|
62
|
+
staging = { 'foo' => 'bar', 'repository' => 'xyzzy' }
|
63
|
+
WhiskeyDisk::Config.stub!(:configuration_data).and_return(YAML.dump({'foo' => { 'production' => { 'repository' => 'b'}, 'staging' => staging }}))
|
64
|
+
result = WhiskeyDisk::Config.fetch
|
65
|
+
staging.each_pair do |k,v|
|
66
|
+
result[k].should == v
|
72
67
|
end
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'should not include configuration information for other environments in the returned hash' do
|
71
|
+
staging = { 'foo' => 'bar', 'baz' => 'xyzzy' }
|
72
|
+
WhiskeyDisk::Config.stub!(:configuration_data).and_return(YAML.dump({ 'production' => { 'repository' => 'c', 'a' => 'b'}, 'staging' => staging }))
|
73
|
+
WhiskeyDisk::Config.fetch['a'].should.be.nil
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'should include the environment in the hash' do
|
77
|
+
staging = { 'foo' => 'bar', 'baz' => 'xyzzy' }
|
78
|
+
WhiskeyDisk::Config.stub!(:configuration_data).and_return(YAML.dump({'foo' => { 'production' => { 'repository' => 'b'}, 'staging' => staging }}))
|
79
|
+
WhiskeyDisk::Config.fetch['environment'].should == 'staging'
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'should not allow overriding the environment in the configuration file' do
|
83
|
+
staging = { 'foo' => 'bar', 'repository' => 'xyzzy', 'environment' => 'production' }
|
84
|
+
WhiskeyDisk::Config.stub!(:configuration_data).and_return(YAML.dump({'foo' => { 'production' => { 'repository' => 'b'}, 'staging' => staging }}))
|
85
|
+
WhiskeyDisk::Config.fetch['environment'].should == 'staging'
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'should include the project handle in the hash' do
|
89
|
+
staging = { 'foo' => 'bar', 'repository' => 'xyzzy' }
|
90
|
+
WhiskeyDisk::Config.stub!(:configuration_data).and_return(YAML.dump({'foo' => { 'production' => { 'repository' => 'b'}, 'staging' => staging }}))
|
91
|
+
WhiskeyDisk::Config.fetch['project'].should == 'foo'
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'should not allow overriding the project handle in the configuration file' do
|
95
|
+
staging = { 'foo' => 'bar', 'repository' => 'xyzzy', 'project' => 'diskey_whisk' }
|
96
|
+
WhiskeyDisk::Config.stub!(:configuration_data).and_return(YAML.dump({'foo' => { 'production' => { 'repository' => 'b'}, 'staging' => staging }}))
|
97
|
+
WhiskeyDisk::Config.fetch['project'].should == 'foo'
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe 'returning configuration data from a configuration file' do
|
102
|
+
it 'should fail if the configuration file does not exist' do
|
103
|
+
WhiskeyDisk::Config.stub!(:configuration_file).and_return(CURRENT_FILE + '._crap')
|
104
|
+
lambda { WhiskeyDisk::Config.configuration_data }.should.raise
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'should return the contents of the configuration file' do
|
108
|
+
WhiskeyDisk::Config.stub!(:configuration_file).and_return(CURRENT_FILE)
|
109
|
+
File.stub!(:read).with(CURRENT_FILE).and_return('file contents')
|
110
|
+
WhiskeyDisk::Config.configuration_data.should == 'file contents'
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
describe 'transforming data from the configuration file' do
|
115
|
+
it 'should fail if the configuration data cannot be loaded' do
|
116
|
+
WhiskeyDisk::Config.stub!(:configuration_data).and_raise
|
117
|
+
lambda { WhiskeyDisk::Config.load_data }.should.raise
|
118
|
+
end
|
119
|
+
|
120
|
+
it 'should fail if converting the configuration data from YAML fails' do
|
121
|
+
WhiskeyDisk::Config.stub!(:configuration_data).and_return('configuration data')
|
122
|
+
YAML.stub!(:load).and_raise
|
123
|
+
lambda { WhiskeyDisk::Config.load_data }.should.raise
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'should return a normalized version of the un-YAMLized configuration data' do
|
127
|
+
data = { 'a' => 'b', 'c' => 'd' }
|
128
|
+
WhiskeyDisk::Config.stub!(:configuration_data).and_return(YAML.dump(data))
|
129
|
+
WhiskeyDisk::Config.stub!(:normalize_data).with(data).and_return('normalized data')
|
130
|
+
WhiskeyDisk::Config.load_data.should == 'normalized data'
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
describe 'normalizing YAML data from the configuration file' do
|
135
|
+
before do
|
136
|
+
ENV['to'] = @env = 'foo:staging'
|
73
137
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
138
|
+
@bare_data = { 'repository' => 'git://foo/bar.git', 'domain' => 'ogc@ogtastic.com' }
|
139
|
+
@env_data = { 'staging' => @bare_data }
|
140
|
+
@proj_data = { 'foo' => @env_data }
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'should fail if the configuration data is not a hash' do
|
144
|
+
lambda { WhiskeyDisk::Config.normalize_data([]) }.should.raise
|
80
145
|
end
|
81
146
|
|
82
|
-
describe 'when
|
147
|
+
describe 'when no project name is specified via ENV["to"]' do
|
83
148
|
before do
|
84
149
|
ENV['to'] = @env = 'staging'
|
85
|
-
WhiskeyDisk::Config.stub!(:environment_configuration_file).and_return(__FILE__)
|
86
|
-
WhiskeyDisk::Config.stub!(:main_configuration_file).and_return(__FILE__)
|
87
150
|
end
|
88
151
|
|
89
|
-
it 'should
|
90
|
-
WhiskeyDisk::Config.
|
91
|
-
lambda { WhiskeyDisk::Config.fetch }.should.raise(RuntimeError)
|
152
|
+
it 'should return the original data if it has both project and environment scoping' do
|
153
|
+
WhiskeyDisk::Config.normalize_data(@proj_data).should == @proj_data
|
92
154
|
end
|
93
|
-
|
94
|
-
it 'should
|
95
|
-
WhiskeyDisk::Config.
|
96
|
-
lambda { WhiskeyDisk::Config.fetch }.should.raise(RuntimeError)
|
97
|
-
end
|
98
|
-
|
99
|
-
it 'should fail if the main configuration file is invalid' do
|
100
|
-
YAML.stub!(:load).and_raise
|
101
|
-
lambda { WhiskeyDisk::Config.fetch }.should.raise
|
102
|
-
end
|
103
|
-
|
104
|
-
it 'should fail if the separate configuration file cannot be read' do
|
105
|
-
WhiskeyDisk::Config.stub!(:main_configuration_data).and_return(YAML.dump({}))
|
106
|
-
WhiskeyDisk::Config.stub!(:environment_configuration_file).and_return("/tmp")
|
107
|
-
lambda { WhiskeyDisk::Config.fetch }.should.raise
|
108
|
-
end
|
109
|
-
|
110
|
-
it 'should fail if the separate configuration file is invalid' do
|
111
|
-
WhiskeyDisk::Config.stub!(:main_configuration_data).and_return(YAML.dump({}))
|
112
|
-
WhiskeyDisk::Config.stub!(:environment_configuration_data).and_return('BAD DATA')
|
113
|
-
YAML.stub!(:load).with('BAD DATA').and_raise
|
114
|
-
lambda { WhiskeyDisk::Config.fetch }.should.raise
|
115
|
-
end
|
116
|
-
|
117
|
-
it 'should fail if the separate configuration file does not define data for this environment' do
|
118
|
-
WhiskeyDisk::Config.stub!(:main_configuration_data).and_return(YAML.dump({}))
|
119
|
-
WhiskeyDisk::Config.stub!(:environment_configuration_data).and_return(YAML.dump({ 'production' => { 'a' => 'b'} }))
|
120
|
-
lambda { WhiskeyDisk::Config.fetch }.should.raise
|
121
|
-
end
|
122
|
-
|
123
|
-
it 'should return the merger of main and separate yaml configuration data as a hash' do
|
124
|
-
main = { 'staging' => { 'foo' => 'bar'}}
|
125
|
-
env = { 'staging' => { 'baz' => 'xyzzy'}}
|
126
|
-
WhiskeyDisk::Config.stub!(:main_configuration_data).and_return(YAML.dump(main))
|
127
|
-
WhiskeyDisk::Config.stub!(:environment_configuration_data).and_return(YAML.dump(env))
|
128
|
-
result = WhiskeyDisk::Config.fetch
|
129
|
-
main.merge(env)['staging'].each_pair {|k,v| result[k].should == v}
|
130
|
-
end
|
131
|
-
|
132
|
-
it 'should work even if main does not provide configuration data for this environment' do
|
133
|
-
main = { 'production' => { 'foo' => 'bar'}}
|
134
|
-
env = { 'staging' => { 'baz' => 'xyzzy'}}
|
135
|
-
WhiskeyDisk::Config.stub!(:main_configuration_data).and_return(YAML.dump(main))
|
136
|
-
WhiskeyDisk::Config.stub!(:environment_configuration_data).and_return(YAML.dump(env))
|
137
|
-
result = WhiskeyDisk::Config.fetch
|
138
|
-
env['staging'].each_pair {|k,v| result[k].should == v}
|
155
|
+
|
156
|
+
it 'should return the original data wrapped in project scope, using a dummy project, if it has environment scoping but no project scoping' do
|
157
|
+
WhiskeyDisk::Config.normalize_data(@env_data).should == { 'unnamed_project' => @env_data }
|
139
158
|
end
|
140
|
-
|
141
|
-
it 'should
|
142
|
-
|
143
|
-
env = { 'staging' => { 'baz' => 'xyzzy', 'foo' => 'mine'}}
|
144
|
-
WhiskeyDisk::Config.stub!(:main_configuration_data).and_return(YAML.dump(main))
|
145
|
-
WhiskeyDisk::Config.stub!(:environment_configuration_data).and_return(YAML.dump(env))
|
146
|
-
result = WhiskeyDisk::Config.fetch
|
147
|
-
env['staging'].each_pair {|k,v| result[k].should == v}
|
148
|
-
end
|
149
|
-
|
150
|
-
it 'should include the environment in the hash' do
|
151
|
-
main = { 'staging' => { 'foo' => 'bar'}}
|
152
|
-
env = { 'staging' => { 'baz' => 'xyzzy'}}
|
153
|
-
WhiskeyDisk::Config.stub!(:main_configuration_data).and_return(YAML.dump(main))
|
154
|
-
WhiskeyDisk::Config.stub!(:environment_configuration_data).and_return(YAML.dump(env))
|
155
|
-
WhiskeyDisk::Config.fetch['environment'].should == 'staging'
|
156
|
-
end
|
157
|
-
|
158
|
-
it 'should not allow overriding the environment in the main configuration file' do
|
159
|
-
main = { 'staging' => { 'foo' => 'bar', 'environment' => 'production'}}
|
160
|
-
env = { 'staging' => { 'baz' => 'xyzzy'}}
|
161
|
-
WhiskeyDisk::Config.stub!(:main_configuration_data).and_return(YAML.dump(main))
|
162
|
-
WhiskeyDisk::Config.stub!(:environment_configuration_data).and_return(YAML.dump(env))
|
163
|
-
WhiskeyDisk::Config.fetch['environment'].should == 'staging'
|
159
|
+
|
160
|
+
it 'should return the original data wrapped in a project scope, using a dummy project, and an environment scope if it has neither scoping' do
|
161
|
+
WhiskeyDisk::Config.normalize_data(@bare_data).should == { 'unnamed_project' => { 'staging' => @bare_data } }
|
164
162
|
end
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
WhiskeyDisk::Config.stub!(:environment_configuration_data).and_return(YAML.dump(env))
|
171
|
-
WhiskeyDisk::Config.fetch['environment'].should == 'staging'
|
163
|
+
end
|
164
|
+
|
165
|
+
describe 'when a project name is specified via ENV["to"]' do
|
166
|
+
before do
|
167
|
+
ENV['to'] = @env = 'whiskey_disk:staging'
|
172
168
|
end
|
173
169
|
|
174
|
-
it 'should
|
175
|
-
|
176
|
-
env = { 'staging' => { 'baz' => 'xyzzy' }}
|
177
|
-
WhiskeyDisk::Config.stub!(:main_configuration_data).and_return(YAML.dump(main))
|
178
|
-
WhiskeyDisk::Config.stub!(:environment_configuration_data).and_return(YAML.dump(env))
|
179
|
-
WhiskeyDisk::Config.stub!(:project_name).and_return('whiskey_disk')
|
180
|
-
WhiskeyDisk::Config.fetch['project'].should == 'whiskey_disk'
|
170
|
+
it 'should return the original data if it has both project and environment scoping' do
|
171
|
+
WhiskeyDisk::Config.normalize_data(@proj_data).should == @proj_data
|
181
172
|
end
|
182
|
-
|
183
|
-
it 'should
|
184
|
-
|
185
|
-
env = { 'staging' => { 'baz' => 'xyzzy' }}
|
186
|
-
WhiskeyDisk::Config.stub!(:main_configuration_data).and_return(YAML.dump(main))
|
187
|
-
WhiskeyDisk::Config.stub!(:environment_configuration_data).and_return(YAML.dump(env))
|
188
|
-
WhiskeyDisk::Config.stub!(:project_name).and_return('whiskey_disk')
|
189
|
-
WhiskeyDisk::Config.fetch['project'].should == 'diskey_whisk'
|
173
|
+
|
174
|
+
it 'should return the original data wrapped in project scope if it has environment scoping but no project scoping' do
|
175
|
+
WhiskeyDisk::Config.normalize_data(@env_data).should == { 'whiskey_disk' => @env_data }
|
190
176
|
end
|
191
|
-
|
192
|
-
it 'should
|
193
|
-
|
194
|
-
env = { 'staging' => { 'baz' => 'xyzzy', 'project' => 'diskey_whisk' }}
|
195
|
-
WhiskeyDisk::Config.stub!(:main_configuration_data).and_return(YAML.dump(main))
|
196
|
-
WhiskeyDisk::Config.stub!(:environment_configuration_data).and_return(YAML.dump(env))
|
197
|
-
WhiskeyDisk::Config.stub!(:project_name).and_return('whiskey_disk')
|
198
|
-
WhiskeyDisk::Config.fetch['project'].should == 'diskey_whisk'
|
177
|
+
|
178
|
+
it 'should return the original data wrapped in a project scope and an environment scope if it has neither scoping' do
|
179
|
+
WhiskeyDisk::Config.normalize_data(@bare_data).should == { 'whiskey_disk' => { 'staging' => @bare_data } }
|
199
180
|
end
|
200
|
-
end
|
201
|
-
end
|
202
|
-
|
203
|
-
describe 'when returning the configuration filenames' do
|
204
|
-
before do
|
205
|
-
ENV['to'] = @env = 'staging'
|
206
|
-
WhiskeyDisk::Config.stub!(:main_configuration_file).and_return('/path/to/main')
|
207
|
-
WhiskeyDisk::Config.stub!(:environment_configuration_file).and_return('/path/to/staging')
|
208
181
|
end
|
182
|
+
end
|
209
183
|
|
210
|
-
|
211
|
-
|
212
|
-
|
184
|
+
describe 'computing the project name from a configuration hash' do
|
185
|
+
it 'should return the project name from the ENV["to"] setting when it is available' do
|
186
|
+
ENV['to'] = 'foo:staging'
|
187
|
+
WhiskeyDisk::Config.project_name.should == 'foo'
|
213
188
|
end
|
214
189
|
|
215
|
-
it 'should
|
216
|
-
|
190
|
+
it 'should fail when ENV["to"] is unset' do
|
191
|
+
ENV['to'] = ''
|
192
|
+
WhiskeyDisk::Config.project_name.should == 'unnamed_project'
|
217
193
|
end
|
218
|
-
|
219
|
-
it 'should
|
220
|
-
|
194
|
+
|
195
|
+
it 'should return "unnamed_project" when no ENV["to"] project setting is available' do
|
196
|
+
ENV['to'] = 'staging'
|
197
|
+
WhiskeyDisk::Config.project_name.should == 'unnamed_project'
|
221
198
|
end
|
222
199
|
end
|
223
200
|
|
224
|
-
describe '
|
225
|
-
|
226
|
-
|
201
|
+
describe 'finding the configuration file' do
|
202
|
+
before do
|
203
|
+
ENV['to'] = @env = 'staging'
|
227
204
|
end
|
228
205
|
|
229
|
-
|
230
|
-
|
231
|
-
|
206
|
+
describe 'and no path is specified' do
|
207
|
+
before do
|
208
|
+
ENV['path'] = @path = nil
|
209
|
+
end
|
210
|
+
|
211
|
+
describe 'and a project name is specified in ENV["to"]' do
|
212
|
+
before do
|
213
|
+
ENV['to'] = @env = 'foo:staging'
|
214
|
+
end
|
215
|
+
|
216
|
+
it 'should return the path to deploy/foo/<environment>.yml under the project base path if it exists' do
|
217
|
+
WhiskeyDisk::Config.stub!(:base_path).and_return('/path/to/project/config')
|
218
|
+
File.stub!(:exists?).with('/path/to/project/config/deploy/foo/staging.yml').and_return(true)
|
219
|
+
WhiskeyDisk::Config.configuration_file.should == '/path/to/project/config/deploy/foo/staging.yml'
|
220
|
+
end
|
221
|
+
|
222
|
+
it 'should return the path to deploy/foo.yml under the project base path if it exists' do
|
223
|
+
WhiskeyDisk::Config.stub!(:base_path).and_return('/path/to/project/config')
|
224
|
+
File.stub!(:exists?).with('/path/to/project/config/deploy/foo/staging.yml').and_return(false)
|
225
|
+
File.stub!(:exists?).with('/path/to/project/config/deploy/foo.yml').and_return(true)
|
226
|
+
WhiskeyDisk::Config.configuration_file.should == '/path/to/project/config/deploy/foo.yml'
|
227
|
+
end
|
228
|
+
|
229
|
+
it 'should return the path to a per-environment configuration file in the deploy/ directory under the project base path if it exists' do
|
230
|
+
WhiskeyDisk::Config.stub!(:base_path).and_return('/path/to/project/config')
|
231
|
+
File.stub!(:exists?).with('/path/to/project/config/deploy/foo/staging.yml').and_return(false)
|
232
|
+
File.stub!(:exists?).with('/path/to/project/config/deploy/foo.yml').and_return(false)
|
233
|
+
File.stub!(:exists?).with('/path/to/project/config/deploy/staging.yml').and_return(true)
|
234
|
+
WhiskeyDisk::Config.configuration_file.should == '/path/to/project/config/deploy/staging.yml'
|
235
|
+
end
|
232
236
|
|
233
|
-
|
234
|
-
|
235
|
-
|
237
|
+
it 'should return the path to a per-environment configuration file under the project base path if it exists' do
|
238
|
+
WhiskeyDisk::Config.stub!(:base_path).and_return('/path/to/project/config')
|
239
|
+
File.stub!(:exists?).with('/path/to/project/config/deploy/foo/staging.yml').and_return(false)
|
240
|
+
File.stub!(:exists?).with('/path/to/project/config/deploy/foo.yml').and_return(false)
|
241
|
+
File.stub!(:exists?).with('/path/to/project/config/deploy/staging.yml').and_return(false)
|
242
|
+
File.stub!(:exists?).with('/path/to/project/config/staging.yml').and_return(true)
|
243
|
+
WhiskeyDisk::Config.configuration_file.should == '/path/to/project/config/staging.yml'
|
244
|
+
end
|
236
245
|
|
237
|
-
|
238
|
-
|
239
|
-
|
246
|
+
it 'should return the path to deploy.yml under the project base path' do
|
247
|
+
WhiskeyDisk::Config.stub!(:base_path).and_return('/path/to/project/config')
|
248
|
+
File.stub!(:exists?).with('/path/to/project/config/deploy/foo/staging.yml').and_return(false)
|
249
|
+
File.stub!(:exists?).with('/path/to/project/config/deploy/foo.yml').and_return(false)
|
250
|
+
File.stub!(:exists?).with('/path/to/project/config/deploy/staging.yml').and_return(false)
|
251
|
+
File.stub!(:exists?).with('/path/to/project/config/staging.yml').and_return(false)
|
252
|
+
File.stub!(:exists?).with('/path/to/project/config/deploy.yml').and_return(true)
|
253
|
+
WhiskeyDisk::Config.configuration_file.should == '/path/to/project/config/deploy.yml'
|
254
|
+
end
|
240
255
|
|
241
|
-
|
242
|
-
|
243
|
-
|
256
|
+
it 'should fail if no per-environment config file nor deploy.yml exists under the project base path' do
|
257
|
+
WhiskeyDisk::Config.stub!(:base_path).and_return('/path/to/project/config')
|
258
|
+
File.stub!(:exists?).with('/path/to/project/config/deploy/foo/staging.yml').and_return(false)
|
259
|
+
File.stub!(:exists?).with('/path/to/project/config/deploy/foo.yml').and_return(false)
|
260
|
+
File.stub!(:exists?).with('/path/to/project/config/deploy/staging.yml').and_return(false)
|
261
|
+
File.stub!(:exists?).with('/path/to/project/config/staging.yml').and_return(false)
|
262
|
+
File.stub!(:exists?).with('/path/to/project/config/deploy.yml').and_return(false)
|
263
|
+
lambda { WhiskeyDisk::Config.configuration_file }.should.raise
|
264
|
+
end
|
265
|
+
end
|
266
|
+
|
267
|
+
describe 'and no project name is specified in ENV["to"]' do
|
268
|
+
it 'should return the path to a per-environment configuration file in the deploy/ directory under the project base path if it exists' do
|
269
|
+
WhiskeyDisk::Config.stub!(:base_path).and_return('/path/to/project/config')
|
270
|
+
File.stub!(:exists?).with('/path/to/project/config/deploy/staging.yml').and_return(true)
|
271
|
+
WhiskeyDisk::Config.configuration_file.should == '/path/to/project/config/deploy/staging.yml'
|
272
|
+
end
|
244
273
|
|
245
|
-
|
246
|
-
|
274
|
+
it 'should return the path to a per-environment configuration file under the project base path if it exists' do
|
275
|
+
WhiskeyDisk::Config.stub!(:base_path).and_return('/path/to/project/config')
|
276
|
+
File.stub!(:exists?).with('/path/to/project/config/deploy/staging.yml').and_return(false)
|
277
|
+
File.stub!(:exists?).with('/path/to/project/config/staging.yml').and_return(true)
|
278
|
+
WhiskeyDisk::Config.configuration_file.should == '/path/to/project/config/staging.yml'
|
279
|
+
end
|
280
|
+
|
281
|
+
it 'should return the path to deploy.yml under the project base path' do
|
282
|
+
WhiskeyDisk::Config.stub!(:base_path).and_return('/path/to/project/config')
|
283
|
+
File.stub!(:exists?).with('/path/to/project/config/deploy/staging.yml').and_return(false)
|
284
|
+
File.stub!(:exists?).with('/path/to/project/config/staging.yml').and_return(false)
|
285
|
+
File.stub!(:exists?).with('/path/to/project/config/deploy.yml').and_return(true)
|
286
|
+
WhiskeyDisk::Config.configuration_file.should == '/path/to/project/config/deploy.yml'
|
287
|
+
end
|
288
|
+
|
289
|
+
it 'should fail if no per-environment config file nor deploy.yml exists under the project base path' do
|
290
|
+
WhiskeyDisk::Config.stub!(:base_path).and_return('/path/to/project/config')
|
291
|
+
File.stub!(:exists?).with('/path/to/project/config/deploy/staging.yml').and_return(false)
|
292
|
+
File.stub!(:exists?).with('/path/to/project/config/staging.yml').and_return(false)
|
293
|
+
File.stub!(:exists?).with('/path/to/project/config/deploy.yml').and_return(false)
|
294
|
+
lambda { WhiskeyDisk::Config.configuration_file }.should.raise
|
295
|
+
end
|
296
|
+
end
|
247
297
|
end
|
248
|
-
end
|
249
298
|
|
250
|
-
|
251
|
-
|
252
|
-
WhiskeyDisk::Config.
|
253
|
-
WhiskeyDisk::Config.main_configuration_file.should == '/path/to/project/config/deploy.yml'
|
299
|
+
it 'should fail if a path is specified which does not exist' do
|
300
|
+
ENV['path'] = @path = (CURRENT_FILE + "_.crap")
|
301
|
+
lambda { WhiskeyDisk::Config.configuration_file }.should.raise
|
254
302
|
end
|
255
|
-
end
|
256
303
|
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
304
|
+
it 'should return the file path when a path which points to an existing file is specified' do
|
305
|
+
ENV['path'] = @path = CURRENT_FILE
|
306
|
+
File.stub!(:exists?).with(@path).and_return(true)
|
307
|
+
WhiskeyDisk::Config.configuration_file.should == @path
|
261
308
|
end
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
309
|
+
|
310
|
+
describe 'and a path which points to a directory is specified' do
|
311
|
+
before do
|
312
|
+
ENV['path'] = @path = CURRENT
|
313
|
+
end
|
314
|
+
|
315
|
+
describe 'and a project name is specified in ENV["to"]' do
|
316
|
+
before do
|
317
|
+
ENV['to'] = @env = 'foo:staging'
|
318
|
+
end
|
319
|
+
|
320
|
+
it 'should return the path to deploy/foo/<environment>.yml under the project base path if it exists' do
|
321
|
+
WhiskeyDisk::Config.stub!(:base_path).and_return(@path)
|
322
|
+
File.stub!(:exists?).with(File.join(@path, 'deploy', 'foo', 'staging.yml')).and_return(true)
|
323
|
+
WhiskeyDisk::Config.configuration_file.should == File.join(@path, 'deploy', 'foo' ,'staging.yml')
|
324
|
+
end
|
325
|
+
|
326
|
+
it 'should return the path to deploy/foo.yml under the project base path if it exists' do
|
327
|
+
WhiskeyDisk::Config.stub!(:base_path).and_return(@path)
|
328
|
+
File.stub!(:exists?).with(File.join(@path, 'deploy', 'foo', 'staging.yml')).and_return(false)
|
329
|
+
File.stub!(:exists?).with(File.join(@path, 'deploy', 'foo.yml')).and_return(true)
|
330
|
+
WhiskeyDisk::Config.configuration_file.should == File.join(@path, 'deploy', 'foo.yml')
|
331
|
+
end
|
332
|
+
|
333
|
+
it 'should return the path to a per-environment configuration file under deploy/ in the path specified if that file exists' do
|
334
|
+
File.stub!(:exists?).with(File.join(@path, 'deploy', 'foo', 'staging.yml')).and_return(false)
|
335
|
+
File.stub!(:exists?).with(File.join(@path, 'deploy', 'foo.yml')).and_return(false)
|
336
|
+
File.stub!(:exists?).with(File.join(@path, 'deploy', 'staging.yml')).and_return(true)
|
337
|
+
WhiskeyDisk::Config.configuration_file.should == File.join(@path, 'deploy', 'staging.yml')
|
338
|
+
end
|
339
|
+
|
340
|
+
it 'should return the path to a per-environment configuration file in the path specified if that file exists' do
|
341
|
+
File.stub!(:exists?).with(File.join(@path, 'deploy', 'foo', 'staging.yml')).and_return(false)
|
342
|
+
File.stub!(:exists?).with(File.join(@path, 'deploy', 'foo.yml')).and_return(false)
|
343
|
+
File.stub!(:exists?).with(File.join(@path, 'deploy', 'staging.yml')).and_return(false)
|
344
|
+
File.stub!(:exists?).with(File.join(@path, 'staging.yml')).and_return(true)
|
345
|
+
WhiskeyDisk::Config.configuration_file.should == File.join(@path, 'staging.yml')
|
346
|
+
end
|
347
|
+
|
348
|
+
it 'should return the path to deploy.yaml in the path specified if deploy.yml exists' do
|
349
|
+
File.stub!(:exists?).with(File.join(@path, 'deploy', 'foo', 'staging.yml')).and_return(false)
|
350
|
+
File.stub!(:exists?).with(File.join(@path, 'deploy', 'foo.yml')).and_return(false)
|
351
|
+
File.stub!(:exists?).with(File.join(@path, 'deploy', 'staging.yml')).and_return(false)
|
352
|
+
File.stub!(:exists?).with(File.join(@path, 'staging.yml')).and_return(false)
|
353
|
+
File.stub!(:exists?).with(File.join(@path, 'deploy.yml')).and_return(true)
|
354
|
+
WhiskeyDisk::Config.configuration_file.should == File.join(@path, 'deploy.yml')
|
355
|
+
end
|
356
|
+
|
357
|
+
it 'should fail if no per-environment configuration file nor deploy.yml exists in the path specified' do
|
358
|
+
File.stub!(:exists?).with(File.join(@path, 'deploy', 'foo', 'staging.yml')).and_return(false)
|
359
|
+
File.stub!(:exists?).with(File.join(@path, 'deploy', 'foo.yml')).and_return(false)
|
360
|
+
File.stub!(:exists?).with(File.join(@path, 'deploy', 'staging.yml')).and_return(false)
|
361
|
+
File.stub!(:exists?).with(File.join(@path, 'staging.yml')).and_return(false)
|
362
|
+
File.stub!(:exists?).with(File.join(@path, 'deploy.yml')).and_return(false)
|
363
|
+
lambda { WhiskeyDisk::Config.configuration_file }.should.raise
|
364
|
+
end
|
365
|
+
end
|
366
|
+
|
367
|
+
describe 'and no project name is specified in ENV["to"]' do
|
368
|
+
it 'should return the path to a per-environment configuration file under deploy/ in the path specified if that file exists' do
|
369
|
+
File.stub!(:exists?).with(File.join(@path, 'deploy', 'staging.yml')).and_return(true)
|
370
|
+
WhiskeyDisk::Config.configuration_file.should == File.join(@path, 'deploy', 'staging.yml')
|
371
|
+
end
|
372
|
+
|
373
|
+
it 'should return the path to a per-environment configuration file in the path specified if that file exists' do
|
374
|
+
File.stub!(:exists?).with(File.join(@path, 'deploy', 'staging.yml')).and_return(false)
|
375
|
+
File.stub!(:exists?).with(File.join(@path, 'staging.yml')).and_return(true)
|
376
|
+
WhiskeyDisk::Config.configuration_file.should == File.join(@path, 'staging.yml')
|
377
|
+
end
|
378
|
+
|
379
|
+
it 'should return the path to deploy.yaml in the path specified if deploy.yml exists' do
|
380
|
+
File.stub!(:exists?).with(File.join(@path, 'deploy', 'staging.yml')).and_return(false)
|
381
|
+
File.stub!(:exists?).with(File.join(@path, 'staging.yml')).and_return(false)
|
382
|
+
File.stub!(:exists?).with(File.join(@path, 'deploy.yml')).and_return(true)
|
383
|
+
WhiskeyDisk::Config.configuration_file.should == File.join(@path, 'deploy.yml')
|
384
|
+
end
|
385
|
+
|
386
|
+
it 'should fail if no per-environment configuration file nor deploy.yml exists in the path specified' do
|
387
|
+
File.stub!(:exists?).with(File.join(@path, 'deploy', 'staging.yml')).and_return(false)
|
388
|
+
File.stub!(:exists?).with(File.join(@path, 'staging.yml')).and_return(false)
|
389
|
+
File.stub!(:exists?).with(File.join(@path, 'deploy.yml')).and_return(false)
|
390
|
+
lambda { WhiskeyDisk::Config.configuration_file }.should.raise
|
391
|
+
end
|
392
|
+
end
|
267
393
|
end
|
268
394
|
end
|
269
395
|
|
270
396
|
describe 'computing the base path for the project' do
|
397
|
+
before do
|
398
|
+
ENV['path'] = @path = nil
|
399
|
+
end
|
400
|
+
|
401
|
+
it 'should return the path set in the "path" environment variable when one is set' do
|
402
|
+
ENV['path'] = @path = CURRENT
|
403
|
+
WhiskeyDisk::Config.base_path.should == @path
|
404
|
+
end
|
405
|
+
|
271
406
|
it 'should fail if there is no Rakefile along the root path to the current directory' do
|
272
407
|
WhiskeyDisk::Config.stub!(:contains_rakefile?).and_return(false)
|
273
408
|
lambda { WhiskeyDisk::Config.base_path }.should.raise
|
274
409
|
end
|
275
410
|
|
276
|
-
it 'return the nearest enclosing path with a Rakefile along the root path to the current directory' do
|
411
|
+
it 'return the config directory in the nearest enclosing path with a Rakefile along the root path to the current directory' do
|
277
412
|
top = ::File.expand_path(File.join(CURRENT, '..', '..'))
|
278
413
|
WhiskeyDisk::Config.stub!(:contains_rakefile?).and_return(false)
|
279
414
|
WhiskeyDisk::Config.stub!(:contains_rakefile?).with(top).and_return(true)
|
280
415
|
Dir.chdir(CURRENT)
|
281
|
-
WhiskeyDisk::Config.base_path.should == top
|
416
|
+
WhiskeyDisk::Config.base_path.should == File.join(top, 'config')
|
282
417
|
end
|
283
418
|
end
|
284
419
|
end
|