kumade 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,23 +0,0 @@
1
- Feature: Namespaced deploy tasks
2
- In order to avoid task name conflicts
3
- As a user
4
- I want to have namespaced deploy tasks
5
-
6
- Background:
7
- Given a directory named "deployer"
8
- And I cd to "deployer"
9
- And I stub out the "staging" deploy method
10
- And I stub out the "production" deploy method
11
- And I load the namespaced tasks
12
-
13
- Scenario: kumade:deploy task is an alias for kumade:deploy:staging
14
- When I successfully run the rake task "kumade:deploy"
15
- Then the output should contain "Force pushed master -> staging"
16
-
17
- Scenario: Deploying to staging
18
- When I successfully run the rake task "kumade:deploy:staging"
19
- Then the output should contain "Force pushed master -> staging"
20
-
21
- Scenario: Deploying to production
22
- When I successfully run the rake task "kumade:deploy:production"
23
- Then the output should contain "Force pushed master -> production"
@@ -1,10 +0,0 @@
1
- Given /^I stub out the "([^"]+)" deploy method$/ do |environment|
2
- append_to_file("Rakefile", <<-RAKE)
3
-
4
- class Kumade::Deployer
5
- def deploy_to_#{environment}
6
- puts "Force pushed master -> #{environment}"
7
- end
8
- end
9
- RAKE
10
- end
@@ -1,27 +0,0 @@
1
- Given /^I load the non\-namespaced tasks$/ do
2
- prepend_require_kumade_to_rakefile!
3
-
4
- steps %{
5
- When I append to "Rakefile" with:
6
- """
7
-
8
- Kumade.load_tasks
9
- """
10
- }
11
- end
12
-
13
- Given /^I load the namespaced tasks$/ do
14
- prepend_require_kumade_to_rakefile!
15
-
16
- steps %{
17
- When I append to "Rakefile" with:
18
- """
19
-
20
- Kumade.load_namespaced_tasks
21
- """
22
- }
23
- end
24
-
25
- When /^I successfully run the rake task "([^"]*)"$/ do |task_name|
26
- When %{I successfully run `bundle exec rake #{task_name}`}
27
- end
@@ -1,15 +0,0 @@
1
- module InsertIntoRakefileHelpers
2
- def insert_after_tasks_are_loaded(new_content)
3
- rakefile_path = File.join(current_dir, 'Rakefile')
4
- current_rakefile_content = File.readlines(rakefile_path)
5
- load_tasks_index = current_rakefile_content.index("Kumade.load_tasks")
6
-
7
- new_rakefile_content = current_rakefile_content[0..load_tasks_index].join +
8
- "\n" + new_content +
9
- current_rakefile_content[load_tasks_index..-1].join
10
- When %{I write to "Rakefile" with:}, new_rakefile_content
11
- When %{I commit everything in the current directory to git}
12
- end
13
- end
14
-
15
- World(InsertIntoRakefileHelpers)
@@ -1,18 +0,0 @@
1
- require 'fileutils'
2
-
3
- module RequireKumade
4
- def prepend_require_kumade_to_rakefile!
5
- rakefile_path = File.join(current_dir, 'Rakefile')
6
- if File.exist?(rakefile_path)
7
- unless `head -n1 #{rakefile_path}`.include?("require 'kumade'")
8
- current_rakefile_content = File.read(rakefile_path)
9
- new_rakefile_content = "require 'kumade'\n" + current_rakefile_content
10
- When %{I write to "Rakefile" with:}, new_rakefile_content
11
- end
12
- else
13
- Given %{an empty file named "Rakefile"}
14
- end
15
- end
16
- end
17
-
18
- World(RequireKumade)
@@ -1,12 +0,0 @@
1
- class Kumade
2
- desc "Alias for kumade:deploy"
3
- task :deploy => "kumade:deploy"
4
-
5
- namespace :deploy do
6
- desc "Alias for kumade:deploy:staging"
7
- task :staging => "kumade:deploy:staging"
8
-
9
- desc "Alias for kumade:deploy:production"
10
- task :production => "kumade:deploy:production"
11
- end
12
- end
@@ -1,18 +0,0 @@
1
- class Kumade
2
- namespace :kumade do
3
- desc "Alias for kumade:deploy:staging"
4
- task :deploy => "deploy:staging"
5
-
6
- namespace :deploy do
7
- desc "Deploy to Heroku staging"
8
- task :staging do
9
- deployer.deploy_to_staging
10
- end
11
-
12
- desc "Deploy to Heroku production"
13
- task :production do
14
- deployer.deploy_to_production
15
- end
16
- end
17
- end
18
- end
@@ -1,564 +0,0 @@
1
- require 'spec_helper'
2
- require 'jammit'
3
-
4
- class Kumade
5
- describe Deployer, "#load_tasks" do
6
- it "loads the deploy tasks" do
7
- Rake.application.tasks.should be_empty
8
- subject.load_tasks
9
- task_names = Rake.application.tasks.map{|task| task.name }
10
- %w(deploy deploy:production deploy:staging).each do |expected_name|
11
- task_names.should include expected_name
12
- end
13
- end
14
- end
15
-
16
- describe Deployer, "#pre_deploy" do
17
- it "calls the correct methods in order" do
18
- %w(
19
- ensure_clean_git
20
- ensure_rake_passes
21
- package_assets
22
- git_push
23
- ).each do |task|
24
- subject.should_receive(task).ordered.and_return(true)
25
- end
26
-
27
- subject.pre_deploy
28
- end
29
- end
30
-
31
- describe Deployer, "#deploy_to_staging" do
32
- it "calls the correct methods in order" do
33
- subject.stub(:run => true)
34
-
35
- subject.should_receive(:ensure_staging_app_is_present).
36
- ordered
37
-
38
- subject.should_receive(:pre_deploy).
39
- ordered.
40
- and_return(true)
41
-
42
- subject.should_receive(:git_force_push).
43
- ordered.
44
- and_return(true)
45
-
46
- subject.should_receive(:heroku_migrate).
47
- ordered.
48
- with(:staging)
49
-
50
- subject.deploy_to_staging
51
- end
52
-
53
- it "deploys to Kumade.staging" do
54
- subject.stub(:pre_deploy => true,
55
- :run => true)
56
- subject.stub(:ensure_staging_app_is_present)
57
- Kumade.staging_remote = 'orange'
58
-
59
- subject.should_receive(:git_force_push).with('orange')
60
-
61
- subject.deploy_to_staging
62
- end
63
- end
64
-
65
- describe Deployer, "#deploy_to_production" do
66
- it "calls the correct methods in order" do
67
- subject.stub(:run => true)
68
-
69
- subject.should_receive(:ensure_production_app_is_present).
70
- ordered
71
-
72
- subject.should_receive(:pre_deploy).
73
- ordered.
74
- and_return(true)
75
-
76
- subject.should_receive(:git_force_push).
77
- ordered.
78
- and_return(true)
79
-
80
- subject.should_receive(:heroku_migrate).
81
- ordered.
82
- with(:production)
83
-
84
- subject.deploy_to_production
85
- end
86
-
87
- it "deploys to Kumade.production" do
88
- subject.stub(:pre_deploy => true,
89
- :run => true)
90
- subject.stub(:ensure_production_app_is_present)
91
-
92
- Kumade.production_remote = 'bamboo'
93
-
94
- subject.should_receive(:git_force_push).with('bamboo')
95
-
96
- subject.deploy_to_production
97
- end
98
- end
99
-
100
- describe Deployer, "#git_push" do
101
- let(:remote){ 'origin' }
102
-
103
- before { subject.stub(:announce) }
104
-
105
- it "calls `git push`" do
106
- subject.should_receive(:run).
107
- with("git push #{remote} master").
108
- and_return(true)
109
- subject.git_push(remote)
110
- end
111
-
112
- context "when `git push` fails" do
113
- before do
114
- subject.stub(:run => false)
115
- end
116
-
117
- it "raises an error" do
118
- lambda do
119
- subject.git_push(remote)
120
- end.should raise_error("Failed to push master -> #{remote}")
121
- end
122
- end
123
-
124
- context "when `git push` succeeds" do
125
- before do
126
- subject.stub(:run => true)
127
- end
128
-
129
- it "does not raise an error" do
130
- subject.stub(:announce => false)
131
- lambda do
132
- subject.git_push(remote)
133
- end.should_not raise_error
134
- end
135
-
136
- it "prints the correct message" do
137
- subject.should_receive(:announce).
138
- with("Pushed master -> #{remote}")
139
-
140
- subject.git_push(remote)
141
- end
142
- end
143
- end
144
-
145
- describe Deployer, "#git_force_push" do
146
- let(:remote){ 'origin' }
147
- before { subject.stub(:announce) }
148
-
149
- it "calls `git push -f`" do
150
- subject.should_receive(:run).
151
- with("git push -f #{remote} master").
152
- and_return(true)
153
- subject.git_force_push(remote)
154
- end
155
-
156
- context "when `git push -f` fails" do
157
- before do
158
- subject.stub(:run => false)
159
- end
160
-
161
- it "raises an error" do
162
- lambda do
163
- subject.git_force_push(remote)
164
- end.should raise_error("Failed to force push master -> #{remote}")
165
- end
166
- end
167
-
168
- context "when `git push -f` succeeds" do
169
- before do
170
- subject.stub(:run => true)
171
- end
172
-
173
- it "does not raise an error" do
174
- lambda do
175
- subject.git_force_push(remote)
176
- end.should_not raise_error
177
- end
178
-
179
- it "prints the correct message" do
180
- subject.should_receive(:announce).
181
- with("Force pushed master -> #{remote}")
182
-
183
- subject.git_force_push(remote)
184
- end
185
- end
186
- end
187
-
188
- describe Deployer, "#ensure_clean_git" do
189
- context "when git is dirty" do
190
- before { subject.stub(:git_dirty? => true) }
191
-
192
- it "raises an error" do
193
- lambda do
194
- subject.ensure_clean_git
195
- end.should raise_error("Cannot deploy: repo is not clean.")
196
- end
197
- end
198
-
199
- context "when git is clean" do
200
- before { subject.stub(:git_dirty? => false) }
201
-
202
- it "does not raise an error" do
203
- lambda do
204
- subject.ensure_clean_git
205
- end.should_not raise_error
206
- end
207
- end
208
- end
209
-
210
- describe Deployer, "#ensure_rake_passes" do
211
- context "with a default task" do
212
- before do
213
- subject.stub(:default_task_exists? => true)
214
- end
215
-
216
- it "does not raise an error if the default task succeeds" do
217
- subject.stub(:rake_succeeded? => true)
218
- lambda do
219
- subject.ensure_rake_passes
220
- end.should_not raise_error
221
- end
222
-
223
- it "raises an error if the default task failse" do
224
- subject.stub(:rake_succeeded? => false)
225
- lambda do
226
- subject.ensure_rake_passes
227
- end.should raise_error("Cannot deploy: tests did not pass")
228
- end
229
- end
230
- end
231
-
232
- describe Deployer, "#default_task_exists?" do
233
- before { Rake::Task.clear }
234
-
235
- it "returns true if a default task does exist" do
236
- Rake::Task.define_task(:default){}
237
-
238
- subject.default_task_exists?.should be_true
239
- end
240
-
241
- it "returns false if a default task does not exist" do
242
- subject.default_task_exists?.should be_false
243
- end
244
- end
245
-
246
- describe Deployer, "#rake_succeeded?" do
247
- before { Rake::Task.clear }
248
-
249
- it "returns true if the default task passed" do
250
- Rake::Task.define_task(:default){}
251
-
252
- subject.rake_succeeded?.should be_true
253
- end
254
-
255
- it "returns false if the default task failed" do
256
- Rake::Task.define_task(:default){ fail "blerg" }
257
- subject.rake_succeeded?.should be_false
258
- end
259
- end
260
-
261
- describe Deployer, "#package_assets" do
262
- context "with Jammit installed" do
263
- it "calls package_with_jammit" do
264
- subject.should_receive(:package_with_jammit)
265
- subject.package_assets
266
- end
267
- end
268
-
269
- context "with Jammit not installed" do
270
- before { subject.stub(:jammit_installed? => false) }
271
- it "does not call package_with_jammit" do
272
- subject.should_receive(:package_with_jammit).exactly(0).times
273
- subject.package_assets
274
- end
275
- end
276
-
277
- context "with More installed" do
278
- before do
279
- subject.stub(:jammit_installed? => false)
280
- subject.stub(:more_installed? => true)
281
- end
282
-
283
- it "calls package_with_more" do
284
- subject.should_receive(:package_with_more)
285
- subject.package_assets
286
- end
287
- end
288
-
289
- context "with More not installed" do
290
- before do
291
- subject.stub(:jammit_installed? => false)
292
- subject.stub(:more_installed? => false)
293
- end
294
-
295
- it "does not call package_with_more" do
296
- subject.should_receive(:package_with_more).exactly(0).times
297
- subject.package_assets
298
- end
299
- end
300
- end
301
-
302
- describe Deployer, "#package_with_jammit" do
303
- before do
304
- subject.stub(:git_add_and_commit_all_assets_in)
305
- subject.stub(:announce)
306
- Jammit.stub(:package!)
307
- end
308
-
309
- it "calls Jammit.package!" do
310
- Jammit.should_receive(:package!).once
311
- subject.package_with_jammit
312
- end
313
-
314
- it "prints the correct message if packaging succeeded" do
315
- subject.should_receive(:announce).with("Successfully packaged with Jammit")
316
-
317
- subject.package_with_jammit
318
- end
319
-
320
- it "raises an error if packaging failed" do
321
- Jammit.stub(:package!) do
322
- raise Jammit::MissingConfiguration.new("random Jammit error")
323
- end
324
-
325
- lambda do
326
- subject.package_with_jammit
327
- end.should raise_error(Jammit::MissingConfiguration)
328
- end
329
-
330
- it "calls git_add_and_commit_all_assets_in if assets were added" do
331
- subject.stub(:git_dirty? => true,
332
- :absolute_assets_path => 'blerg')
333
- subject.should_receive(:git_add_and_commit_all_assets_in).
334
- with('blerg').
335
- and_return(true)
336
-
337
- subject.package_with_jammit
338
- end
339
-
340
- it "does not call git_add_and_commit_all_jammit_assets if no assets were added" do
341
- subject.stub(:git_dirty? => false)
342
- subject.should_receive(:git_add_and_commit_all_assets_in).exactly(0).times
343
-
344
- subject.package_with_jammit
345
- end
346
- end
347
-
348
- describe Deployer, "#package_with_more" do
349
- before do
350
- subject.stub(:git_add_and_commit_all_assets_in => true,
351
- :more_assets_path => 'assets',
352
- :announce => nil)
353
- Rake::Task.clear
354
- Rake::Task.define_task('more:generate'){}
355
- end
356
-
357
- it "calls the more:generate task" do
358
- Rake::Task.clear
359
- more_generate_task = Rake::Task.define_task('more:generate'){}
360
- more_generate_task.should_receive(:invoke).once
361
- subject.package_with_more
362
- end
363
-
364
- it "prints the correct message if packaging succeeded" do
365
- subject.stub(:git_dirty? => true)
366
- subject.should_receive(:announce).with("Successfully packaged with More")
367
-
368
- subject.package_with_more
369
- end
370
-
371
- it "prints no message if packaging was a no-op" do
372
- subject.stub(:git_dirty? => false)
373
- subject.should_receive(:announce).exactly(0).times
374
-
375
- subject.package_with_more
376
- end
377
-
378
- it "raises an error if packaging failed" do
379
- Rake::Task.clear
380
- Rake::Task.define_task('more:generate') do
381
- fail "blerg"
382
- end
383
-
384
- lambda do
385
- subject.package_with_more
386
- end.should raise_error("blerg")
387
- end
388
-
389
- it "calls git_add_and_commit_all_assets_in if assets were added" do
390
- subject.stub(:git_dirty? => true,
391
- :more_assets_path => 'blerg')
392
- subject.should_receive(:git_add_and_commit_all_assets_in).
393
- with('blerg').
394
- and_return(true)
395
-
396
- subject.package_with_more
397
- end
398
-
399
- it "does not call git_add_and_commit_all_more_assets if no assets were added" do
400
- subject.stub(:git_dirty? => false)
401
- subject.should_receive(:git_add_and_commit_all_assets_in).exactly(0).times
402
-
403
- subject.package_with_more
404
- end
405
- end
406
-
407
- describe Deployer, "#git_add_and_commit_all_assets_in" do
408
- before do
409
- subject.stub(:run => true,
410
- :announce => nil)
411
- end
412
-
413
- it "announces the correct message" do
414
- subject.should_receive(:announce).with("Committing assets")
415
-
416
- subject.git_add_and_commit_all_assets_in('blerg')
417
- end
418
-
419
- it "runs the correct commands" do
420
- subject.should_receive(:run).
421
- with("git add blerg && git commit -m 'Assets'")
422
-
423
- subject.git_add_and_commit_all_assets_in('blerg')
424
- end
425
-
426
- it "raises an error if it could not add and commit assets" do
427
- subject.stub(:run => false)
428
-
429
- lambda do
430
- subject.git_add_and_commit_all_assets_in('blerg')
431
- end.should raise_error("Cannot deploy: couldn't commit assets")
432
- end
433
- end
434
-
435
- describe Deployer, "#absolute_assets_path" do
436
- it "returns the correct asset path" do
437
- Jammit.stub(:package_path => 'blerg')
438
- current_dir = File.expand_path(Dir.pwd)
439
- subject.absolute_assets_path.should == File.join(current_dir, 'public', 'blerg')
440
- end
441
- end
442
-
443
- describe Deployer, "#more_assets_path" do
444
- it "returns the correct asset path" do
445
- module ::Less
446
- class More
447
- def self.destination_path
448
- 'blerg'
449
- end
450
- end
451
- end
452
- subject.more_assets_path.should == 'public/blerg'
453
- end
454
- end
455
-
456
- describe Deployer, "#jammit_installed?" do
457
- it "returns true because it's loaded by the Gemfile" do
458
- subject.jammit_installed?.should be_true
459
- end
460
- end
461
-
462
- describe Deployer, "#more_installed?" do
463
- before do
464
- if defined?(Less)
465
- Object.send(:remove_const, :Less)
466
- end
467
- end
468
-
469
- it "returns false if it does not find Less::More" do
470
- subject.more_installed?.should be_false
471
- end
472
-
473
- it "returns true if it finds Less::More" do
474
- module Less
475
- class More
476
- end
477
- end
478
- subject.more_installed?.should be_true
479
- end
480
- end
481
-
482
- describe Deployer, "#heroku_migrate" do
483
- let(:staging_app) { 'staging-sushi' }
484
- let(:production_app){ 'production-sushi' }
485
-
486
- before do
487
- Kumade.reset!
488
- Kumade.staging_app = staging_app
489
- Kumade.production_app = production_app
490
- end
491
-
492
- it "runs db:migrate with the correct staging app" do
493
- subject.should_receive(:run).
494
- with("bundle exec heroku rake db:migrate --app #{staging_app}")
495
-
496
- subject.heroku_migrate(:staging)
497
- end
498
-
499
- it "runs db:migrate with the correct production app" do
500
- subject.should_receive(:run).
501
- with("bundle exec heroku rake db:migrate --app #{production_app}")
502
-
503
- subject.heroku_migrate(:production)
504
- end
505
- end
506
-
507
- describe Deployer, "#string_present?" do
508
- it "returns false for nil" do
509
- subject.string_present?(nil).should be_false
510
- end
511
-
512
- it "returns false for false" do
513
- subject.string_present?(false).should be_false
514
- end
515
-
516
- it "returns false for true" do
517
- subject.string_present?(true).should be_false
518
- end
519
-
520
- it "returns false for an empty string" do
521
- subject.string_present?('').should be_false
522
- end
523
-
524
- it "returns true for a non-empty string" do
525
- subject.string_present?('abc').should be_true
526
- end
527
- end
528
-
529
- describe Deployer, "#ensure_staging_app_is_present" do
530
- after { Kumade.reset! }
531
-
532
- it "does not raise an error if Kumade.staging_app is present" do
533
- Kumade.staging_app = 'abc'
534
- lambda do
535
- subject.ensure_staging_app_is_present
536
- end.should_not raise_error
537
- end
538
-
539
- it "raises an error if Kumade.staging_app is not present" do
540
- Kumade.staging_app = ''
541
- lambda do
542
- subject.ensure_staging_app_is_present
543
- end.should raise_error("Cannot deploy: Kumade.staging_app is not present")
544
- end
545
- end
546
-
547
- describe Deployer, "#ensure_production_app_is_present" do
548
- after { Kumade.reset! }
549
-
550
- it "does not raise an error if Kumade.production_app is present" do
551
- Kumade.production_app = 'abc'
552
- lambda do
553
- subject.ensure_production_app_is_present
554
- end.should_not raise_error
555
- end
556
-
557
- it "raises an error if Kumade.production_app is not present" do
558
- Kumade.production_app = ''
559
- lambda do
560
- subject.ensure_production_app_is_present
561
- end.should raise_error("Cannot deploy: Kumade.production_app is not present")
562
- end
563
- end
564
- end