kumade 0.0.9 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,8 +7,13 @@ Feature: Kumade executable
7
7
  Background:
8
8
  Given a directory named "executable"
9
9
  And I cd to "executable"
10
- When I create a Heroku remote for "pretend-staging-app" named "pretend-staging"
10
+ When I successfully run `git init`
11
+ And I successfully run `touch .gitkeep`
12
+ And I successfully run `git add .`
13
+ And I successfully run `git commit -am First`
14
+ And I create a Heroku remote for "pretend-staging-app" named "pretend-staging"
11
15
  And I create a Heroku remote for "app-two" named "staging"
16
+ And I create a non-Heroku remote named "bad-remote"
12
17
 
13
18
  Scenario: Pretend mode with a Heroku remote
14
19
  When I run `kumade deploy pretend-staging -p`
@@ -21,7 +26,6 @@ Feature: Kumade executable
21
26
  ==> Pushed master -> origin
22
27
  run git push -f pretend-staging deploy:master
23
28
  ==> Force pushed master -> pretend-staging
24
- run bundle exec heroku rake db:migrate --app pretend-staging-app
25
29
  ==> Migrated pretend-staging-app
26
30
  run git checkout master && git branch -D deploy
27
31
  ==> Deployed to: pretend-staging
@@ -38,5 +42,5 @@ Feature: Kumade executable
38
42
  Then the output should match /Cannot deploy: /
39
43
 
40
44
  Scenario: Deploying to a non-Heroku remote fails
41
- When I run `kumade deploy origin`
42
- Then the output should match /==> ! Cannot deploy: "origin" remote does not point to Heroku/
45
+ When I run `kumade deploy bad-remote`
46
+ Then the output should match /==> ! Cannot deploy: "bad-remote" remote does not point to Heroku/
@@ -1,6 +1,9 @@
1
1
  When /^I create a Heroku remote for "([^"]*)" named "([^"]*)"$/ do |app_name, remote_name|
2
- `git remote add #{remote_name} git@heroku.com:#{app_name}.git`
2
+ When %{I run `git remote add #{remote_name} git@heroku.com:#{app_name}.git`}
3
+ end
3
4
 
5
+ When /^I create a non-Heroku remote named "([^"]*)"$/ do |remote_name|
6
+ When %{I run `git remote add #{remote_name} git@github.com:gabebw/kumade.git`}
4
7
  end
5
8
 
6
9
  After("@creates-remote") do
@@ -2,5 +2,5 @@ require 'aruba/cucumber'
2
2
  require 'kumade'
3
3
 
4
4
  Before('@extra-timeout') do
5
- @aruba_timeout_seconds = 60
5
+ @aruba_timeout_seconds = 10
6
6
  end
@@ -1,19 +1,19 @@
1
1
  module Kumade
2
2
  class Deployer < Thor::Shell::Color
3
3
  DEPLOY_BRANCH = "deploy"
4
- attr_reader :pretending
4
+ attr_reader :environment, :pretending
5
5
 
6
- def initialize(pretending = false)
6
+ def initialize(environment = 'staging', pretending = false)
7
7
  super()
8
- @pretending = pretending
8
+ @environment = environment
9
+ @pretending = pretending
9
10
  end
10
11
 
11
- def deploy_to(environment)
12
- string_environment = environment.to_s
13
- ensure_heroku_remote_exists_for(string_environment)
12
+ def deploy
13
+ ensure_heroku_remote_exists
14
14
  pre_deploy
15
- sync_heroku(string_environment)
16
- heroku_migrate(string_environment)
15
+ sync_heroku
16
+ heroku_migrate
17
17
  post_deploy
18
18
  end
19
19
 
@@ -29,21 +29,21 @@ module Kumade
29
29
  success("Pushed master -> origin")
30
30
  end
31
31
 
32
- def sync_heroku(environment)
32
+ def sync_heroku
33
33
  run_or_error("git push -f #{environment} #{DEPLOY_BRANCH}:master",
34
34
  "Failed to force push #{DEPLOY_BRANCH} -> #{environment}/master")
35
35
  success("Force pushed master -> #{environment}")
36
36
  end
37
37
 
38
- def heroku_migrate(environment)
38
+ def heroku_migrate
39
39
  app = Kumade.app_for(environment)
40
40
 
41
- heroku("rake db:migrate", app)
41
+ heroku("rake db:migrate", app) unless pretending
42
42
  success("Migrated #{app}")
43
43
  end
44
44
 
45
45
  def post_deploy
46
- run_or_error("git checkout master", "git branch -D #{DEPLOY_BRANCH}",
46
+ run_or_error(["git checkout master", "git branch -D #{DEPLOY_BRANCH}"],
47
47
  "Failed to clean up #{DEPLOY_BRANCH} branch")
48
48
  end
49
49
 
@@ -58,7 +58,7 @@ module Kumade
58
58
  end
59
59
 
60
60
  def on_cedar?(app)
61
- selected_stack = `heroku stack --app '#{app}'`.split("\n").grep(/^\*/).first
61
+ selected_stack = run("heroku stack --app '#{app}'", :capture => true).split("\n").grep(/^\*/).first
62
62
  selected_stack && selected_stack.include?('cedar')
63
63
  end
64
64
 
@@ -110,7 +110,7 @@ module Kumade
110
110
  end
111
111
 
112
112
  def git_add_and_commit_all_assets_in(dir)
113
- run_or_error "git checkout -b #{DEPLOY_BRANCH}", "git add -f #{dir}", "git commit -m 'Compiled assets'",
113
+ run_or_error ["git checkout -b #{DEPLOY_BRANCH}", "git add -f #{dir}", "git commit -m 'Compiled assets'"],
114
114
  "Cannot deploy: couldn't commit assets"
115
115
 
116
116
  success "Added and committed all assets"
@@ -165,8 +165,8 @@ module Kumade
165
165
  !$?.success?
166
166
  end
167
167
 
168
- def run_or_error(*commands, error_message)
169
- all_commands = commands.join(' && ')
168
+ def run_or_error(commands, error_message)
169
+ all_commands = [commands].flatten.join(' && ')
170
170
  if pretending
171
171
  say_status(:run, all_commands)
172
172
  else
@@ -174,9 +174,9 @@ module Kumade
174
174
  end
175
175
  end
176
176
 
177
- def run(command)
177
+ def run(command, config = {})
178
178
  say_status :run, command
179
- system command
179
+ config[:capture] ? `#{command}` : system("#{command}")
180
180
  end
181
181
 
182
182
  def announce(message)
@@ -192,7 +192,7 @@ module Kumade
192
192
  say("==> #{message}", :green)
193
193
  end
194
194
 
195
- def ensure_heroku_remote_exists_for(environment)
195
+ def ensure_heroku_remote_exists
196
196
  if remote_exists?(environment)
197
197
  if app_name = Kumade.app_for(environment)
198
198
  success("#{environment} is a Heroku remote")
@@ -10,7 +10,7 @@ module Kumade
10
10
  say("==> In Pretend Mode", :red) if options[:pretend]
11
11
  say "==> Deploying to: #{environment}"
12
12
 
13
- Deployer.new(options[:pretend]).deploy_to(environment)
13
+ Deployer.new(environment, options[:pretend]).deploy
14
14
 
15
15
  say "==> Deployed to: #{environment}", :green
16
16
  end
@@ -1,3 +1,3 @@
1
1
  module Kumade
2
- VERSION = "0.0.9"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -28,10 +28,11 @@ describe Kumade::Deployer, "#pre_deploy" do
28
28
  end
29
29
  end
30
30
 
31
- describe Kumade::Deployer, "#deploy_to" do
31
+ describe Kumade::Deployer, "#deploy" do
32
32
  let(:remote_name){ 'staging' }
33
33
  let(:app_name){ 'kumade-staging' }
34
34
 
35
+
35
36
  before do
36
37
  subject.stub(:say)
37
38
  force_add_heroku_remote(remote_name, app_name)
@@ -42,9 +43,8 @@ describe Kumade::Deployer, "#deploy_to" do
42
43
  it "calls the correct methods in order" do
43
44
  subject.stub(:run => true)
44
45
 
45
- subject.should_receive(:ensure_heroku_remote_exists_for).
46
- ordered.
47
- with(remote_name)
46
+ subject.should_receive(:ensure_heroku_remote_exists).
47
+ ordered
48
48
 
49
49
  subject.should_receive(:pre_deploy).
50
50
  ordered.
@@ -55,34 +55,20 @@ describe Kumade::Deployer, "#deploy_to" do
55
55
  and_return(true)
56
56
 
57
57
  subject.should_receive(:heroku_migrate).
58
- ordered.
59
- with(remote_name)
58
+ ordered
60
59
 
61
60
  subject.should_receive(:post_deploy)
62
61
 
63
- subject.deploy_to(remote_name)
64
- end
65
-
66
- it "deploys to the correct remote" do
67
- subject.stub(:ensure_heroku_remote_exists_for => true,
68
- :pre_deploy => true,
69
- :on_cedar? => false,
70
- :run => true)
71
-
72
- subject.should_receive(:sync_heroku).with(remote_name)
73
-
74
- subject.deploy_to(remote_name)
62
+ subject.deploy
75
63
  end
76
64
  end
77
65
 
78
66
  describe Kumade::Deployer, "#sync_github" do
79
- let(:remote){ 'origin' }
80
-
81
67
  before { subject.stub(:say) }
82
68
 
83
69
  it "calls `git push`" do
84
70
  subject.should_receive(:run).
85
- with("git push #{remote} master").
71
+ with("git push origin master").
86
72
  and_return(true)
87
73
  subject.sync_github
88
74
  end
@@ -91,7 +77,7 @@ describe Kumade::Deployer, "#sync_github" do
91
77
  before { subject.stub(:run => false) }
92
78
 
93
79
  it "prints an error message" do
94
- subject.should_receive(:error).with("Failed to push master -> #{remote}")
80
+ subject.should_receive(:error).with("Failed to push master -> origin")
95
81
 
96
82
  subject.sync_github
97
83
  end
@@ -106,7 +92,7 @@ describe Kumade::Deployer, "#sync_github" do
106
92
  end
107
93
 
108
94
  it "prints a success message" do
109
- subject.should_receive(:success).with("Pushed master -> #{remote}")
95
+ subject.should_receive(:success).with("Pushed master -> origin")
110
96
 
111
97
  subject.sync_github
112
98
  end
@@ -114,14 +100,15 @@ describe Kumade::Deployer, "#sync_github" do
114
100
  end
115
101
 
116
102
  describe Kumade::Deployer, "#sync_heroku" do
117
- let(:environment) { 'staging' }
103
+ let(:environment) { 'my-env' }
104
+ subject { Kumade::Deployer.new(environment) }
118
105
  before { subject.stub(:say) }
119
106
 
120
107
  it "calls `git push -f`" do
121
108
  subject.should_receive(:run).
122
109
  with("git push -f #{environment} deploy:master").
123
110
  and_return(true)
124
- subject.sync_heroku(environment)
111
+ subject.sync_heroku
125
112
  end
126
113
 
127
114
  context "when syncing to heroku fails" do
@@ -131,7 +118,7 @@ describe Kumade::Deployer, "#sync_heroku" do
131
118
 
132
119
  it "prints an error" do
133
120
  subject.should_receive(:error)
134
- subject.sync_heroku(environment)
121
+ subject.sync_heroku
135
122
  end
136
123
  end
137
124
 
@@ -143,14 +130,14 @@ describe Kumade::Deployer, "#sync_heroku" do
143
130
 
144
131
  it "does not raise an error" do
145
132
  subject.should_not_receive(:error)
146
- subject.sync_heroku(environment)
133
+ subject.sync_heroku
147
134
  end
148
135
 
149
136
  it "prints a success message" do
150
137
  subject.should_receive(:success).
151
138
  with("Force pushed master -> #{environment}")
152
139
 
153
- subject.sync_heroku(environment)
140
+ subject.sync_heroku
154
141
  end
155
142
  end
156
143
  end
@@ -439,11 +426,11 @@ describe Kumade::Deployer, "#heroku_migrate" do
439
426
  with("rake db:migrate", app_name)
440
427
  subject.should_receive(:success).with("Migrated #{app_name}")
441
428
 
442
- subject.heroku_migrate(environment)
429
+ subject.heroku_migrate
443
430
  end
444
431
  end
445
432
 
446
- describe Kumade::Deployer, "#ensure_heroku_remote_exists_for" do
433
+ describe Kumade::Deployer, "#ensure_heroku_remote_exists" do
447
434
  let(:environment){ 'staging' }
448
435
  let(:bad_environment){ 'bad' }
449
436
  let(:staging_app_name) { 'staging-sushi' }
@@ -460,35 +447,40 @@ describe Kumade::Deployer, "#ensure_heroku_remote_exists_for" do
460
447
  end
461
448
 
462
449
  context "when the remote points to Heroku" do
450
+ subject { Kumade::Deployer.new(environment) }
451
+
463
452
  it "does not print an error" do
464
453
  subject.should_not_receive(:error)
465
454
 
466
- subject.ensure_heroku_remote_exists_for(environment)
455
+ subject.ensure_heroku_remote_exists
467
456
  end
468
457
 
469
458
  it "prints a success message" do
470
459
  subject.should_receive(:success).with("#{environment} is a Heroku remote")
471
460
 
472
- subject.ensure_heroku_remote_exists_for(environment)
461
+ subject.ensure_heroku_remote_exists
473
462
  end
474
463
  end
475
464
 
476
465
 
477
466
  context "when the remote does not exist" do
467
+ subject { Kumade::Deployer.new(environment) }
478
468
  before { remove_remote(environment) }
479
469
 
480
470
  it "prints an error" do
481
471
  subject.should_receive(:error).with(%{Cannot deploy: "#{environment}" remote does not exist})
482
472
 
483
- subject.ensure_heroku_remote_exists_for(environment)
473
+ subject.ensure_heroku_remote_exists
484
474
  end
485
475
  end
486
476
 
487
477
  context "when the remote does not point to Heroku" do
478
+ subject { Kumade::Deployer.new(bad_environment) }
479
+
488
480
  it "prints an error" do
489
481
  subject.should_receive(:error).with(%{Cannot deploy: "#{bad_environment}" remote does not point to Heroku})
490
482
 
491
- subject.ensure_heroku_remote_exists_for(bad_environment)
483
+ subject.ensure_heroku_remote_exists
492
484
  end
493
485
  end
494
486
  end
@@ -6,8 +6,8 @@ module Kumade
6
6
 
7
7
  let(:environment){ 'bamboo' }
8
8
 
9
- it "calls the deploy method with the correct environment" do
10
- Deployer.any_instance.should_receive(:deploy_to).with(environment)
9
+ it "calls the deploy method" do
10
+ Deployer.any_instance.should_receive(:deploy)
11
11
  subject.deploy(environment)
12
12
  end
13
13
  end
metadata CHANGED
@@ -1,8 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kumade
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 27
4
5
  prerelease:
5
- version: 0.0.9
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
6
11
  platform: ruby
7
12
  authors:
8
13
  - Gabe Berke-Williams
@@ -11,7 +16,8 @@ autorequire:
11
16
  bindir: bin
12
17
  cert_chain: []
13
18
 
14
- date: 2011-08-02 00:00:00 Z
19
+ date: 2011-08-05 00:00:00 -04:00
20
+ default_executable:
15
21
  dependencies:
16
22
  - !ruby/object:Gem::Dependency
17
23
  name: heroku
@@ -21,6 +27,9 @@ dependencies:
21
27
  requirements:
22
28
  - - ">="
23
29
  - !ruby/object:Gem::Version
30
+ hash: 3
31
+ segments:
32
+ - 0
24
33
  version: "0"
25
34
  type: :runtime
26
35
  version_requirements: *id001
@@ -32,6 +41,10 @@ dependencies:
32
41
  requirements:
33
42
  - - ~>
34
43
  - !ruby/object:Gem::Version
44
+ hash: 23
45
+ segments:
46
+ - 0
47
+ - 14
35
48
  version: "0.14"
36
49
  type: :runtime
37
50
  version_requirements: *id002
@@ -43,6 +56,11 @@ dependencies:
43
56
  requirements:
44
57
  - - ~>
45
58
  - !ruby/object:Gem::Version
59
+ hash: 49
60
+ segments:
61
+ - 0
62
+ - 8
63
+ - 7
46
64
  version: 0.8.7
47
65
  type: :development
48
66
  version_requirements: *id003
@@ -54,6 +72,11 @@ dependencies:
54
72
  requirements:
55
73
  - - ~>
56
74
  - !ruby/object:Gem::Version
75
+ hash: 23
76
+ segments:
77
+ - 2
78
+ - 6
79
+ - 0
57
80
  version: 2.6.0
58
81
  type: :development
59
82
  version_requirements: *id004
@@ -65,6 +88,11 @@ dependencies:
65
88
  requirements:
66
89
  - - ~>
67
90
  - !ruby/object:Gem::Version
91
+ hash: 19
92
+ segments:
93
+ - 1
94
+ - 0
95
+ - 2
68
96
  version: 1.0.2
69
97
  type: :development
70
98
  version_requirements: *id005
@@ -76,6 +104,11 @@ dependencies:
76
104
  requirements:
77
105
  - - ~>
78
106
  - !ruby/object:Gem::Version
107
+ hash: 9
108
+ segments:
109
+ - 0
110
+ - 4
111
+ - 3
79
112
  version: 0.4.3
80
113
  type: :development
81
114
  version_requirements: *id006
@@ -87,6 +120,11 @@ dependencies:
87
120
  requirements:
88
121
  - - ~>
89
122
  - !ruby/object:Gem::Version
123
+ hash: 1
124
+ segments:
125
+ - 0
126
+ - 6
127
+ - 3
90
128
  version: 0.6.3
91
129
  type: :development
92
130
  version_requirements: *id007
@@ -121,6 +159,7 @@ files:
121
159
  - spec/kumade/thor_task_spec.rb
122
160
  - spec/kumade_spec.rb
123
161
  - spec/spec_helper.rb
162
+ has_rdoc: true
124
163
  homepage: ""
125
164
  licenses: []
126
165
 
@@ -134,17 +173,23 @@ required_ruby_version: !ruby/object:Gem::Requirement
134
173
  requirements:
135
174
  - - ">="
136
175
  - !ruby/object:Gem::Version
176
+ hash: 3
177
+ segments:
178
+ - 0
137
179
  version: "0"
138
180
  required_rubygems_version: !ruby/object:Gem::Requirement
139
181
  none: false
140
182
  requirements:
141
183
  - - ">="
142
184
  - !ruby/object:Gem::Version
185
+ hash: 3
186
+ segments:
187
+ - 0
143
188
  version: "0"
144
189
  requirements: []
145
190
 
146
191
  rubyforge_project:
147
- rubygems_version: 1.8.6
192
+ rubygems_version: 1.6.2
148
193
  signing_key:
149
194
  specification_version: 3
150
195
  summary: Simple rake tasks for deploying to Heroku