pulsar 0.3.5 → 1.0.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (137) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rspec +1 -0
  4. data/.rubocop.yml +150 -0
  5. data/.ruby-version +1 -1
  6. data/LICENSE.txt +1 -1
  7. data/README.md +4 -265
  8. data/bin/pulsar +1 -1
  9. data/circle.yml +22 -0
  10. data/lib/pulsar.rb +28 -7
  11. data/lib/pulsar/cli.rb +79 -0
  12. data/lib/pulsar/constants.rb +5 -0
  13. data/lib/pulsar/generators/initial_repo/Gemfile +3 -0
  14. data/lib/pulsar/generators/{init_repo → initial_repo}/README.md +1 -1
  15. data/lib/pulsar/generators/initial_repo/apps/Capfile +8 -0
  16. data/lib/pulsar/generators/initial_repo/apps/deploy.rb +35 -0
  17. data/lib/pulsar/generators/initial_repo/apps/your_app/Capfile +18 -0
  18. data/lib/pulsar/generators/initial_repo/apps/your_app/deploy.rb +4 -0
  19. data/lib/pulsar/generators/initial_repo/apps/your_app/production.rb +3 -0
  20. data/lib/pulsar/generators/initial_repo/apps/your_app/staging.rb +3 -0
  21. data/lib/pulsar/generators/initial_repo/recipes/generic/rake.rake +12 -0
  22. data/lib/pulsar/generators/{init_repo/apps/your_app/recipes/production → initial_repo/recipes/rails}/.gitkeep +0 -0
  23. data/lib/pulsar/interactors/add_applications.rb +48 -0
  24. data/lib/pulsar/interactors/cleanup.rb +9 -0
  25. data/lib/pulsar/interactors/clone_repository.rb +50 -0
  26. data/lib/pulsar/interactors/copy_environment_file.rb +30 -0
  27. data/lib/pulsar/interactors/copy_initial_repository.rb +22 -0
  28. data/lib/pulsar/interactors/create_capfile.rb +32 -0
  29. data/lib/pulsar/interactors/create_deploy_file.rb +32 -0
  30. data/lib/pulsar/interactors/create_run_dirs.rb +21 -0
  31. data/lib/pulsar/interactors/identify_repository_location.rb +23 -0
  32. data/lib/pulsar/interactors/identify_repository_type.rb +34 -0
  33. data/lib/pulsar/interactors/run_bundle_install.rb +28 -0
  34. data/lib/pulsar/interactors/run_capistrano.rb +30 -0
  35. data/lib/pulsar/organizers/deploy.rb +16 -0
  36. data/lib/pulsar/organizers/install.rb +7 -0
  37. data/lib/pulsar/organizers/list.rb +12 -0
  38. data/lib/pulsar/version.rb +1 -1
  39. data/pulsar.gemspec +13 -11
  40. data/spec/features/deploy_spec.rb +162 -0
  41. data/spec/features/install_spec.rb +66 -0
  42. data/spec/features/list_spec.rb +140 -0
  43. data/spec/spec_helper.rb +26 -14
  44. data/{lib/pulsar/generators/init_repo/apps/your_app/recipes/staging → spec/support/dummies}/.gitkeep +0 -0
  45. data/spec/support/dummies/conf/dir/Gemfile +3 -0
  46. data/spec/support/dummies/conf/dir/apps/Capfile +9 -0
  47. data/spec/support/dummies/conf/dir/apps/blog/Capfile +1 -0
  48. data/spec/support/dummies/conf/dir/apps/blog/deploy.rb +4 -0
  49. data/spec/support/dummies/conf/dir/apps/blog/production.rb +4 -0
  50. data/spec/support/dummies/conf/dir/apps/blog/staging.rb +4 -0
  51. data/spec/support/dummies/conf/dir/apps/deploy.rb +1 -0
  52. data/{lib/pulsar/generators/init_repo/recipes/rails/.gitkeep → spec/support/dummies/conf/dir/apps/ecommerce/staging.rb} +0 -0
  53. data/spec/support/dummies/conf/dir/recipes/.gitkeep +0 -0
  54. data/spec/support/dummies/conf/dotenv +1 -0
  55. data/spec/support/dummies/conf/empty/apps/.gitkeep +0 -0
  56. data/spec/support/dummies/conf/empty/recipes/.gitkeep +0 -0
  57. data/spec/support/dummies/conf/wrong_bundle/Gemfile +3 -0
  58. data/spec/support/dummies/conf/wrong_bundle/apps/Capfile +9 -0
  59. data/spec/support/dummies/conf/wrong_bundle/apps/blog/Capfile +1 -0
  60. data/spec/support/dummies/conf/wrong_bundle/apps/blog/deploy.rb +4 -0
  61. data/spec/support/dummies/conf/wrong_bundle/apps/blog/production.rb +4 -0
  62. data/spec/support/dummies/conf/wrong_bundle/apps/deploy.rb +1 -0
  63. data/spec/support/dummies/conf/wrong_bundle/recipes/.gitkeep +0 -0
  64. data/spec/support/dummies/conf/wrong_cap/Gemfile +3 -0
  65. data/spec/support/dummies/conf/wrong_cap/apps/Capfile +0 -0
  66. data/spec/support/dummies/conf/wrong_cap/apps/blog/deploy.rb +4 -0
  67. data/spec/support/dummies/conf/wrong_cap/apps/blog/production.rb +4 -0
  68. data/spec/support/dummies/conf/wrong_cap/apps/deploy.rb +1 -0
  69. data/spec/support/dummies/conf/wrong_cap/recipes/.gitkeep +0 -0
  70. data/spec/units/cli/deploy_spec.rb +116 -0
  71. data/spec/units/cli/install_spec.rb +44 -0
  72. data/spec/units/cli/list_spec.rb +107 -0
  73. data/spec/units/constants_spec.rb +21 -0
  74. data/spec/units/interactors/add_applications_spec.rb +46 -0
  75. data/spec/units/interactors/cleanup_spec.rb +21 -0
  76. data/spec/units/interactors/clone_initial_repository_spec.rb +41 -0
  77. data/spec/units/interactors/clone_repository_spec.rb +122 -0
  78. data/spec/units/interactors/copy_environment_file_spec.rb +80 -0
  79. data/spec/units/interactors/create_capfile_spec.rb +77 -0
  80. data/spec/units/interactors/create_deploy_file_spec.rb +70 -0
  81. data/spec/units/interactors/create_run_dirs_spec.rb +47 -0
  82. data/spec/units/interactors/identify_repository_location_spec.rb +49 -0
  83. data/spec/units/interactors/identify_repository_type_spec.rb +85 -0
  84. data/spec/units/interactors/run_bundle_install_spec.rb +60 -0
  85. data/spec/units/interactors/run_capistrano_spec.rb +92 -0
  86. data/spec/units/organizers/deploy_spec.rb +28 -0
  87. data/spec/units/organizers/install_spec.rb +13 -0
  88. data/spec/units/organizers/list_spec.rb +24 -0
  89. metadata +179 -106
  90. data/.ruby-gemset +0 -1
  91. data/.travis.yml +0 -17
  92. data/bin/pulsar-utils +0 -5
  93. data/lib/pulsar/commands/all.rb +0 -6
  94. data/lib/pulsar/commands/init.rb +0 -23
  95. data/lib/pulsar/commands/list.rb +0 -19
  96. data/lib/pulsar/commands/main.rb +0 -64
  97. data/lib/pulsar/commands/utils.rb +0 -14
  98. data/lib/pulsar/generators/init_repo/Gemfile +0 -7
  99. data/lib/pulsar/generators/init_repo/apps/base.rb +0 -41
  100. data/lib/pulsar/generators/init_repo/apps/your_app/defaults.rb +0 -9
  101. data/lib/pulsar/generators/init_repo/apps/your_app/production.rb +0 -12
  102. data/lib/pulsar/generators/init_repo/apps/your_app/recipes/custom_recipe.rb +0 -14
  103. data/lib/pulsar/generators/init_repo/apps/your_app/staging.rb +0 -12
  104. data/lib/pulsar/generators/init_repo/recipes/generic/cleanup.rb +0 -50
  105. data/lib/pulsar/generators/init_repo/recipes/generic/utils.rb +0 -9
  106. data/lib/pulsar/helpers/all.rb +0 -8
  107. data/lib/pulsar/helpers/capistrano.rb +0 -47
  108. data/lib/pulsar/helpers/clamp.rb +0 -223
  109. data/lib/pulsar/helpers/path.rb +0 -71
  110. data/lib/pulsar/helpers/shell.rb +0 -31
  111. data/lib/pulsar/options/all.rb +0 -6
  112. data/lib/pulsar/options/conf_repo.rb +0 -41
  113. data/lib/pulsar/options/shared.rb +0 -15
  114. data/spec/pulsar/commands/init_spec.rb +0 -10
  115. data/spec/pulsar/commands/list_spec.rb +0 -127
  116. data/spec/pulsar/commands/main_spec.rb +0 -360
  117. data/spec/pulsar/commands/utils_spec.rb +0 -33
  118. data/spec/pulsar/helpers/capistrano_spec.rb +0 -70
  119. data/spec/pulsar/helpers/clamp_spec.rb +0 -105
  120. data/spec/pulsar/helpers/shell_spec.rb +0 -11
  121. data/spec/support/dummies/dummy_app/config.ru +0 -3
  122. data/spec/support/dummies/dummy_conf/Gemfile +0 -4
  123. data/spec/support/dummies/dummy_conf/apps/base.rb +0 -46
  124. data/spec/support/dummies/dummy_conf/apps/dummy_app/custom_stage.rb +0 -5
  125. data/spec/support/dummies/dummy_conf/apps/dummy_app/defaults.rb +0 -7
  126. data/spec/support/dummies/dummy_conf/apps/dummy_app/production.rb +0 -5
  127. data/spec/support/dummies/dummy_conf/apps/dummy_app/recipes/custom_recipe.rb +0 -1
  128. data/spec/support/dummies/dummy_conf/apps/dummy_app/recipes/production/custom_recipe.rb +0 -1
  129. data/spec/support/dummies/dummy_conf/apps/dummy_app/recipes/staging/custom_recipe.rb +0 -1
  130. data/spec/support/dummies/dummy_conf/apps/dummy_app/staging.rb +0 -5
  131. data/spec/support/dummies/dummy_conf/apps/other_dummy_app/custom_stage.rb +0 -5
  132. data/spec/support/dummies/dummy_conf/apps/other_dummy_app/defaults.rb +0 -7
  133. data/spec/support/dummies/dummy_conf/apps/other_dummy_app/production.rb +0 -5
  134. data/spec/support/dummies/dummy_conf/apps/other_dummy_app/staging.rb +0 -5
  135. data/spec/support/dummies/dummy_conf/recipes/generic/recipe.rb +0 -3
  136. data/spec/support/modules/helpers.rb +0 -85
  137. data/spec/support/modules/output_capture.rb +0 -21
@@ -0,0 +1,32 @@
1
+ module Pulsar
2
+ class CreateDeployFile
3
+ include Interactor
4
+
5
+ before :validate_input!, :prepare_context
6
+
7
+ def call
8
+ default_deploy = "#{context.config_path}/apps/deploy.rb"
9
+ app_deploy = "#{context.config_path}/apps/#{context.application}/deploy.rb"
10
+
11
+ FileUtils.mkdir_p(context.cap_config_path)
12
+ FileUtils.touch(context.deploy_file_path)
13
+ Rake.sh("cat #{default_deploy} >> #{context.deploy_file_path}") if File.exist?(default_deploy)
14
+ Rake.sh("cat #{app_deploy} >> #{context.deploy_file_path}") if File.exist?(app_deploy)
15
+ rescue
16
+ context.fail!
17
+ end
18
+
19
+ private
20
+
21
+ def prepare_context
22
+ context.cap_config_path = "#{context.cap_path}/config"
23
+ context.deploy_file_path = "#{context.cap_config_path}/deploy.rb"
24
+ end
25
+
26
+ def validate_input!
27
+ context.fail! if context.config_path.nil? ||
28
+ context.cap_path.nil? ||
29
+ context.application.nil?
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,21 @@
1
+ module Pulsar
2
+ class CreateRunDirs
3
+ include Interactor
4
+
5
+ def call
6
+ context.timestamp = Time.now.to_f
7
+ context.bundle_path = "#{PULSAR_HOME}/bundle"
8
+ context.run_path = "#{PULSAR_TMP}/run-#{context.timestamp}"
9
+ context.config_path = "#{context.run_path}/conf"
10
+ context.cap_path = "#{context.run_path}/cap"
11
+
12
+ FileUtils.mkdir_p(context.bundle_path)
13
+ FileUtils.mkdir_p(context.config_path)
14
+ FileUtils.mkdir_p(context.cap_path)
15
+ end
16
+
17
+ def rollback
18
+ FileUtils.rm_rf(context.run_path)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,23 @@
1
+ module Pulsar
2
+ class IdentifyRepositoryLocation
3
+ include Interactor
4
+
5
+ before :validate_input!
6
+
7
+ def call
8
+ context.repository_location = if File.exist?(context.repository)
9
+ :local
10
+ else
11
+ :remote
12
+ end
13
+ rescue
14
+ context.fail!
15
+ end
16
+
17
+ private
18
+
19
+ def validate_input!
20
+ context.fail! if context.repository.nil?
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,34 @@
1
+ module Pulsar
2
+ class IdentifyRepositoryType
3
+ include Interactor
4
+
5
+ before :validate_input!
6
+
7
+ def call
8
+ case context.repository_location
9
+ when :local
10
+ context.repository_type = git_repository? ? :git : :folder
11
+ when :remote
12
+ context.repository_type = github_repository? ? :github : :git
13
+ end
14
+ rescue
15
+ context.fail!
16
+ end
17
+
18
+ private
19
+
20
+ def validate_input!
21
+ context.fail! if context.repository.nil?
22
+ context.fail! if context.repository_location.nil?
23
+ end
24
+
25
+ def git_repository?
26
+ Rake.sh("git -C #{context.repository} status >/dev/null 2>&1") &&
27
+ File.exist?("#{context.repository}/.git")
28
+ end
29
+
30
+ def github_repository?
31
+ context.repository =~ %r{^[\w-]+\/[\w-]+$}
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,28 @@
1
+ module Pulsar
2
+ class RunBundleInstall
3
+ include Interactor
4
+
5
+ before :validate_input!
6
+
7
+ def call
8
+ gemfile_env = "BUNDLE_GEMFILE=#{context.config_path}/Gemfile"
9
+ bundle_env = "BUNDLE_PATH=#{context.bundle_path}"
10
+ cmd_env = "#{gemfile_env} #{bundle_env}"
11
+ out_redir = ENV['DRY_RUN'] ? '> /dev/null 2>&1' : nil
12
+ bundle_cmd = "#{cmd_env} bundle check || #{cmd_env} bundle install"
13
+
14
+ Bundler.with_clean_env do
15
+ context.fail! unless system("#{bundle_cmd}#{out_redir}")
16
+ end
17
+ rescue
18
+ context.fail!
19
+ end
20
+
21
+ private
22
+
23
+ def validate_input!
24
+ context.fail! if context.config_path.nil? ||
25
+ context.bundle_path.nil?
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,30 @@
1
+ module Pulsar
2
+ class RunCapistrano
3
+ include Interactor
4
+
5
+ before :validate_input!
6
+
7
+ def call
8
+ Dir.chdir(context.cap_path) do
9
+ gemfile_env = "BUNDLE_GEMFILE=#{context.config_path}/Gemfile"
10
+ bundle_env = "BUNDLE_PATH=#{context.bundle_path}"
11
+ cap_opts = ENV['DRY_RUN'] ? '--dry-run ' : nil
12
+ out_redir = ENV['DRY_RUN'] ? '> /dev/null 2>&1' : nil
13
+ cap_cmd = "bundle exec cap #{cap_opts}#{context.environment} deploy"
14
+
15
+ context.fail! unless system("#{gemfile_env} #{bundle_env} #{cap_cmd}#{out_redir}")
16
+ end
17
+ rescue
18
+ context.fail!
19
+ end
20
+
21
+ private
22
+
23
+ def validate_input!
24
+ context.fail! if context.cap_path.nil? ||
25
+ context.config_path.nil? ||
26
+ context.bundle_path.nil? ||
27
+ context.environment.nil?
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,16 @@
1
+ module Pulsar
2
+ class Deploy
3
+ include Interactor::Organizer
4
+
5
+ organize IdentifyRepositoryLocation,
6
+ IdentifyRepositoryType,
7
+ CreateRunDirs,
8
+ CloneRepository,
9
+ CreateCapfile,
10
+ CreateDeployFile,
11
+ CopyEnvironmentFile,
12
+ RunBundleInstall,
13
+ RunCapistrano,
14
+ Cleanup
15
+ end
16
+ end
@@ -0,0 +1,7 @@
1
+ module Pulsar
2
+ class Install
3
+ include Interactor::Organizer
4
+
5
+ organize CopyInitialRepository
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ module Pulsar
2
+ class List
3
+ include Interactor::Organizer
4
+
5
+ organize IdentifyRepositoryLocation,
6
+ IdentifyRepositoryType,
7
+ CreateRunDirs,
8
+ CloneRepository,
9
+ AddApplications,
10
+ Cleanup
11
+ end
12
+ end
@@ -1,3 +1,3 @@
1
1
  module Pulsar
2
- VERSION = '0.3.5'
2
+ VERSION = '1.0.0.pre'.freeze
3
3
  end
data/pulsar.gemspec CHANGED
@@ -6,8 +6,8 @@ require 'pulsar/version'
6
6
  Gem::Specification.new do |gem|
7
7
  gem.name = 'pulsar'
8
8
  gem.version = Pulsar::VERSION
9
- gem.authors = ['Alberto Vena', 'Matteo Latini']
10
- gem.email = ['info@nebulab.it']
9
+ gem.authors = ['Matteo Latini']
10
+ gem.email = ['matteolatini@nebulab.it']
11
11
  gem.homepage = 'http://pulsar.nebulab.it'
12
12
  gem.description = 'Manage your Capistrano deployments with ease'
13
13
  gem.summary = '
@@ -17,16 +17,18 @@ Gem::Specification.new do |gem|
17
17
  '
18
18
 
19
19
  gem.files = `git ls-files`.split($/)
20
- gem.executables = gem.files.grep(/^bin\//).map { |f| File.basename(f) }
21
- gem.test_files = gem.files.grep(/^(test|spec|features)\//)
20
+ gem.executables = gem.files.grep(%r{^bin\/}).map { |f| File.basename(f) }
21
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)\/})
22
22
  gem.require_paths = ['lib']
23
23
 
24
- gem.add_dependency 'clamp', '~> 0.5'
25
- gem.add_dependency 'bundler', '~> 1.2'
26
- gem.add_dependency 'colored', '~> 1.2'
24
+ gem.add_dependency 'bundler', '~> 1.8'
25
+ gem.add_dependency 'thor', '~> 0.19'
26
+ gem.add_dependency 'interactor', '~> 3.1'
27
+ gem.add_dependency 'dotenv', '~> 2.0'
27
28
 
28
- gem.add_development_dependency 'rake', '10.3.2'
29
- gem.add_development_dependency 'rspec', '3.1.0'
30
- gem.add_development_dependency 'codeclimate-test-reporter', '~> 0.4.6'
31
- gem.add_development_dependency 'rubocop', '~> 0.29.1'
29
+ gem.add_development_dependency 'rake', '~> 10.4'
30
+ gem.add_development_dependency 'rspec', '~> 3.2'
31
+ gem.add_development_dependency 'codeclimate-test-reporter', '~> 0.4'
32
+ gem.add_development_dependency 'rubocop', '~> 0.47'
33
+ gem.add_development_dependency 'timecop', '~> 0.8'
32
34
  end
@@ -0,0 +1,162 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe 'Deploy' do
4
+ subject { -> { command } }
5
+
6
+ let(:command) do
7
+ `DRY_RUN=true ruby #{RSpec.configuration.pulsar_command} deploy #{options} #{arguments}`
8
+ end
9
+
10
+ let(:repo) { RSpec.configuration.pulsar_conf_path }
11
+ let(:options) { "--conf-repo #{repo}" }
12
+ let(:arguments) { 'blog production' }
13
+
14
+ context 'via a subcommand named deploy' do
15
+ let(:error) { /Could not find command/ }
16
+
17
+ it { is_expected.not_to output(error).to_stderr_from_any_process }
18
+ end
19
+
20
+ context 'requires a --conf-repo option' do
21
+ let(:options) { nil }
22
+ let(:error) { /No value provided for required options '--conf-repo'/ }
23
+
24
+ it { is_expected.to output(error).to_stderr_from_any_process }
25
+
26
+ context 'can be specified via the alias -c' do
27
+ let(:options) { "-c #{repo}" }
28
+
29
+ it { is_expected.not_to output(error).to_stderr_from_any_process }
30
+ end
31
+
32
+ context 'can be specified via the environment variable PULSAR_CONF_REPO' do
33
+ before { ENV['PULSAR_CONF_REPO'] = repo }
34
+
35
+ it { is_expected.not_to output(error).to_stderr_from_any_process }
36
+ end
37
+ end
38
+
39
+ context 'requires application and environment arguments' do
40
+ let(:arguments) { nil }
41
+ let(:error) { /Usage: "pulsar deploy APPLICATION ENVIRONMENT"/ }
42
+
43
+ it { is_expected.to output(error).to_stderr_from_any_process }
44
+ end
45
+
46
+ context 'when succeeds' do
47
+ subject { command }
48
+
49
+ context 'deploys an application on a environment in the pulsar configuration' do
50
+ let(:output) { "Deployed blog on production!\n" }
51
+
52
+ context 'from a local folder' do
53
+ it { is_expected.to match(output) }
54
+
55
+ context 'leaves the tmp folder empty' do
56
+ subject { Dir.glob("#{Pulsar::PULSAR_TMP}/*") }
57
+
58
+ before { command }
59
+
60
+ it { is_expected.to be_empty }
61
+ end
62
+ end
63
+
64
+ context 'from a local repository' do
65
+ let(:repo) { RSpec.configuration.pulsar_local_conf_repo_path }
66
+
67
+ before do
68
+ FileUtils.cp_r(RSpec.configuration.pulsar_conf_path, repo)
69
+ `git init #{repo}`
70
+ end
71
+
72
+ context 'uncommitted changes' do
73
+ it { is_expected.not_to match(output) }
74
+
75
+ context 'leaves the tmp folder empty' do
76
+ subject { Dir.glob("#{Pulsar::PULSAR_TMP}/*") }
77
+
78
+ before { command }
79
+
80
+ it { is_expected.to be_empty }
81
+ end
82
+ end
83
+
84
+ context 'committed changes' do
85
+ before do
86
+ `git -C #{repo} add . && git -C #{repo} commit -m 'Initial Commit'`
87
+ end
88
+
89
+ it { is_expected.to match(output) }
90
+
91
+ context 'leaves the tmp folder empty' do
92
+ subject { Dir.glob("#{Pulsar::PULSAR_TMP}/*") }
93
+
94
+ before { command }
95
+
96
+ it { is_expected.to be_empty }
97
+ end
98
+ end
99
+ end
100
+
101
+ context 'from a remote Git repository' do
102
+ let(:repo) { RSpec.configuration.pulsar_remote_git_conf }
103
+ let(:arguments) { 'your_app staging' }
104
+ let(:output) { "Deployed your_app on staging!\n" }
105
+
106
+ it { is_expected.to match(output) }
107
+
108
+ context 'leaves the tmp folder empty' do
109
+ subject { Dir.glob("#{Pulsar::PULSAR_TMP}/*") }
110
+
111
+ before { command }
112
+
113
+ it { is_expected.to be_empty }
114
+ end
115
+ end
116
+
117
+ context 'from a remote GitHub repository' do
118
+ let(:repo) { RSpec.configuration.pulsar_remote_github_conf }
119
+ let(:arguments) { 'your_app staging' }
120
+ let(:output) { "Deployed your_app on staging!\n" }
121
+
122
+ it { is_expected.to match(output) }
123
+
124
+ context 'leaves the tmp folder empty' do
125
+ subject { Dir.glob("#{Pulsar::PULSAR_TMP}/*") }
126
+
127
+ before { command }
128
+
129
+ it { is_expected.to be_empty }
130
+ end
131
+ end
132
+ end
133
+ end
134
+
135
+ context 'when fails' do
136
+ subject { command }
137
+
138
+ context 'because of wrong directory' do
139
+ let(:repo) { './some-wrong-directory' }
140
+
141
+ it { is_expected.to match("Failed to deploy blog on production.\n") }
142
+ end
143
+
144
+ context 'because of empty directory' do
145
+ let(:repo) { RSpec.configuration.pulsar_empty_conf_path }
146
+
147
+ it { is_expected.to match("Failed to deploy blog on production.\n") }
148
+ end
149
+
150
+ context 'because Bundler failed' do
151
+ let(:repo) { RSpec.configuration.pulsar_wrong_bundle_conf_path }
152
+
153
+ it { is_expected.to match("Failed to deploy blog on production.\n") }
154
+ end
155
+
156
+ context 'because Capistrano failed' do
157
+ let(:repo) { RSpec.configuration.pulsar_wrong_cap_conf_path }
158
+
159
+ it { is_expected.to match("Failed to deploy blog on production.\n") }
160
+ end
161
+ end
162
+ end
@@ -0,0 +1,66 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe 'Install' do
4
+ subject { command }
5
+
6
+ let(:command) do
7
+ `ruby #{RSpec.configuration.pulsar_command} install #{arguments}`
8
+ end
9
+
10
+ let(:arguments) { nil }
11
+
12
+ context 'via a subcommand named install' do
13
+ subject { -> { command } }
14
+
15
+ let(:error) { /Could not find command/ }
16
+
17
+ it { is_expected.not_to output(error).to_stderr_from_any_process }
18
+ end
19
+
20
+ context 'when succeeds' do
21
+ it { is_expected.to eql "Successfully created intial repo!\n" }
22
+
23
+ context 'creates a directory' do
24
+ subject { -> { command } }
25
+
26
+ context 'with the basic configuration' do
27
+ subject(:initial_pulsar_repo) do
28
+ Dir.entries('./../../../lib/pulsar/generators/initial_repo/')
29
+ end
30
+
31
+ before { command }
32
+
33
+ it 'contains the initial directory structure' do
34
+ is_expected.to eql Dir.entries('./pulsar-conf')
35
+ end
36
+ end
37
+
38
+ context 'inside the current directory by default' do
39
+ it 'named pulsar-conf' do
40
+ is_expected
41
+ .to change { File.exist?('./pulsar-conf') }.from(false).to(true)
42
+ end
43
+ end
44
+
45
+ context 'inside a directory passed as argument' do
46
+ let(:arguments) { './my-dir' }
47
+
48
+ it 'named as the argument' do
49
+ is_expected.to change { File.exist?('./my-dir') }.from(false).to(true)
50
+ end
51
+ end
52
+ end
53
+ end
54
+
55
+ context 'when fails' do
56
+ let(:arguments) { '/pulsar-conf' }
57
+
58
+ it { is_expected.to eql "Failed to create intial repo.\n" }
59
+
60
+ context 'does not create a directory' do
61
+ subject { -> { command } }
62
+
63
+ it { is_expected.not_to change { File.exist?('./my-dir') }.from(false) }
64
+ end
65
+ end
66
+ end