kumade 0.4.0 → 0.5.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/README.md +9 -1
- data/features/kumade_executable.feature +11 -12
- data/features/kumade_without_jammit.feature +2 -2
- data/kumade.gemspec +1 -0
- data/lib/kumade.rb +7 -1
- data/lib/kumade/cli.rb +4 -4
- data/lib/kumade/command_line.rb +33 -0
- data/lib/kumade/configuration.rb +13 -6
- data/lib/kumade/deployer.rb +9 -9
- data/lib/kumade/git.rb +25 -20
- data/lib/kumade/heroku.rb +18 -11
- data/lib/kumade/outputter.rb +21 -0
- data/lib/kumade/packager.rb +23 -76
- data/lib/kumade/packager_list.rb +29 -0
- data/lib/kumade/packagers/jammit_packager.rb +20 -0
- data/lib/kumade/packagers/more_packager.rb +20 -0
- data/lib/kumade/packagers/noop_packager.rb +14 -0
- data/lib/kumade/rake_task_runner.rb +29 -0
- data/lib/kumade/version.rb +1 -1
- data/spec/kumade/cli_spec.rb +5 -5
- data/spec/kumade/command_line_spec.rb +107 -0
- data/spec/kumade/configuration_spec.rb +15 -2
- data/spec/kumade/deployer_spec.rb +39 -25
- data/spec/kumade/git_spec.rb +168 -57
- data/spec/kumade/heroku_spec.rb +19 -25
- data/spec/kumade/outputter_spec.rb +50 -0
- data/spec/kumade/packager_list_spec.rb +31 -0
- data/spec/kumade/packager_spec.rb +66 -275
- data/spec/kumade/packagers/jammit_packager_spec.rb +27 -0
- data/spec/kumade/packagers/more_packager_spec.rb +37 -0
- data/spec/kumade/packagers/noop_packager_spec.rb +9 -0
- data/spec/kumade/rake_task_runner_spec.rb +75 -0
- data/spec/spec_helper.rb +13 -2
- data/spec/support/define_constant.rb +41 -0
- data/spec/support/environments.rb +32 -0
- data/spec/support/git.rb +5 -0
- data/spec/support/heroku.rb +6 -6
- data/spec/support/shared_examples/packager.rb +6 -0
- metadata +65 -28
- data/lib/kumade/base.rb +0 -35
- data/spec/kumade/base_spec.rb +0 -99
@@ -0,0 +1,29 @@
|
|
1
|
+
module Kumade
|
2
|
+
class PackagerList
|
3
|
+
include Enumerable
|
4
|
+
|
5
|
+
PACKAGERS = [MorePackager, JammitPackager]
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@packagers = build_packagers_list
|
9
|
+
end
|
10
|
+
|
11
|
+
def each(&block)
|
12
|
+
@packagers.each(&block)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def build_packagers_list
|
18
|
+
if installed_packagers.any?
|
19
|
+
installed_packagers
|
20
|
+
else
|
21
|
+
[NoopPackager]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def installed_packagers
|
26
|
+
PACKAGERS.select(&:installed?)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
begin
|
2
|
+
require "jammit"
|
3
|
+
rescue LoadError
|
4
|
+
end
|
5
|
+
|
6
|
+
module Kumade
|
7
|
+
class JammitPackager
|
8
|
+
def self.assets_path
|
9
|
+
File.join(Jammit::PUBLIC_ROOT, Jammit.package_path)
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.installed?
|
13
|
+
!!defined?(Jammit)
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.package
|
17
|
+
Jammit.package!
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
begin
|
2
|
+
require "less/more"
|
3
|
+
rescue LoadError
|
4
|
+
end
|
5
|
+
|
6
|
+
module Kumade
|
7
|
+
class MorePackager
|
8
|
+
def self.assets_path
|
9
|
+
File.join("public", ::Less::More.destination_path)
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.installed?
|
13
|
+
!!defined?(Less::More)
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.package
|
17
|
+
::Less::More.generate_all
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Kumade
|
2
|
+
class RakeTaskRunner
|
3
|
+
def initialize(task_name)
|
4
|
+
@task_name = task_name
|
5
|
+
end
|
6
|
+
|
7
|
+
def invoke
|
8
|
+
return unless task_defined?
|
9
|
+
|
10
|
+
Kumade.configuration.outputter.success("Running rake task: #{@task_name}")
|
11
|
+
Rake::Task[@task_name].invoke if task_should_be_run?
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def task_defined?
|
17
|
+
load_rakefile
|
18
|
+
Rake::Task.task_defined?(@task_name)
|
19
|
+
end
|
20
|
+
|
21
|
+
def task_should_be_run?
|
22
|
+
!Kumade.configuration.pretending?
|
23
|
+
end
|
24
|
+
|
25
|
+
def load_rakefile
|
26
|
+
load("Rakefile") if File.exist?("Rakefile")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/kumade/version.rb
CHANGED
data/spec/kumade/cli_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Kumade::CLI do
|
3
|
+
describe Kumade::CLI, :with_mock_outputter do
|
4
4
|
let(:out) { StringIO.new }
|
5
5
|
let(:environment) { 'my-environment' }
|
6
6
|
let(:deployer) { stub("Deployer", :new => deployer_instance) }
|
@@ -16,7 +16,7 @@ describe Kumade::CLI do
|
|
16
16
|
context pretend_flag do
|
17
17
|
it "sets pretending to true" do
|
18
18
|
subject
|
19
|
-
Kumade.configuration.
|
19
|
+
Kumade.configuration.should be_pretending
|
20
20
|
end
|
21
21
|
|
22
22
|
it "deploys" do
|
@@ -36,7 +36,7 @@ describe Kumade::CLI do
|
|
36
36
|
end
|
37
37
|
|
38
38
|
it "sets pretending to false" do
|
39
|
-
Kumade.configuration.
|
39
|
+
Kumade.configuration.should_not be_pretending
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
@@ -45,7 +45,7 @@ describe Kumade::CLI do
|
|
45
45
|
|
46
46
|
it "sets pretending to false" do
|
47
47
|
subject
|
48
|
-
Kumade.configuration.
|
48
|
+
Kumade.configuration.should_not be_pretending
|
49
49
|
end
|
50
50
|
|
51
51
|
it "deploys" do
|
@@ -82,7 +82,7 @@ describe Kumade::CLI, ".swapping_stdout_for" do
|
|
82
82
|
$stdout.puts "Hello, you can't see me."
|
83
83
|
end
|
84
84
|
|
85
|
-
stdout.
|
85
|
+
stdout.should have_received(:print).never
|
86
86
|
|
87
87
|
output.rewind
|
88
88
|
output.read.should == "Hello, you can't see me.\n"
|
@@ -0,0 +1,107 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Kumade::CommandLine, "#run_or_error", :with_mock_outputter do
|
4
|
+
subject { Kumade::CommandLine.new("echo") }
|
5
|
+
|
6
|
+
context "when pretending" do
|
7
|
+
let(:command_line) { stub("Cocaine::CommandLine instance", :run => nil, :command => 'command') }
|
8
|
+
|
9
|
+
before do
|
10
|
+
Cocaine::CommandLine.stubs(:new).returns(command_line)
|
11
|
+
Kumade.configuration.pretending = true
|
12
|
+
end
|
13
|
+
|
14
|
+
it "does not run the command" do
|
15
|
+
subject.run_or_error
|
16
|
+
|
17
|
+
command_line.should have_received(:run).never
|
18
|
+
end
|
19
|
+
|
20
|
+
it "prints the command" do
|
21
|
+
subject.run_or_error
|
22
|
+
Kumade.configuration.outputter.should have_received(:say_command).with(command_line.command).once
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context "when successful" do
|
27
|
+
before do
|
28
|
+
Kumade.configuration.pretending = false
|
29
|
+
end
|
30
|
+
|
31
|
+
it "returns true" do
|
32
|
+
subject.run_or_error.should be_true
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context "when unsuccessful" do
|
37
|
+
subject { Kumade::CommandLine.new("BAD COMMAND") }
|
38
|
+
before do
|
39
|
+
Kumade.configuration.pretending = false
|
40
|
+
end
|
41
|
+
|
42
|
+
it "prints an error message" do
|
43
|
+
subject.run_or_error("something bad")
|
44
|
+
|
45
|
+
Kumade.configuration.outputter.should have_received(:error).with("something bad")
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe Kumade::CommandLine, "#run_with_status", :with_mock_outputter do
|
51
|
+
let(:command) { "echo" }
|
52
|
+
let(:command_line) { stub("Cocaine::CommandLine instance", :run => nil, :command => command) }
|
53
|
+
subject { Kumade::CommandLine.new(command) }
|
54
|
+
|
55
|
+
before do
|
56
|
+
Cocaine::CommandLine.stubs(:new).returns(command_line)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "prints the command" do
|
60
|
+
subject.run_with_status
|
61
|
+
|
62
|
+
Kumade.configuration.outputter.should have_received(:say_command).with(command).once
|
63
|
+
end
|
64
|
+
|
65
|
+
context "when pretending" do
|
66
|
+
before { Kumade.configuration.pretending = true }
|
67
|
+
|
68
|
+
it "does not run the command" do
|
69
|
+
subject.run_with_status
|
70
|
+
|
71
|
+
command_line.should have_received(:run).never
|
72
|
+
end
|
73
|
+
|
74
|
+
it "returns true" do
|
75
|
+
subject.run_with_status.should be_true
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
context "when not pretending" do
|
80
|
+
before { Kumade.configuration.pretending = false }
|
81
|
+
|
82
|
+
it "runs the command" do
|
83
|
+
subject.run_with_status
|
84
|
+
|
85
|
+
command_line.should have_received(:run).once
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe Kumade::CommandLine, "#run", :with_mock_outputter do
|
91
|
+
context "when successful" do
|
92
|
+
subject { Kumade::CommandLine.new("echo") }
|
93
|
+
|
94
|
+
it "returns true" do
|
95
|
+
subject.run.should == true
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
context "when unsuccessful" do
|
100
|
+
let(:bad_command) { "grep FAKE NOT_A_FILE" }
|
101
|
+
subject { Kumade::CommandLine.new("#{bad_command} 2>/dev/null") }
|
102
|
+
|
103
|
+
it "returns false" do
|
104
|
+
subject.run.should be_false
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -5,10 +5,23 @@ describe Kumade::Configuration, "by default" do
|
|
5
5
|
it { should_not be_pretending }
|
6
6
|
end
|
7
7
|
|
8
|
+
describe Kumade::Configuration, "#outputter" do
|
9
|
+
it "defaults to a Kumade::Outputter instance" do
|
10
|
+
subject.outputter.should be_a Kumade::Outputter
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe Kumade::Configuration, "#outputter=" do
|
15
|
+
it "sets outputter" do
|
16
|
+
subject.outputter = "new-value"
|
17
|
+
subject.outputter.should == "new-value"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
8
21
|
describe Kumade::Configuration, "#pretending" do
|
9
22
|
it "has read/write access for the pretending attribute" do
|
10
23
|
subject.pretending = true
|
11
|
-
subject.
|
24
|
+
subject.should be_pretending
|
12
25
|
end
|
13
26
|
end
|
14
27
|
|
@@ -24,7 +37,7 @@ describe Kumade::Configuration, "#pretending?" do
|
|
24
37
|
end
|
25
38
|
|
26
39
|
it "defaults to false" do
|
27
|
-
subject.
|
40
|
+
subject.should_not be_pretending
|
28
41
|
end
|
29
42
|
end
|
30
43
|
|
@@ -1,8 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
describe Kumade::Deployer, "#pre_deploy" do
|
3
|
+
describe Kumade::Deployer, "#pre_deploy", :with_mock_outputter do
|
6
4
|
let(:git) { subject.git }
|
7
5
|
|
8
6
|
it "calls the correct methods" do
|
@@ -14,11 +12,10 @@ describe Kumade::Deployer, "#pre_deploy" do
|
|
14
12
|
end
|
15
13
|
end
|
16
14
|
|
17
|
-
describe Kumade::Deployer, "#deploy" do
|
15
|
+
describe Kumade::Deployer, "#deploy", :with_mock_outputter do
|
18
16
|
let(:remote_name) { 'staging' }
|
19
17
|
|
20
18
|
before do
|
21
|
-
STDOUT.stubs(:puts)
|
22
19
|
force_add_heroku_remote(remote_name)
|
23
20
|
end
|
24
21
|
|
@@ -31,37 +28,43 @@ describe Kumade::Deployer, "#deploy" do
|
|
31
28
|
subject.deploy
|
32
29
|
end
|
33
30
|
|
34
|
-
|
35
|
-
subject.git.stubs(:heroku_remote?).raises(RuntimeError)
|
31
|
+
context "if deploy fails" do
|
32
|
+
before { subject.git.stubs(:heroku_remote?).raises(RuntimeError.new("fun times")) }
|
36
33
|
|
37
|
-
|
34
|
+
it "calls post_deploy" do
|
35
|
+
subject.expects(:post_deploy)
|
36
|
+
subject.deploy
|
37
|
+
end
|
38
38
|
|
39
|
-
|
39
|
+
it "prints the error" do
|
40
|
+
subject.deploy
|
41
|
+
Kumade.configuration.outputter.should have_received(:error).with("RuntimeError: fun times")
|
42
|
+
end
|
40
43
|
end
|
41
44
|
end
|
42
45
|
|
43
|
-
describe Kumade::Deployer, "#
|
46
|
+
describe Kumade::Deployer, "#sync_origin", :with_mock_outputter do
|
44
47
|
let(:new_branch) { 'new-branch' }
|
45
48
|
|
46
49
|
before do
|
47
|
-
`git checkout -b #{new_branch}`
|
50
|
+
`git checkout -b #{new_branch} 2>/dev/null`
|
48
51
|
end
|
49
52
|
|
50
|
-
it "pushes the current branch to
|
53
|
+
it "pushes the current branch to origin" do
|
51
54
|
subject.git.expects(:push).with(new_branch)
|
52
55
|
|
53
|
-
subject.
|
56
|
+
subject.sync_origin
|
54
57
|
end
|
55
58
|
end
|
56
59
|
|
57
|
-
describe Kumade::Deployer, "#ensure_clean_git" do
|
60
|
+
describe Kumade::Deployer, "#ensure_clean_git", :with_mock_outputter do
|
58
61
|
it "calls git.ensure_clean_git" do
|
59
62
|
subject.git.expects(:ensure_clean_git)
|
60
63
|
subject.ensure_clean_git
|
61
64
|
end
|
62
65
|
end
|
63
66
|
|
64
|
-
describe Kumade::Deployer, "#ensure_heroku_remote_exists" do
|
67
|
+
describe Kumade::Deployer, "#ensure_heroku_remote_exists", :with_mock_outputter do
|
65
68
|
let(:environment) { 'staging' }
|
66
69
|
|
67
70
|
before do
|
@@ -70,31 +73,28 @@ describe Kumade::Deployer, "#ensure_heroku_remote_exists" do
|
|
70
73
|
end
|
71
74
|
|
72
75
|
context "when the remote points to Heroku" do
|
73
|
-
before { STDOUT.stubs(:puts) }
|
74
|
-
|
75
76
|
it "does not print an error" do
|
76
77
|
subject.ensure_heroku_remote_exists
|
77
78
|
|
78
|
-
|
79
|
+
Kumade.configuration.outputter.should have_received(:error).never
|
79
80
|
end
|
80
81
|
|
81
82
|
it "prints a success message" do
|
82
83
|
subject.ensure_heroku_remote_exists
|
83
84
|
|
84
|
-
|
85
|
+
Kumade.configuration.outputter.should have_received(:success).with(regexp_matches(/#{environment} is a Heroku remote/))
|
85
86
|
end
|
86
87
|
end
|
87
88
|
|
88
89
|
context "when the remote does not exist" do
|
89
90
|
before do
|
90
91
|
remove_remote(environment)
|
91
|
-
STDOUT.stubs(:puts)
|
92
92
|
end
|
93
93
|
|
94
94
|
it "prints an error" do
|
95
|
-
|
95
|
+
subject.ensure_heroku_remote_exists
|
96
96
|
|
97
|
-
|
97
|
+
Kumade.configuration.outputter.should have_received(:error).with(regexp_matches(/Cannot deploy: "#{environment}" remote does not exist/))
|
98
98
|
end
|
99
99
|
end
|
100
100
|
|
@@ -103,14 +103,28 @@ describe Kumade::Deployer, "#ensure_heroku_remote_exists" do
|
|
103
103
|
|
104
104
|
before do
|
105
105
|
`git remote add #{bad_environment} blerg@example.com`
|
106
|
-
STDOUT.stubs(:puts)
|
107
106
|
Kumade.configuration.environment = bad_environment
|
108
107
|
end
|
109
108
|
|
110
109
|
it "prints an error" do
|
111
|
-
|
110
|
+
subject.ensure_heroku_remote_exists
|
112
111
|
|
113
|
-
|
112
|
+
Kumade.configuration.outputter.should have_received(:error).with(regexp_matches(/Cannot deploy: "#{bad_environment}" remote does not point to Heroku/))
|
114
113
|
end
|
115
114
|
end
|
116
115
|
end
|
116
|
+
|
117
|
+
describe Kumade::Deployer, "packaging", :with_mock_outputter do
|
118
|
+
let(:git) { stub("git", :current_branch => "awesome", :delete => true) }
|
119
|
+
let(:packager) { stub("packager", :run => true) }
|
120
|
+
|
121
|
+
before do
|
122
|
+
Kumade::Git.stubs(:new => git)
|
123
|
+
Kumade::Packager.stubs(:new => packager)
|
124
|
+
end
|
125
|
+
|
126
|
+
it "builds the correct packager" do
|
127
|
+
subject.deploy
|
128
|
+
Kumade::Packager.should have_received(:new).with(git)
|
129
|
+
end
|
130
|
+
end
|