kumade 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +0 -1
- data/README.md +19 -21
- data/bin/kumade +1 -1
- data/kumade.gemspec +2 -0
- data/lib/kumade.rb +16 -10
- data/lib/kumade/base.rb +14 -9
- data/lib/kumade/cli.rb +86 -0
- data/lib/kumade/configuration.rb +14 -0
- data/lib/kumade/deployer.rb +27 -128
- data/lib/kumade/git.rb +11 -12
- data/lib/kumade/heroku.rb +46 -0
- data/lib/kumade/packager.rb +94 -0
- data/lib/kumade/version.rb +1 -1
- data/lib/tasks/deploy.rake +1 -1
- data/spec/kumade/base_spec.rb +89 -8
- data/spec/kumade/cli_spec.rb +109 -0
- data/spec/kumade/configuration_spec.rb +36 -0
- data/spec/kumade/deployer_spec.rb +45 -415
- data/spec/kumade/git_spec.rb +88 -21
- data/spec/kumade/heroku_spec.rb +121 -0
- data/spec/kumade/packager_spec.rb +318 -0
- data/spec/kumade_spec.rb +18 -0
- data/spec/spec_helper.rb +19 -3
- data/spec/support/heroku.rb +33 -0
- metadata +63 -22
- data/lib/kumade/runner.rb +0 -70
- data/spec/kumade/runner_spec.rb +0 -66
@@ -1,31 +1,15 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
3
|
+
require 'jammit'
|
4
4
|
|
5
5
|
describe Kumade::Deployer, "#pre_deploy" do
|
6
|
-
|
6
|
+
let(:git) { subject.git }
|
7
7
|
|
8
|
-
it "calls the correct methods
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
sync_github
|
13
|
-
).each do |task|
|
14
|
-
subject.should_receive(task).ordered.and_return(true)
|
15
|
-
end
|
16
|
-
|
17
|
-
subject.pre_deploy
|
18
|
-
end
|
19
|
-
|
20
|
-
it "syncs to github" do
|
21
|
-
%w(
|
22
|
-
ensure_clean_git
|
23
|
-
package_assets
|
24
|
-
).each do |task|
|
25
|
-
subject.stub(task)
|
26
|
-
end
|
8
|
+
it "calls the correct methods" do
|
9
|
+
git.expects(:ensure_clean_git)
|
10
|
+
subject.expects(:package_assets)
|
11
|
+
git.expects(:push).with(subject.git.current_branch)
|
27
12
|
|
28
|
-
subject.should_receive(:sync_github)
|
29
13
|
subject.pre_deploy
|
30
14
|
end
|
31
15
|
end
|
@@ -34,453 +18,99 @@ describe Kumade::Deployer, "#deploy" do
|
|
34
18
|
let(:remote_name) { 'staging' }
|
35
19
|
|
36
20
|
before do
|
37
|
-
|
21
|
+
STDOUT.stubs(:puts)
|
38
22
|
force_add_heroku_remote(remote_name)
|
39
23
|
end
|
40
24
|
|
41
|
-
it "calls the correct methods
|
42
|
-
subject.
|
25
|
+
it "calls the correct methods" do
|
26
|
+
subject.expects(:pre_deploy)
|
27
|
+
subject.heroku.expects(:sync)
|
28
|
+
subject.heroku.expects(:migrate_database)
|
29
|
+
subject.expects(:post_deploy)
|
43
30
|
|
44
|
-
subject.
|
45
|
-
|
46
|
-
|
47
|
-
subject.should_receive(:pre_deploy).
|
48
|
-
ordered.
|
49
|
-
and_return(true)
|
50
|
-
|
51
|
-
subject.should_receive(:sync_heroku).
|
52
|
-
ordered.
|
53
|
-
and_return(true)
|
31
|
+
subject.deploy
|
32
|
+
end
|
54
33
|
|
55
|
-
|
56
|
-
|
34
|
+
it "calls post_deploy if deploy fails" do
|
35
|
+
subject.git.stubs(:heroku_remote?).raises(RuntimeError)
|
57
36
|
|
58
|
-
subject.
|
37
|
+
subject.expects(:post_deploy)
|
59
38
|
|
60
39
|
subject.deploy
|
61
40
|
end
|
62
41
|
end
|
63
42
|
|
64
43
|
describe Kumade::Deployer, "#sync_github" do
|
65
|
-
let(:
|
66
|
-
|
67
|
-
before { subject.stub(:git => git_mock) }
|
44
|
+
let(:new_branch) { 'new-branch' }
|
68
45
|
|
69
|
-
|
70
|
-
|
71
|
-
subject.sync_github
|
46
|
+
before do
|
47
|
+
`git checkout -b #{new_branch}`
|
72
48
|
end
|
73
|
-
end
|
74
|
-
|
75
|
-
describe Kumade::Deployer, "#sync_heroku" do
|
76
|
-
let(:environment) { 'my-env' }
|
77
|
-
let(:git_mock) { mock() }
|
78
49
|
|
79
|
-
|
50
|
+
it "pushes the current branch to github" do
|
51
|
+
subject.git.expects(:push).with(new_branch)
|
80
52
|
|
81
|
-
|
82
|
-
|
83
|
-
it "calls git.create and git.push" do
|
84
|
-
git_mock.should_receive(:create).with("deploy")
|
85
|
-
git_mock.should_receive(:push).with("deploy:master", environment, true)
|
86
|
-
subject.sync_heroku
|
53
|
+
subject.sync_github
|
87
54
|
end
|
88
55
|
end
|
89
56
|
|
90
57
|
describe Kumade::Deployer, "#ensure_clean_git" do
|
91
|
-
let(:git_mock) { mock() }
|
92
|
-
|
93
|
-
before { subject.stub(:git => git_mock) }
|
94
|
-
|
95
58
|
it "calls git.ensure_clean_git" do
|
96
|
-
|
59
|
+
subject.git.expects(:ensure_clean_git)
|
97
60
|
subject.ensure_clean_git
|
98
61
|
end
|
99
62
|
end
|
100
63
|
|
101
|
-
describe Kumade::Deployer, "#package_assets" do
|
102
|
-
context "with Jammit installed" do
|
103
|
-
it "calls package_with_jammit" do
|
104
|
-
subject.should_receive(:package_with_jammit)
|
105
|
-
subject.package_assets
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
context "with Jammit not installed" do
|
110
|
-
before { subject.stub(:jammit_installed? => false) }
|
111
|
-
it "does not call package_with_jammit" do
|
112
|
-
subject.should_not_receive(:package_with_jammit)
|
113
|
-
subject.package_assets
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
context "with More installed" do
|
118
|
-
before do
|
119
|
-
subject.stub(:jammit_installed? => false)
|
120
|
-
subject.stub(:more_installed? => true)
|
121
|
-
end
|
122
|
-
|
123
|
-
it "calls package_with_more" do
|
124
|
-
subject.should_receive(:package_with_more)
|
125
|
-
subject.package_assets
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
context "with More not installed" do
|
130
|
-
before do
|
131
|
-
subject.stub(:jammit_installed? => false)
|
132
|
-
subject.stub(:more_installed? => false)
|
133
|
-
end
|
134
|
-
|
135
|
-
it "does not call package_with_more" do
|
136
|
-
subject.should_not_receive(:package_with_more)
|
137
|
-
subject.package_assets
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
context "with custom rake task installed" do
|
142
|
-
before do
|
143
|
-
subject.stub(:jammit_installed? => false,
|
144
|
-
:more_installed? => false,
|
145
|
-
:invoke_custom_task => nil,
|
146
|
-
:custom_task? => true)
|
147
|
-
end
|
148
|
-
|
149
|
-
it "invokes custom task" do
|
150
|
-
subject.should_receive(:invoke_custom_task)
|
151
|
-
subject.package_assets
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
context "with custom rake task not installed" do
|
156
|
-
before do
|
157
|
-
subject.stub(:jammit_installed? => false,
|
158
|
-
:more_installed? => false,
|
159
|
-
:invoke_custom_task => nil,
|
160
|
-
:custom_task? => false)
|
161
|
-
end
|
162
|
-
|
163
|
-
it "does not invoke custom task" do
|
164
|
-
subject.should_not_receive(:invoke_custom_task)
|
165
|
-
subject.package_assets
|
166
|
-
end
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
describe Kumade::Deployer, "#package_with_jammit" do
|
171
|
-
before do
|
172
|
-
subject.stub(:git_add_and_commit_all_assets_in)
|
173
|
-
subject.stub(:say)
|
174
|
-
Jammit.stub(:package!)
|
175
|
-
end
|
176
|
-
|
177
|
-
it "calls Jammit.package!" do
|
178
|
-
Jammit.should_receive(:package!).once
|
179
|
-
subject.package_with_jammit
|
180
|
-
end
|
181
|
-
|
182
|
-
context "with updated assets" do
|
183
|
-
before { subject.stub(:git => mock(:dirty? => true)) }
|
184
|
-
|
185
|
-
it "prints the correct message" do
|
186
|
-
subject.should_receive(:success).with("Packaged assets with Jammit")
|
187
|
-
|
188
|
-
subject.package_with_jammit
|
189
|
-
end
|
190
|
-
|
191
|
-
it "calls git_add_and_commit_all_assets_in" do
|
192
|
-
subject.stub(:jammit_assets_path => 'jammit-assets')
|
193
|
-
subject.should_receive(:git_add_and_commit_all_assets_in).
|
194
|
-
with('jammit-assets').
|
195
|
-
and_return(true)
|
196
|
-
|
197
|
-
subject.package_with_jammit
|
198
|
-
end
|
199
|
-
end
|
200
|
-
|
201
|
-
it "prints an error if packaging failed" do
|
202
|
-
Jammit.stub(:package!) do
|
203
|
-
raise Jammit::MissingConfiguration.new("random Jammit error")
|
204
|
-
end
|
205
|
-
subject.should_receive(:error).with("Error: Jammit::MissingConfiguration: random Jammit error")
|
206
|
-
|
207
|
-
subject.package_with_jammit
|
208
|
-
end
|
209
|
-
end
|
210
|
-
|
211
|
-
describe Kumade::Deployer, "#invoke_custom_task" do
|
212
|
-
let(:task) { stub('task', :invoke => nil) }
|
213
|
-
|
214
|
-
before do
|
215
|
-
subject.stub(:say)
|
216
|
-
Rake::Task.stub(:[] => task)
|
217
|
-
end
|
218
|
-
|
219
|
-
it "calls deploy task" do
|
220
|
-
Rake::Task.should_receive(:[]).with("kumade:before_asset_compilation")
|
221
|
-
task.should_receive(:invoke)
|
222
|
-
subject.invoke_custom_task
|
223
|
-
end
|
224
|
-
end
|
225
|
-
|
226
|
-
describe Kumade::Deployer, "#package_with_more" do
|
227
|
-
before do
|
228
|
-
subject.stub(:git_add_and_commit_all_assets_in => true,
|
229
|
-
:more_assets_path => 'assets')
|
230
|
-
subject.stub(:say)
|
231
|
-
end
|
232
|
-
|
233
|
-
it "calls the more:generate task" do
|
234
|
-
subject.should_receive(:run).with("bundle exec rake more:generate")
|
235
|
-
subject.package_with_more
|
236
|
-
end
|
237
|
-
|
238
|
-
context "with changed assets" do
|
239
|
-
it "prints a success message" do
|
240
|
-
subject.stub(:run).with("bundle exec rake more:generate")
|
241
|
-
subject.stub(:git => mock(:dirty? => true))
|
242
|
-
subject.should_receive(:success).with("Packaged assets with More")
|
243
|
-
|
244
|
-
subject.package_with_more
|
245
|
-
end
|
246
|
-
|
247
|
-
it "calls git_add_and_commit_all_assets_in if assets were added" do
|
248
|
-
subject.stub(:git => mock(:dirty? => true),
|
249
|
-
:more_assets_path => 'blerg')
|
250
|
-
subject.stub(:run).with("bundle exec rake more:generate")
|
251
|
-
subject.should_receive(:git_add_and_commit_all_assets_in).
|
252
|
-
with('blerg').
|
253
|
-
and_return(true)
|
254
|
-
|
255
|
-
subject.package_with_more
|
256
|
-
end
|
257
|
-
end
|
258
|
-
|
259
|
-
context "with no changed assets" do
|
260
|
-
it "prints no message" do
|
261
|
-
subject.stub(:run).with("bundle exec rake more:generate")
|
262
|
-
subject.stub(:git => mock(:dirty? => false))
|
263
|
-
subject.should_not_receive(:say)
|
264
|
-
|
265
|
-
subject.package_with_more
|
266
|
-
end
|
267
|
-
|
268
|
-
it "does not call git_add_and_commit_all_more_assets" do
|
269
|
-
subject.stub(:run).with("bundle exec rake more:generate")
|
270
|
-
subject.stub(:git => mock(:dirty? => false))
|
271
|
-
subject.should_not_receive(:git_add_and_commit_all_assets_in)
|
272
|
-
|
273
|
-
subject.package_with_more
|
274
|
-
end
|
275
|
-
end
|
276
|
-
|
277
|
-
it "prints an error if packaging failed" do
|
278
|
-
subject.stub(:run) do |arg|
|
279
|
-
if arg == "bundle exec rake more:generate"
|
280
|
-
raise "blerg"
|
281
|
-
end
|
282
|
-
end
|
283
|
-
|
284
|
-
subject.should_receive(:error).with("Error: RuntimeError: blerg")
|
285
|
-
|
286
|
-
subject.package_with_more
|
287
|
-
end
|
288
|
-
end
|
289
|
-
|
290
|
-
describe Kumade::Deployer, "#git_add_and_commit_all_assets_in" do
|
291
|
-
let(:git_mock) { mock() }
|
292
|
-
|
293
|
-
before { subject.stub(:git => git_mock) }
|
294
|
-
|
295
|
-
it "calls git.add_and_commit_all_in" do
|
296
|
-
git_mock.should_receive(:add_and_commit_all_in).with("dir", 'deploy', 'Compiled assets', "Added and committed all assets", "couldn't commit assets")
|
297
|
-
subject.git_add_and_commit_all_assets_in("dir")
|
298
|
-
end
|
299
|
-
end
|
300
|
-
|
301
|
-
describe Kumade::Deployer, "#jammit_assets_path" do
|
302
|
-
it "returns the correct asset path" do
|
303
|
-
Jammit.stub(:package_path => 'blerg')
|
304
|
-
current_dir = File.expand_path(Dir.pwd)
|
305
|
-
subject.jammit_assets_path.should == File.join(current_dir, 'public', 'blerg')
|
306
|
-
end
|
307
|
-
end
|
308
|
-
|
309
|
-
describe Kumade::Deployer, "#more_assets_path" do
|
310
|
-
it "returns the correct asset path" do
|
311
|
-
module ::Less
|
312
|
-
class More
|
313
|
-
def self.destination_path
|
314
|
-
'blerg'
|
315
|
-
end
|
316
|
-
end
|
317
|
-
end
|
318
|
-
subject.more_assets_path.should == 'public/blerg'
|
319
|
-
end
|
320
|
-
end
|
321
|
-
|
322
|
-
describe Kumade::Deployer, "#jammit_installed?" do
|
323
|
-
it "returns true because it's loaded by the Gemfile" do
|
324
|
-
Kumade::Deployer.new.jammit_installed?.should be_true
|
325
|
-
end
|
326
|
-
|
327
|
-
it "returns false if jammit is not installed" do
|
328
|
-
Kumade::Deployer.new.jammit_installed?.should be_true
|
329
|
-
end
|
330
|
-
end
|
331
|
-
|
332
|
-
describe Kumade::Deployer, "#more_installed?" do
|
333
|
-
before do
|
334
|
-
if defined?(Less)
|
335
|
-
Object.send(:remove_const, :Less)
|
336
|
-
end
|
337
|
-
end
|
338
|
-
|
339
|
-
it "returns false if it does not find Less::More" do
|
340
|
-
Kumade::Deployer.new.more_installed?.should be_false
|
341
|
-
end
|
342
|
-
|
343
|
-
it "returns true if it finds Less::More" do
|
344
|
-
module Less
|
345
|
-
class More
|
346
|
-
end
|
347
|
-
end
|
348
|
-
Kumade::Deployer.new.more_installed?.should be_true
|
349
|
-
end
|
350
|
-
end
|
351
|
-
|
352
|
-
describe Kumade::Deployer, "#custom_task?" do
|
353
|
-
before do
|
354
|
-
Rake::Task.clear
|
355
|
-
end
|
356
|
-
|
357
|
-
it "returns true if it task found" do
|
358
|
-
namespace :kumade do
|
359
|
-
task :before_asset_compilation do
|
360
|
-
|
361
|
-
end
|
362
|
-
end
|
363
|
-
Kumade::Deployer.new.custom_task?.should be_true
|
364
|
-
end
|
365
|
-
|
366
|
-
it "returns false if task not found" do
|
367
|
-
Kumade::Deployer.new.custom_task?.should be_false
|
368
|
-
end
|
369
|
-
end
|
370
|
-
|
371
|
-
describe Kumade::Deployer, "#heroku_migrate" do
|
372
|
-
let(:environment) { 'staging' }
|
373
|
-
|
374
|
-
before do
|
375
|
-
subject.stub(:say)
|
376
|
-
force_add_heroku_remote(environment)
|
377
|
-
end
|
378
|
-
|
379
|
-
it "runs db:migrate with the correct app" do
|
380
|
-
subject.stub(:run => true)
|
381
|
-
subject.should_receive(:heroku).
|
382
|
-
with("rake db:migrate")
|
383
|
-
subject.should_receive(:success).with("Migrated staging")
|
384
|
-
|
385
|
-
subject.heroku_migrate
|
386
|
-
end
|
387
|
-
end
|
388
|
-
|
389
64
|
describe Kumade::Deployer, "#ensure_heroku_remote_exists" do
|
390
|
-
let(:environment)
|
391
|
-
let(:bad_environment) { 'bad' }
|
65
|
+
let(:environment) { 'staging' }
|
392
66
|
|
393
67
|
before do
|
394
|
-
subject.stub(:say)
|
395
68
|
force_add_heroku_remote(environment)
|
396
|
-
|
69
|
+
Kumade.configuration.environment = environment
|
397
70
|
end
|
398
71
|
|
399
72
|
context "when the remote points to Heroku" do
|
400
|
-
|
73
|
+
before { STDOUT.stubs(:puts) }
|
401
74
|
|
402
75
|
it "does not print an error" do
|
403
|
-
subject.should_not_receive(:error)
|
404
|
-
|
405
76
|
subject.ensure_heroku_remote_exists
|
77
|
+
|
78
|
+
STDOUT.should_not have_received(:puts).with(regexp_matches(/==> !/))
|
406
79
|
end
|
407
80
|
|
408
81
|
it "prints a success message" do
|
409
|
-
subject.should_receive(:success).with("#{environment} is a Heroku remote")
|
410
|
-
|
411
82
|
subject.ensure_heroku_remote_exists
|
83
|
+
|
84
|
+
STDOUT.should have_received(:puts).with(regexp_matches(/#{environment} is a Heroku remote/))
|
412
85
|
end
|
413
86
|
end
|
414
87
|
|
415
|
-
|
416
88
|
context "when the remote does not exist" do
|
417
|
-
|
418
|
-
|
89
|
+
before do
|
90
|
+
remove_remote(environment)
|
91
|
+
STDOUT.stubs(:puts)
|
92
|
+
end
|
419
93
|
|
420
94
|
it "prints an error" do
|
421
|
-
subject.
|
95
|
+
lambda { subject.ensure_heroku_remote_exists }.should raise_error(Kumade::DeploymentError)
|
422
96
|
|
423
|
-
|
97
|
+
STDOUT.should have_received(:puts).with(regexp_matches(/Cannot deploy: "#{environment}" remote does not exist/))
|
424
98
|
end
|
425
99
|
end
|
426
100
|
|
427
101
|
context "when the remote does not point to Heroku" do
|
428
|
-
|
429
|
-
|
430
|
-
it "prints an error" do
|
431
|
-
subject.should_receive(:error).with(%{Cannot deploy: "#{bad_environment}" remote does not point to Heroku})
|
102
|
+
let(:bad_environment) { 'bad' }
|
432
103
|
|
433
|
-
|
104
|
+
before do
|
105
|
+
`git remote add #{bad_environment} blerg@example.com`
|
106
|
+
STDOUT.stubs(:puts)
|
107
|
+
Kumade.configuration.environment = bad_environment
|
434
108
|
end
|
435
|
-
end
|
436
|
-
end
|
437
|
-
|
438
|
-
describe Kumade::Deployer, "#cedar?" do
|
439
|
-
context "when on Cedar" do
|
440
|
-
subject { Kumade::Deployer.new('staging', false) }
|
441
|
-
before { subject.stub(:heroku).and_return(" bamboo\n* cedar\n") }
|
442
|
-
its(:cedar?) { should be_true }
|
443
|
-
end
|
444
|
-
|
445
|
-
context "when not on Cedar" do
|
446
|
-
subject { Kumade::Deployer.new('staging', false) }
|
447
|
-
before { subject.stub(:heroku).and_return("* bamboo\n cedar\n") }
|
448
|
-
its(:cedar?) { should be_false }
|
449
|
-
end
|
450
|
-
end
|
451
109
|
|
452
|
-
|
453
|
-
|
454
|
-
subject { Kumade::Deployer.new('staging', false) }
|
455
|
-
before { subject.stub(:cedar?).and_return(true) }
|
456
|
-
it "runs commands with `run`" do
|
457
|
-
subject.should_receive(:run_or_error).with("bundle exec heroku run rake --remote staging", //)
|
458
|
-
subject.heroku("rake")
|
459
|
-
end
|
460
|
-
end
|
110
|
+
it "prints an error" do
|
111
|
+
lambda { subject.ensure_heroku_remote_exists }.should raise_error(Kumade::DeploymentError)
|
461
112
|
|
462
|
-
|
463
|
-
subject { Kumade::Deployer.new('staging', false) }
|
464
|
-
before { subject.stub(:cedar?).and_return(false) }
|
465
|
-
it "runs commands without `run`" do
|
466
|
-
subject.should_receive(:run_or_error).with("bundle exec heroku rake --remote staging", //)
|
467
|
-
subject.heroku("rake")
|
113
|
+
STDOUT.should have_received(:puts).with(regexp_matches(/Cannot deploy: "#{bad_environment}" remote does not point to Heroku/))
|
468
114
|
end
|
469
115
|
end
|
470
116
|
end
|
471
|
-
|
472
|
-
describe Kumade::Deployer, "#post_deploy" do
|
473
|
-
let(:git_mock) { mock() }
|
474
|
-
|
475
|
-
before { subject.stub(:git => git_mock) }
|
476
|
-
|
477
|
-
it "calls git.delete" do
|
478
|
-
git_mock.should_receive(:delete).with('deploy', 'master')
|
479
|
-
subject.post_deploy
|
480
|
-
end
|
481
|
-
|
482
|
-
it "prints its message and raises its message" do
|
483
|
-
subject.should_receive(:say).with("==> ! I'm an error!", :red)
|
484
|
-
lambda { subject.error("I'm an error!") }.should raise_error(Kumade::DeploymentError)
|
485
|
-
end
|
486
|
-
end
|