whiskey_disk 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/README +51 -0
- data/Rakefile +29 -0
- data/TODO.txt +3 -0
- data/VERSION +1 -0
- data/examples/deploy-staging.yml +6 -0
- data/examples/deploy.rake +11 -0
- data/examples/deploy.yml +12 -0
- data/init.rb +1 -0
- data/install.rb +5 -0
- data/lib/tasks/deploy.rb +36 -0
- data/lib/whiskey_disk/config.rb +77 -0
- data/lib/whiskey_disk.rb +122 -0
- data/spec/.bacon +0 -0
- data/spec/init_spec.rb +9 -0
- data/spec/install_spec.rb +43 -0
- data/spec/spec_helper.rb +5 -0
- data/spec/tasks/deploy_spec.rb +277 -0
- data/spec/whiskey_disk/config_spec.rb +276 -0
- data/spec/whiskey_disk_spec.rb +387 -0
- metadata +88 -0
@@ -0,0 +1,277 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper.rb'))
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
describe 'rake tasks' do
|
5
|
+
before do
|
6
|
+
Rake.application = @rake = Rake::Application.new
|
7
|
+
load File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'lib', 'tasks', 'deploy.rb'))
|
8
|
+
WhiskeyDisk.reset
|
9
|
+
end
|
10
|
+
|
11
|
+
after do
|
12
|
+
Rake.application = nil
|
13
|
+
end
|
14
|
+
|
15
|
+
describe 'deploy:setup' do
|
16
|
+
describe 'when a domain is specified' do
|
17
|
+
before do
|
18
|
+
@configuration = { 'domain' => 'some domain'}
|
19
|
+
WhiskeyDisk::Config.stub!(:fetch).and_return(@configuration)
|
20
|
+
[
|
21
|
+
:ensure_main_parent_path_is_present,
|
22
|
+
:ensure_config_parent_path_is_present,
|
23
|
+
:checkout_main_repository,
|
24
|
+
:install_hooks,
|
25
|
+
:checkout_configuration_repository,
|
26
|
+
:refresh_configuration,
|
27
|
+
:run_post_setup_hooks,
|
28
|
+
:flush
|
29
|
+
].each do |meth|
|
30
|
+
WhiskeyDisk.stub!(meth)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should make changes on the specified domain' do
|
35
|
+
@rake["deploy:setup"].invoke
|
36
|
+
WhiskeyDisk.should.be.remote
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should ensure that the parent path for the main repository checkout is present' do
|
40
|
+
WhiskeyDisk.should.receive(:ensure_main_parent_path_is_present)
|
41
|
+
@rake["deploy:setup"].invoke
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should ensure that the parent path for the configuration repository checkout is present' do
|
45
|
+
WhiskeyDisk.should.receive(:ensure_config_parent_path_is_present)
|
46
|
+
@rake["deploy:setup"].invoke
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should check out the main repository' do
|
50
|
+
WhiskeyDisk.should.receive(:checkout_main_repository)
|
51
|
+
@rake["deploy:setup"].invoke
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should install a post-receive hook on the checked out repository' do
|
55
|
+
WhiskeyDisk.should.receive(:install_hooks)
|
56
|
+
@rake["deploy:setup"].invoke
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'should check out the configuration repository' do
|
60
|
+
WhiskeyDisk.should.receive(:checkout_configuration_repository)
|
61
|
+
@rake["deploy:setup"].invoke
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'should refresh the configuration' do
|
65
|
+
WhiskeyDisk.should.receive(:refresh_configuration)
|
66
|
+
@rake["deploy:setup"].invoke
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'should run any post setup hooks' do
|
70
|
+
WhiskeyDisk.should.receive(:run_post_setup_hooks)
|
71
|
+
@rake["deploy:setup"].invoke
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'should flush WhiskeyDisk changes' do
|
75
|
+
WhiskeyDisk.should.receive(:flush)
|
76
|
+
@rake["deploy:setup"].invoke
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe 'when no domain is specified' do
|
81
|
+
before do
|
82
|
+
@configuration = { 'domain' => '' }
|
83
|
+
WhiskeyDisk::Config.stub!(:fetch).and_return(@configuration)
|
84
|
+
|
85
|
+
[
|
86
|
+
:ensure_config_parent_path_is_present,
|
87
|
+
:checkout_configuration_repository,
|
88
|
+
:refresh_configuration,
|
89
|
+
:run_post_setup_hooks,
|
90
|
+
:flush
|
91
|
+
].each do |meth|
|
92
|
+
WhiskeyDisk.stub!(meth)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'should make changes on the local system' do
|
97
|
+
WhiskeyDisk.should.not.be.remote
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'should NOT ensure that the parent path for the main repository checkout is present' do
|
101
|
+
WhiskeyDisk.should.not.receive(:ensure_main_parent_path_is_present)
|
102
|
+
@rake["deploy:setup"].invoke
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'should ensure that the parent path for the configuration repository checkout is present' do
|
106
|
+
WhiskeyDisk.should.receive(:ensure_config_parent_path_is_present)
|
107
|
+
@rake["deploy:setup"].invoke
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'should NOT check out the main repository' do
|
111
|
+
WhiskeyDisk.should.not.receive(:checkout_main_repository)
|
112
|
+
@rake["deploy:setup"].invoke
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'should NOT install a post-receive hook on the checked out repository' do
|
116
|
+
WhiskeyDisk.should.not.receive(:install_hooks)
|
117
|
+
@rake["deploy:setup"].invoke
|
118
|
+
end
|
119
|
+
|
120
|
+
it 'should check out the configuration repository' do
|
121
|
+
WhiskeyDisk.should.receive(:checkout_configuration_repository)
|
122
|
+
@rake["deploy:setup"].invoke
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'should refresh the configuration' do
|
126
|
+
WhiskeyDisk.should.receive(:refresh_configuration)
|
127
|
+
@rake["deploy:setup"].invoke
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'should run any post setup hooks' do
|
131
|
+
WhiskeyDisk.should.receive(:run_post_setup_hooks)
|
132
|
+
@rake["deploy:setup"].invoke
|
133
|
+
end
|
134
|
+
|
135
|
+
it 'should flush WhiskeyDisk changes' do
|
136
|
+
WhiskeyDisk.should.receive(:flush)
|
137
|
+
@rake["deploy:setup"].invoke
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
describe 'deploy:now' do
|
143
|
+
describe 'when a domain is specified' do
|
144
|
+
before do
|
145
|
+
@configuration = { 'domain' => 'some domain'}
|
146
|
+
WhiskeyDisk::Config.stub!(:fetch).and_return(@configuration)
|
147
|
+
[
|
148
|
+
:update_main_repository_checkout,
|
149
|
+
:update_configuration_repository_checkout,
|
150
|
+
:refresh_configuration,
|
151
|
+
:run_post_deploy_hooks,
|
152
|
+
:flush
|
153
|
+
].each do |meth|
|
154
|
+
WhiskeyDisk.stub!(meth)
|
155
|
+
end
|
156
|
+
end
|
157
|
+
it 'should make changes on the specified domain' do
|
158
|
+
@rake["deploy:now"].invoke
|
159
|
+
WhiskeyDisk.should.be.remote
|
160
|
+
end
|
161
|
+
|
162
|
+
it 'should update the main repository checkout' do
|
163
|
+
WhiskeyDisk.should.receive(:update_main_repository_checkout)
|
164
|
+
@rake["deploy:now"].invoke
|
165
|
+
end
|
166
|
+
|
167
|
+
it 'should update the configuration repository checkout' do
|
168
|
+
WhiskeyDisk.should.receive(:update_configuration_repository_checkout)
|
169
|
+
@rake["deploy:now"].invoke
|
170
|
+
end
|
171
|
+
|
172
|
+
it 'should refresh the configuration' do
|
173
|
+
WhiskeyDisk.should.receive(:refresh_configuration)
|
174
|
+
@rake["deploy:now"].invoke
|
175
|
+
end
|
176
|
+
|
177
|
+
it 'should run any post deployment hooks' do
|
178
|
+
WhiskeyDisk.should.receive(:run_post_deploy_hooks)
|
179
|
+
@rake["deploy:now"].invoke
|
180
|
+
end
|
181
|
+
|
182
|
+
it 'should flush WhiskeyDisk changes' do
|
183
|
+
WhiskeyDisk.should.receive(:flush)
|
184
|
+
@rake["deploy:now"].invoke
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
describe 'when no domain is specified' do
|
189
|
+
before do
|
190
|
+
@configuration = { 'domain' => '' }
|
191
|
+
WhiskeyDisk::Config.stub!(:fetch).and_return(@configuration)
|
192
|
+
|
193
|
+
[
|
194
|
+
:update_configuration_repository_checkout,
|
195
|
+
:refresh_configuration,
|
196
|
+
:run_post_deploy_hooks,
|
197
|
+
:flush
|
198
|
+
].each do |meth|
|
199
|
+
WhiskeyDisk.stub!(meth)
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
it 'should make changes on the local system' do
|
204
|
+
WhiskeyDisk.should.not.be.remote
|
205
|
+
end
|
206
|
+
|
207
|
+
it 'should NOT update the main repository checkout' do
|
208
|
+
WhiskeyDisk.should.not.receive(:update_main_repository_checkout)
|
209
|
+
@rake["deploy:now"].invoke
|
210
|
+
end
|
211
|
+
|
212
|
+
it 'should update the configuration repository checkout' do
|
213
|
+
WhiskeyDisk.should.receive(:update_configuration_repository_checkout)
|
214
|
+
@rake["deploy:now"].invoke
|
215
|
+
end
|
216
|
+
|
217
|
+
it 'should refresh the configuration' do
|
218
|
+
WhiskeyDisk.should.receive(:refresh_configuration)
|
219
|
+
@rake["deploy:now"].invoke
|
220
|
+
end
|
221
|
+
|
222
|
+
it 'should run any post deployment hooks' do
|
223
|
+
WhiskeyDisk.should.receive(:run_post_deploy_hooks)
|
224
|
+
@rake["deploy:now"].invoke
|
225
|
+
end
|
226
|
+
|
227
|
+
it 'should flush WhiskeyDisk changes' do
|
228
|
+
WhiskeyDisk.should.receive(:flush)
|
229
|
+
@rake["deploy:now"].invoke
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
describe 'deploy:post_setup' do
|
234
|
+
it 'should run the defined post_setup rake task when a post_setup rake task is defined for this environment' do
|
235
|
+
@configuration = { 'environment' => 'production'}
|
236
|
+
WhiskeyDisk::Config.stub!(:fetch).and_return(@configuration)
|
237
|
+
WhiskeyDisk.reset
|
238
|
+
|
239
|
+
task "deploy:production:post_setup" do
|
240
|
+
WhiskeyDisk.fake_method
|
241
|
+
end
|
242
|
+
|
243
|
+
WhiskeyDisk.should.receive(:fake_method)
|
244
|
+
Rake::Task['deploy:post_setup'].invoke
|
245
|
+
end
|
246
|
+
|
247
|
+
it 'should not fail when no post_setup rake task is defined for this environment' do
|
248
|
+
@configuration = { 'environment' => 'staging'}
|
249
|
+
WhiskeyDisk::Config.stub!(:fetch).and_return(@configuration)
|
250
|
+
WhiskeyDisk.reset
|
251
|
+
lambda { Rake::Task['deploy:post_setup'].invoke }.should.not.raise
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
describe 'deploy:post_deploy' do
|
256
|
+
it 'should run the defined post_deploy rake task when a post_deploy rake task is defined for this environment' do
|
257
|
+
@configuration = { 'environment' => 'production'}
|
258
|
+
WhiskeyDisk::Config.stub!(:fetch).and_return(@configuration)
|
259
|
+
WhiskeyDisk.reset
|
260
|
+
|
261
|
+
task "deploy:production:post_deploy" do
|
262
|
+
WhiskeyDisk.fake_method
|
263
|
+
end
|
264
|
+
|
265
|
+
WhiskeyDisk.should.receive(:fake_method)
|
266
|
+
Rake::Task['deploy:post_deploy'].invoke
|
267
|
+
end
|
268
|
+
|
269
|
+
it 'should not fail when no post_deploy rake task is defined for this environment' do
|
270
|
+
@configuration = { 'environment' => 'staging'}
|
271
|
+
WhiskeyDisk::Config.stub!(:fetch).and_return(@configuration)
|
272
|
+
WhiskeyDisk.reset
|
273
|
+
lambda { Rake::Task['deploy:post_deploy'].invoke }.should.not.raise
|
274
|
+
end
|
275
|
+
end
|
276
|
+
end
|
277
|
+
end
|
@@ -0,0 +1,276 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper.rb'))
|
2
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'lib', 'whiskey_disk', 'config'))
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
CURRENT = File.expand_path(File.dirname(__FILE__)) # BACON evidently mucks around with __FILE__ or something related :-/
|
6
|
+
|
7
|
+
describe WhiskeyDisk::Config do
|
8
|
+
describe 'when fetching configuration' do
|
9
|
+
it 'should fail if the current environment cannot be determined' do
|
10
|
+
ENV['to'] = nil
|
11
|
+
lambda { WhiskeyDisk::Config.fetch }.should.raise
|
12
|
+
end
|
13
|
+
|
14
|
+
describe 'when there is no separate configuration file for the current environment' do
|
15
|
+
before do
|
16
|
+
ENV['to'] = @env = 'staging'
|
17
|
+
WhiskeyDisk::Config.stub!(:environment_configuration_data).and_return(nil)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should fail if the main configuration file does not exist' do
|
21
|
+
WhiskeyDisk::Config.stub!(:main_configuration_file).and_return(__FILE__ + "_.crap")
|
22
|
+
lambda { WhiskeyDisk::Config.fetch }.should.raise
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should fail if the main configuration file cannot be read' do
|
26
|
+
WhiskeyDisk::Config.stub!(:main_configuration_file).and_return("/tmp")
|
27
|
+
lambda { WhiskeyDisk::Config.fetch }.should.raise
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should fail if the main configuration file is invalid' do
|
31
|
+
YAML.stub!(:load).and_raise
|
32
|
+
lambda { WhiskeyDisk::Config.fetch }.should.raise
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should fail if the main configuration file does not define data for this environment' do
|
36
|
+
WhiskeyDisk::Config.stub!(:main_configuration_data).and_return(YAML.dump({ 'production' => { 'a' => 'b'} }))
|
37
|
+
lambda { WhiskeyDisk::Config.fetch }.should.raise
|
38
|
+
end
|
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'
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'should allow overriding the project handle in the configuration file' do
|
75
|
+
staging = { 'foo' => 'bar', 'baz' => 'xyzzy', 'project' => 'diskey_whisk' }
|
76
|
+
WhiskeyDisk::Config.stub!(:project_name).and_return('whiskey_disk')
|
77
|
+
WhiskeyDisk::Config.stub!(:main_configuration_data).and_return(YAML.dump({ 'production' => { 'a' => 'b'}, 'staging' => staging }))
|
78
|
+
WhiskeyDisk::Config.fetch['project'].should == 'diskey_whisk'
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe 'when there is a separate configuration file for the current environment' do
|
83
|
+
before do
|
84
|
+
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
|
+
end
|
88
|
+
|
89
|
+
it 'should fail if the main configuration file does not exist' do
|
90
|
+
WhiskeyDisk::Config.stub!(:main_configuration_file).and_return(__FILE__ + "_.crap")
|
91
|
+
lambda { WhiskeyDisk::Config.fetch }.should.raise(RuntimeError)
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'should fail if the main configuration file cannot be read' do
|
95
|
+
WhiskeyDisk::Config.stub!(:main_configuration_file).and_return("/tmp")
|
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}
|
139
|
+
end
|
140
|
+
|
141
|
+
it 'should override main configuration file data with separate configuration file data when there is a conflict' do
|
142
|
+
main = { 'production' => { 'foo' => 'bar'}}
|
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'
|
164
|
+
end
|
165
|
+
|
166
|
+
it 'should not allow overriding the environment in the separate configuration file' do
|
167
|
+
main = { 'staging' => { 'foo' => 'bar', 'environment' => 'production'}}
|
168
|
+
env = { 'staging' => { 'baz' => 'xyzzy', 'environment' => 'production'}}
|
169
|
+
WhiskeyDisk::Config.stub!(:main_configuration_data).and_return(YAML.dump(main))
|
170
|
+
WhiskeyDisk::Config.stub!(:environment_configuration_data).and_return(YAML.dump(env))
|
171
|
+
WhiskeyDisk::Config.fetch['environment'].should == 'staging'
|
172
|
+
end
|
173
|
+
|
174
|
+
it 'should include the project handle in the hash' do
|
175
|
+
main = { 'staging' => { 'foo' => 'bar' }}
|
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'
|
181
|
+
end
|
182
|
+
|
183
|
+
it 'should allow overriding the project handle in the main configuration file' do
|
184
|
+
main = { 'staging' => { 'foo' => 'bar', 'project' => 'diskey_whisk' }}
|
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'
|
190
|
+
end
|
191
|
+
|
192
|
+
it 'should allow overriding the project handle in the separate configuration file' do
|
193
|
+
main = { 'staging' => { 'foo' => 'bar', 'project' => 'diskey_whisk' }}
|
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'
|
199
|
+
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
|
+
end
|
209
|
+
|
210
|
+
it 'should fail if the current environment cannot be determined' do
|
211
|
+
ENV['to'] = nil
|
212
|
+
lambda { WhiskeyDisk::Config.filenames }.should.raise
|
213
|
+
end
|
214
|
+
|
215
|
+
it 'should include the location of the main configuration file' do
|
216
|
+
WhiskeyDisk::Config.filenames.should.include('/path/to/main')
|
217
|
+
end
|
218
|
+
|
219
|
+
it 'should include the location of a separate configuration file for this environment' do
|
220
|
+
WhiskeyDisk::Config.filenames.should.include('/path/to/staging')
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
describe 'computing the project name from a configuration hash' do
|
225
|
+
it 'should return the empty string if no repository is defined' do
|
226
|
+
WhiskeyDisk::Config.project_name({}).should == ''
|
227
|
+
end
|
228
|
+
|
229
|
+
it 'should return the empty string if the repository is blank' do
|
230
|
+
WhiskeyDisk::Config.project_name({ 'repository' => ''}).should == ''
|
231
|
+
end
|
232
|
+
|
233
|
+
it 'should return the last path segment if the repository does not end in .git' do
|
234
|
+
WhiskeyDisk::Config.project_name({ 'repository' => 'git@foo/bar/baz'}).should == 'baz'
|
235
|
+
end
|
236
|
+
|
237
|
+
it 'should return the last pasth segment, stripping .git, if the repository ends in .git' do
|
238
|
+
WhiskeyDisk::Config.project_name({ 'repository' => 'git@foo/bar/baz.git'}).should == 'baz'
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
describe 'finding the main configuration file' do
|
243
|
+
it 'should return the path to deploy.yml in the config directory under the project base path' do
|
244
|
+
WhiskeyDisk::Config.stub!(:base_path).and_return('/path/to/project')
|
245
|
+
WhiskeyDisk::Config.main_configuration_file.should == '/path/to/project/config/deploy.yml'
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
describe 'finding the per-environment configuration file' do
|
250
|
+
it 'should fail if the current environment cannot be determined' do
|
251
|
+
ENV['to'] = nil
|
252
|
+
lambda { WhiskeyDisk::Config.environment_configuration_file }.should.raise
|
253
|
+
end
|
254
|
+
|
255
|
+
it 'should return the path to deploy-<environment>.yml in the config directory under the project base path' do
|
256
|
+
ENV['to'] = @env = 'staging'
|
257
|
+
WhiskeyDisk::Config.stub!(:base_path).and_return('/path/to/project')
|
258
|
+
WhiskeyDisk::Config.environment_configuration_file.should == '/path/to/project/config/deploy-staging.yml'
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
262
|
+
describe 'computing the base path for the project' do
|
263
|
+
it 'should fail if there is no Rakefile along the root path to the current directory' do
|
264
|
+
WhiskeyDisk::Config.stub!(:contains_rakefile?).and_return(false)
|
265
|
+
lambda { WhiskeyDisk::Config.base_path }.should.raise
|
266
|
+
end
|
267
|
+
|
268
|
+
it 'return the nearest enclosing path with a Rakefile along the root path to the current directory' do
|
269
|
+
top = ::File.expand_path(File.join(CURRENT, '..', '..'))
|
270
|
+
WhiskeyDisk::Config.stub!(:contains_rakefile?).and_return(false)
|
271
|
+
WhiskeyDisk::Config.stub!(:contains_rakefile?).with(top).and_return(true)
|
272
|
+
Dir.chdir(CURRENT)
|
273
|
+
WhiskeyDisk::Config.base_path.should == top
|
274
|
+
end
|
275
|
+
end
|
276
|
+
end
|