pulsar 0.3.4 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.hound.yml +3 -0
- data/.rubocop.yml +5 -0
- data/.ruby-version +1 -1
- data/.travis.yml +4 -1
- data/README.md +4 -4
- data/Rakefile +3 -3
- data/lib/pulsar.rb +9 -8
- data/lib/pulsar/commands/all.rb +4 -4
- data/lib/pulsar/commands/init.rb +7 -5
- data/lib/pulsar/commands/main.rb +43 -32
- data/lib/pulsar/commands/utils.rb +7 -3
- data/lib/pulsar/generators/init_repo/apps/your_app/defaults.rb +1 -1
- data/lib/pulsar/generators/init_repo/apps/your_app/production.rb +2 -2
- data/lib/pulsar/generators/init_repo/apps/your_app/staging.rb +2 -2
- data/lib/pulsar/generators/init_repo/recipes/generic/cleanup.rb +9 -9
- data/lib/pulsar/generators/init_repo/recipes/generic/utils.rb +6 -3
- data/lib/pulsar/helpers/all.rb +7 -5
- data/lib/pulsar/helpers/capistrano.rb +4 -4
- data/lib/pulsar/helpers/clamp.rb +32 -33
- data/lib/pulsar/helpers/path.rb +15 -2
- data/lib/pulsar/helpers/shell.rb +3 -3
- data/lib/pulsar/options/all.rb +5 -3
- data/lib/pulsar/options/conf_repo.rb +17 -16
- data/lib/pulsar/options/shared.rb +3 -2
- data/lib/pulsar/version.rb +1 -1
- data/pulsar.gemspec +17 -17
- data/spec/pulsar/commands/init_spec.rb +4 -3
- data/spec/pulsar/commands/list_spec.rb +63 -47
- data/spec/pulsar/commands/main_spec.rb +175 -125
- data/spec/pulsar/commands/utils_spec.rb +13 -13
- data/spec/pulsar/helpers/capistrano_spec.rb +37 -31
- data/spec/pulsar/helpers/clamp_spec.rb +68 -37
- data/spec/pulsar/helpers/shell_spec.rb +3 -3
- data/spec/spec_helper.rb +12 -11
- data/spec/support/dummies/dummy_conf/Gemfile +1 -1
- data/spec/support/dummies/dummy_conf/apps/base.rb +5 -5
- data/spec/support/dummies/dummy_conf/apps/dummy_app/custom_stage.rb +2 -2
- data/spec/support/dummies/dummy_conf/apps/dummy_app/defaults.rb +1 -1
- data/spec/support/dummies/dummy_conf/apps/dummy_app/production.rb +2 -2
- data/spec/support/dummies/dummy_conf/apps/dummy_app/staging.rb +2 -2
- data/spec/support/dummies/dummy_conf/apps/other_dummy_app/custom_stage.rb +2 -2
- data/spec/support/dummies/dummy_conf/apps/other_dummy_app/defaults.rb +1 -1
- data/spec/support/dummies/dummy_conf/apps/other_dummy_app/production.rb +2 -2
- data/spec/support/dummies/dummy_conf/apps/other_dummy_app/staging.rb +2 -2
- data/spec/support/modules/helpers.rb +40 -35
- metadata +20 -17
@@ -1,33 +1,33 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Pulsar::UtilsCommand do
|
4
|
-
let(:pulsar) { Pulsar::UtilsCommand.new(
|
4
|
+
let(:pulsar) { Pulsar::UtilsCommand.new('') }
|
5
5
|
|
6
|
-
context
|
6
|
+
context '--version option' do
|
7
7
|
before do
|
8
8
|
begin
|
9
|
-
pulsar.parse([
|
9
|
+
pulsar.parse(['--version'])
|
10
10
|
rescue SystemExit => e
|
11
11
|
@system_exit = e
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
it
|
16
|
-
stdout.
|
15
|
+
it 'shows version' do
|
16
|
+
expect(stdout).to include(Pulsar::VERSION)
|
17
17
|
end
|
18
18
|
|
19
|
-
it
|
20
|
-
@system_exit.
|
21
|
-
@system_exit.status.
|
19
|
+
it 'exits with a zero status' do
|
20
|
+
expect(@system_exit).not_to be_nil
|
21
|
+
expect(@system_exit.status).to be 0
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
context
|
26
|
-
it
|
25
|
+
context 'subcommands' do
|
26
|
+
it 'should be cap and list and init' do
|
27
27
|
help = pulsar.help
|
28
|
-
help.
|
29
|
-
help.
|
30
|
-
help.
|
28
|
+
expect(help).to match(/Subcommands:/)
|
29
|
+
expect(help).to match(/list/)
|
30
|
+
expect(help).to match(/init/)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
@@ -3,62 +3,68 @@ require 'spec_helper'
|
|
3
3
|
describe Pulsar::Helpers::Capistrano do
|
4
4
|
include Pulsar::Helpers::Capistrano
|
5
5
|
|
6
|
-
context
|
7
|
-
it
|
8
|
-
ENV['CONFIG_PATH'] =
|
9
|
-
File.
|
10
|
-
File.
|
11
|
-
|
12
|
-
self.should_receive(:load).with("/config/path/recipes/generic/recipe.rb")
|
6
|
+
context 'load_recipes' do
|
7
|
+
it 'loads capistrano recipes from CONFIG_PATH env variable' do
|
8
|
+
ENV['CONFIG_PATH'] = '/config/path'
|
9
|
+
allow(File).to receive(:directory?).and_return(true)
|
10
|
+
allow(File).to receive(:exist?).and_return(true)
|
11
|
+
allow(self).to receive(:load)
|
13
12
|
|
14
13
|
load_recipes { generic :recipe }
|
14
|
+
|
15
|
+
expect(self)
|
16
|
+
.to have_received(:load).with('/config/path/recipes/generic/recipe.rb')
|
15
17
|
end
|
16
18
|
|
17
|
-
it
|
18
|
-
File.
|
19
|
+
it 'raises a missing recipe exception when no recipe folder is found' do
|
20
|
+
allow(File).to receive(:directory?).and_return(false)
|
19
21
|
|
20
|
-
expect { load_recipes { generic :recipe } }
|
22
|
+
expect { load_recipes { generic :recipe } }
|
23
|
+
.to raise_error(RuntimeError, /no recipes of type generic/)
|
21
24
|
end
|
22
25
|
|
23
|
-
it
|
24
|
-
File.
|
25
|
-
File.
|
26
|
+
it 'raises a missing recipe exception when no recipe is found' do
|
27
|
+
allow(File).to receive(:directory?).and_return(true)
|
28
|
+
allow(File).to receive(:exist?).and_return(false)
|
26
29
|
|
27
|
-
expect { load_recipes { generic :missing_recipe } }
|
30
|
+
expect { load_recipes { generic :missing_recipe } }
|
31
|
+
.to raise_error(RuntimeError, /no missing_recipe recipe/)
|
28
32
|
end
|
29
33
|
|
30
|
-
it
|
34
|
+
it 'does not load if :app_only and pulsar is not inside an application' do
|
31
35
|
ENV.delete('APP_PATH')
|
32
|
-
File.
|
33
|
-
File.
|
36
|
+
allow(File).to receive(:directory?).and_return(true)
|
37
|
+
allow(File).to receive(:exist?).and_return(true)
|
38
|
+
allow(self).to receive(:load)
|
34
39
|
|
35
|
-
|
40
|
+
load_recipes(app_only: true) { generic :recipe }
|
36
41
|
|
37
|
-
|
42
|
+
expect(self).not_to have_received(:load)
|
38
43
|
end
|
39
44
|
|
40
|
-
it
|
41
|
-
ENV['APP_PATH'] =
|
42
|
-
File.
|
43
|
-
File.
|
45
|
+
it 'loads if :app_only is true and pulsar is inside an application' do
|
46
|
+
ENV['APP_PATH'] = '/app/path'
|
47
|
+
allow(File).to receive(:directory?).and_return(true)
|
48
|
+
allow(File).to receive(:exist?).and_return(true)
|
49
|
+
allow(self).to receive(:load)
|
44
50
|
|
45
|
-
|
51
|
+
load_recipes(app_only: true) { generic :recipe }
|
46
52
|
|
47
|
-
|
53
|
+
expect(self).to have_received(:load)
|
48
54
|
end
|
49
55
|
end
|
50
56
|
|
51
|
-
context
|
52
|
-
it
|
53
|
-
ENV['APP_PATH'] =
|
57
|
+
context 'from_application_path?' do
|
58
|
+
it 'returns true if APP_PATH env variable is set' do
|
59
|
+
ENV['APP_PATH'] = '/app/path'
|
54
60
|
|
55
|
-
from_application_path
|
61
|
+
expect(from_application_path?).to be true
|
56
62
|
end
|
57
63
|
|
58
|
-
it
|
64
|
+
it 'returns false if APP_PATH env variable is not set' do
|
59
65
|
ENV.delete('APP_PATH')
|
60
66
|
|
61
|
-
from_application_path
|
67
|
+
expect(from_application_path?).to be false
|
62
68
|
end
|
63
69
|
end
|
64
70
|
end
|
@@ -3,72 +3,103 @@ require 'spec_helper'
|
|
3
3
|
describe Pulsar::Helpers::Clamp do
|
4
4
|
include Pulsar::Helpers::Clamp
|
5
5
|
|
6
|
-
context
|
7
|
-
it
|
8
|
-
File.
|
9
|
-
self.
|
10
|
-
|
11
|
-
self.should_receive(:fetch_directory_repo).with("conf-repo/path")
|
6
|
+
context 'fetch_repo' do
|
7
|
+
it 'supports directories' do
|
8
|
+
allow(File).to receive(:directory?).and_return(true)
|
9
|
+
allow(self).to receive(:conf_repo).and_return('conf-repo/path')
|
10
|
+
allow(self).to receive(:fetch_directory_repo)
|
12
11
|
|
13
12
|
fetch_repo
|
14
|
-
end
|
15
13
|
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
expect(self)
|
15
|
+
.to have_received(:fetch_directory_repo).with('conf-repo/path')
|
16
|
+
end
|
19
17
|
|
20
|
-
|
18
|
+
it 'supports full git path' do
|
19
|
+
allow(File).to receive(:directory?).and_return(false)
|
20
|
+
allow(self).to receive(:fetch_git_repo)
|
21
|
+
allow(self)
|
22
|
+
.to receive(:conf_repo)
|
23
|
+
.and_return('git://github.com/gh_user/pulsar-conf.git')
|
21
24
|
|
22
25
|
fetch_repo
|
23
|
-
end
|
24
26
|
|
25
|
-
|
26
|
-
|
27
|
-
|
27
|
+
expect(self)
|
28
|
+
.to have_received(:fetch_git_repo)
|
29
|
+
.with('git://github.com/gh_user/pulsar-conf.git')
|
30
|
+
end
|
28
31
|
|
29
|
-
|
32
|
+
it 'supports full git path on ssh' do
|
33
|
+
allow(File).to receive(:directory?).and_return(false)
|
34
|
+
allow(self).to receive(:fetch_git_repo)
|
35
|
+
allow(self)
|
36
|
+
.to receive(:conf_repo)
|
37
|
+
.and_return('git@github.com:gh_user/pulsar-conf.git')
|
30
38
|
|
31
39
|
fetch_repo
|
32
|
-
end
|
33
40
|
|
34
|
-
|
35
|
-
|
36
|
-
|
41
|
+
expect(self)
|
42
|
+
.to have_received(:fetch_git_repo)
|
43
|
+
.with('git@github.com:gh_user/pulsar-conf.git')
|
44
|
+
end
|
37
45
|
|
38
|
-
|
46
|
+
it 'supports full git path on http' do
|
47
|
+
allow(File).to receive(:directory?).and_return(false)
|
48
|
+
allow(self).to receive(:fetch_git_repo)
|
49
|
+
allow(self)
|
50
|
+
.to receive(:conf_repo)
|
51
|
+
.and_return('https://github.com/gh_user/pulsar.git')
|
39
52
|
|
40
53
|
fetch_repo
|
41
|
-
end
|
42
54
|
|
43
|
-
|
44
|
-
|
45
|
-
|
55
|
+
expect(self)
|
56
|
+
.to have_received(:fetch_git_repo)
|
57
|
+
.with('https://github.com/gh_user/pulsar.git')
|
58
|
+
end
|
46
59
|
|
47
|
-
|
60
|
+
it 'supports github path' do
|
61
|
+
allow(File).to receive(:directory?).and_return(false)
|
62
|
+
allow(self).to receive(:conf_repo).and_return('gh-user/pulsar-conf')
|
63
|
+
allow(self).to receive(:fetch_git_repo)
|
48
64
|
|
49
65
|
fetch_repo
|
66
|
+
|
67
|
+
expect(self)
|
68
|
+
.to have_received(:fetch_git_repo)
|
69
|
+
.with('git@github.com:gh-user/pulsar-conf.git')
|
50
70
|
end
|
51
71
|
end
|
52
72
|
|
53
|
-
context
|
73
|
+
context 'run_capistrano' do
|
54
74
|
before do
|
55
|
-
self.
|
56
|
-
self.
|
57
|
-
self.
|
75
|
+
allow(self).to receive(:config_path).and_return(dummy_conf_path)
|
76
|
+
allow(self).to receive(:verbose?).and_return(false)
|
77
|
+
allow(self).to receive(:capfile_path).and_return('/stubbed/capfile')
|
78
|
+
allow(self).to receive(:run_cmd)
|
58
79
|
end
|
59
80
|
|
60
|
-
it
|
61
|
-
|
81
|
+
it 'runs capistrano when pulsar is invoked from outside an application' do
|
82
|
+
cap_cmd = 'bundle exec cap'
|
83
|
+
env_vars = "CONFIG_PATH=#{config_path}"
|
84
|
+
cmd_args = "--file #{capfile_path} deploy"
|
85
|
+
full_cmd = "#{cap_cmd} #{env_vars} #{cmd_args}"
|
86
|
+
|
87
|
+
run_capistrano('deploy')
|
62
88
|
|
63
|
-
|
89
|
+
expect(self).to have_received(:run_cmd).with(full_cmd, anything)
|
64
90
|
end
|
65
91
|
|
66
|
-
it
|
67
|
-
self.
|
92
|
+
it 'runs capistrano when pulsar is invoked from inside an application' do
|
93
|
+
allow(self).to receive(:application_path).and_return('/app/path')
|
94
|
+
|
95
|
+
cap_cmd = 'bundle exec cap'
|
96
|
+
env_vars = "CONFIG_PATH=#{config_path} APP_PATH=#{application_path}"
|
97
|
+
cmd_args = "--file #{capfile_path} deploy"
|
98
|
+
full_cmd = "#{cap_cmd} #{env_vars} #{cmd_args}"
|
68
99
|
|
69
|
-
|
100
|
+
run_capistrano('deploy')
|
70
101
|
|
71
|
-
|
102
|
+
expect(self).to have_received(:run_cmd).with(full_cmd, anything)
|
72
103
|
end
|
73
104
|
end
|
74
105
|
end
|
@@ -3,9 +3,9 @@ require 'spec_helper'
|
|
3
3
|
describe Pulsar::Helpers::Shell do
|
4
4
|
include Pulsar::Helpers::Shell
|
5
5
|
|
6
|
-
context
|
7
|
-
it
|
8
|
-
expect { run_cmd(
|
6
|
+
context 'run_cmd' do
|
7
|
+
it 'raises exception if command fails' do
|
8
|
+
expect { run_cmd('false', {}) }.to raise_error
|
9
9
|
end
|
10
10
|
end
|
11
11
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,30 +1,31 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
1
|
+
require 'rspec'
|
2
|
+
require 'stringio'
|
3
|
+
require 'fileutils'
|
4
|
+
require 'codeclimate-test-reporter'
|
5
|
+
require 'pulsar'
|
6
|
+
require 'pulsar/commands/main'
|
7
|
+
require 'pulsar/commands/utils'
|
8
8
|
|
9
9
|
#
|
10
10
|
# Code coverage
|
11
11
|
#
|
12
|
-
|
12
|
+
CodeClimate::TestReporter.start
|
13
13
|
|
14
14
|
#
|
15
15
|
# Require all helper modules
|
16
16
|
#
|
17
|
-
Dir[File.join(File.dirname(__FILE__), 'support/modules/**/*.rb')].each
|
17
|
+
Dir[File.join(File.dirname(__FILE__), 'support/modules/**/*.rb')].each do |f|
|
18
|
+
require f
|
19
|
+
end
|
18
20
|
|
19
21
|
RSpec.configure do |config|
|
20
22
|
config.mock_with :rspec
|
23
|
+
config.raise_errors_for_deprecations!
|
21
24
|
|
22
25
|
config.include Helpers
|
23
26
|
config.include OutputCapture
|
24
27
|
|
25
28
|
config.before(:each) do
|
26
|
-
Dir.stub(:home).and_return("/fake/home")
|
27
|
-
|
28
29
|
dummy_dotfile_options.keys.each do |variable|
|
29
30
|
ENV.delete(variable.to_s)
|
30
31
|
end
|
@@ -29,18 +29,18 @@ end
|
|
29
29
|
#
|
30
30
|
set :scm, :git
|
31
31
|
|
32
|
-
set :ssh_options,
|
32
|
+
set :ssh_options, forward_agent: true
|
33
33
|
|
34
|
-
set :default_run_options,
|
34
|
+
set :default_run_options, pty: true
|
35
35
|
|
36
36
|
set :deploy_to, defer { "/var/www/#{application}" }
|
37
37
|
|
38
38
|
set :deploy_via, :remote_cache
|
39
39
|
|
40
|
-
set :user,
|
40
|
+
set :user, 'www-data'
|
41
41
|
|
42
42
|
set :use_sudo, false
|
43
43
|
|
44
|
-
set :rake,
|
44
|
+
set :rake, 'bundle exec rake'
|
45
45
|
|
46
|
-
set :rails_env, defer {
|
46
|
+
set :rails_env, defer { stage }
|