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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rspec +1 -0
- data/.rubocop.yml +150 -0
- data/.ruby-version +1 -1
- data/LICENSE.txt +1 -1
- data/README.md +4 -265
- data/bin/pulsar +1 -1
- data/circle.yml +22 -0
- data/lib/pulsar.rb +28 -7
- data/lib/pulsar/cli.rb +79 -0
- data/lib/pulsar/constants.rb +5 -0
- data/lib/pulsar/generators/initial_repo/Gemfile +3 -0
- data/lib/pulsar/generators/{init_repo → initial_repo}/README.md +1 -1
- data/lib/pulsar/generators/initial_repo/apps/Capfile +8 -0
- data/lib/pulsar/generators/initial_repo/apps/deploy.rb +35 -0
- data/lib/pulsar/generators/initial_repo/apps/your_app/Capfile +18 -0
- data/lib/pulsar/generators/initial_repo/apps/your_app/deploy.rb +4 -0
- data/lib/pulsar/generators/initial_repo/apps/your_app/production.rb +3 -0
- data/lib/pulsar/generators/initial_repo/apps/your_app/staging.rb +3 -0
- data/lib/pulsar/generators/initial_repo/recipes/generic/rake.rake +12 -0
- data/lib/pulsar/generators/{init_repo/apps/your_app/recipes/production → initial_repo/recipes/rails}/.gitkeep +0 -0
- data/lib/pulsar/interactors/add_applications.rb +48 -0
- data/lib/pulsar/interactors/cleanup.rb +9 -0
- data/lib/pulsar/interactors/clone_repository.rb +50 -0
- data/lib/pulsar/interactors/copy_environment_file.rb +30 -0
- data/lib/pulsar/interactors/copy_initial_repository.rb +22 -0
- data/lib/pulsar/interactors/create_capfile.rb +32 -0
- data/lib/pulsar/interactors/create_deploy_file.rb +32 -0
- data/lib/pulsar/interactors/create_run_dirs.rb +21 -0
- data/lib/pulsar/interactors/identify_repository_location.rb +23 -0
- data/lib/pulsar/interactors/identify_repository_type.rb +34 -0
- data/lib/pulsar/interactors/run_bundle_install.rb +28 -0
- data/lib/pulsar/interactors/run_capistrano.rb +30 -0
- data/lib/pulsar/organizers/deploy.rb +16 -0
- data/lib/pulsar/organizers/install.rb +7 -0
- data/lib/pulsar/organizers/list.rb +12 -0
- data/lib/pulsar/version.rb +1 -1
- data/pulsar.gemspec +13 -11
- data/spec/features/deploy_spec.rb +162 -0
- data/spec/features/install_spec.rb +66 -0
- data/spec/features/list_spec.rb +140 -0
- data/spec/spec_helper.rb +26 -14
- data/{lib/pulsar/generators/init_repo/apps/your_app/recipes/staging → spec/support/dummies}/.gitkeep +0 -0
- data/spec/support/dummies/conf/dir/Gemfile +3 -0
- data/spec/support/dummies/conf/dir/apps/Capfile +9 -0
- data/spec/support/dummies/conf/dir/apps/blog/Capfile +1 -0
- data/spec/support/dummies/conf/dir/apps/blog/deploy.rb +4 -0
- data/spec/support/dummies/conf/dir/apps/blog/production.rb +4 -0
- data/spec/support/dummies/conf/dir/apps/blog/staging.rb +4 -0
- data/spec/support/dummies/conf/dir/apps/deploy.rb +1 -0
- data/{lib/pulsar/generators/init_repo/recipes/rails/.gitkeep → spec/support/dummies/conf/dir/apps/ecommerce/staging.rb} +0 -0
- data/spec/support/dummies/conf/dir/recipes/.gitkeep +0 -0
- data/spec/support/dummies/conf/dotenv +1 -0
- data/spec/support/dummies/conf/empty/apps/.gitkeep +0 -0
- data/spec/support/dummies/conf/empty/recipes/.gitkeep +0 -0
- data/spec/support/dummies/conf/wrong_bundle/Gemfile +3 -0
- data/spec/support/dummies/conf/wrong_bundle/apps/Capfile +9 -0
- data/spec/support/dummies/conf/wrong_bundle/apps/blog/Capfile +1 -0
- data/spec/support/dummies/conf/wrong_bundle/apps/blog/deploy.rb +4 -0
- data/spec/support/dummies/conf/wrong_bundle/apps/blog/production.rb +4 -0
- data/spec/support/dummies/conf/wrong_bundle/apps/deploy.rb +1 -0
- data/spec/support/dummies/conf/wrong_bundle/recipes/.gitkeep +0 -0
- data/spec/support/dummies/conf/wrong_cap/Gemfile +3 -0
- data/spec/support/dummies/conf/wrong_cap/apps/Capfile +0 -0
- data/spec/support/dummies/conf/wrong_cap/apps/blog/deploy.rb +4 -0
- data/spec/support/dummies/conf/wrong_cap/apps/blog/production.rb +4 -0
- data/spec/support/dummies/conf/wrong_cap/apps/deploy.rb +1 -0
- data/spec/support/dummies/conf/wrong_cap/recipes/.gitkeep +0 -0
- data/spec/units/cli/deploy_spec.rb +116 -0
- data/spec/units/cli/install_spec.rb +44 -0
- data/spec/units/cli/list_spec.rb +107 -0
- data/spec/units/constants_spec.rb +21 -0
- data/spec/units/interactors/add_applications_spec.rb +46 -0
- data/spec/units/interactors/cleanup_spec.rb +21 -0
- data/spec/units/interactors/clone_initial_repository_spec.rb +41 -0
- data/spec/units/interactors/clone_repository_spec.rb +122 -0
- data/spec/units/interactors/copy_environment_file_spec.rb +80 -0
- data/spec/units/interactors/create_capfile_spec.rb +77 -0
- data/spec/units/interactors/create_deploy_file_spec.rb +70 -0
- data/spec/units/interactors/create_run_dirs_spec.rb +47 -0
- data/spec/units/interactors/identify_repository_location_spec.rb +49 -0
- data/spec/units/interactors/identify_repository_type_spec.rb +85 -0
- data/spec/units/interactors/run_bundle_install_spec.rb +60 -0
- data/spec/units/interactors/run_capistrano_spec.rb +92 -0
- data/spec/units/organizers/deploy_spec.rb +28 -0
- data/spec/units/organizers/install_spec.rb +13 -0
- data/spec/units/organizers/list_spec.rb +24 -0
- metadata +179 -106
- data/.ruby-gemset +0 -1
- data/.travis.yml +0 -17
- data/bin/pulsar-utils +0 -5
- data/lib/pulsar/commands/all.rb +0 -6
- data/lib/pulsar/commands/init.rb +0 -23
- data/lib/pulsar/commands/list.rb +0 -19
- data/lib/pulsar/commands/main.rb +0 -64
- data/lib/pulsar/commands/utils.rb +0 -14
- data/lib/pulsar/generators/init_repo/Gemfile +0 -7
- data/lib/pulsar/generators/init_repo/apps/base.rb +0 -41
- data/lib/pulsar/generators/init_repo/apps/your_app/defaults.rb +0 -9
- data/lib/pulsar/generators/init_repo/apps/your_app/production.rb +0 -12
- data/lib/pulsar/generators/init_repo/apps/your_app/recipes/custom_recipe.rb +0 -14
- data/lib/pulsar/generators/init_repo/apps/your_app/staging.rb +0 -12
- data/lib/pulsar/generators/init_repo/recipes/generic/cleanup.rb +0 -50
- data/lib/pulsar/generators/init_repo/recipes/generic/utils.rb +0 -9
- data/lib/pulsar/helpers/all.rb +0 -8
- data/lib/pulsar/helpers/capistrano.rb +0 -47
- data/lib/pulsar/helpers/clamp.rb +0 -223
- data/lib/pulsar/helpers/path.rb +0 -71
- data/lib/pulsar/helpers/shell.rb +0 -31
- data/lib/pulsar/options/all.rb +0 -6
- data/lib/pulsar/options/conf_repo.rb +0 -41
- data/lib/pulsar/options/shared.rb +0 -15
- data/spec/pulsar/commands/init_spec.rb +0 -10
- data/spec/pulsar/commands/list_spec.rb +0 -127
- data/spec/pulsar/commands/main_spec.rb +0 -360
- data/spec/pulsar/commands/utils_spec.rb +0 -33
- data/spec/pulsar/helpers/capistrano_spec.rb +0 -70
- data/spec/pulsar/helpers/clamp_spec.rb +0 -105
- data/spec/pulsar/helpers/shell_spec.rb +0 -11
- data/spec/support/dummies/dummy_app/config.ru +0 -3
- data/spec/support/dummies/dummy_conf/Gemfile +0 -4
- data/spec/support/dummies/dummy_conf/apps/base.rb +0 -46
- data/spec/support/dummies/dummy_conf/apps/dummy_app/custom_stage.rb +0 -5
- data/spec/support/dummies/dummy_conf/apps/dummy_app/defaults.rb +0 -7
- data/spec/support/dummies/dummy_conf/apps/dummy_app/production.rb +0 -5
- data/spec/support/dummies/dummy_conf/apps/dummy_app/recipes/custom_recipe.rb +0 -1
- data/spec/support/dummies/dummy_conf/apps/dummy_app/recipes/production/custom_recipe.rb +0 -1
- data/spec/support/dummies/dummy_conf/apps/dummy_app/recipes/staging/custom_recipe.rb +0 -1
- data/spec/support/dummies/dummy_conf/apps/dummy_app/staging.rb +0 -5
- data/spec/support/dummies/dummy_conf/apps/other_dummy_app/custom_stage.rb +0 -5
- data/spec/support/dummies/dummy_conf/apps/other_dummy_app/defaults.rb +0 -7
- data/spec/support/dummies/dummy_conf/apps/other_dummy_app/production.rb +0 -5
- data/spec/support/dummies/dummy_conf/apps/other_dummy_app/staging.rb +0 -5
- data/spec/support/dummies/dummy_conf/recipes/generic/recipe.rb +0 -3
- data/spec/support/modules/helpers.rb +0 -85
- data/spec/support/modules/output_capture.rb +0 -21
@@ -0,0 +1,107 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Pulsar::CLI do
|
4
|
+
subject { Pulsar::List }
|
5
|
+
|
6
|
+
let(:described_instance) { described_class.new }
|
7
|
+
let(:fail_text) { /Failed to list application and environments./ }
|
8
|
+
|
9
|
+
context '#list' do
|
10
|
+
let(:result) { spy }
|
11
|
+
let(:repo) { './conf_repo' }
|
12
|
+
|
13
|
+
before do
|
14
|
+
allow($stdout).to receive(:puts)
|
15
|
+
allow(Pulsar::List).to receive(:call).and_return(result)
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'when using --conf-repo' do
|
19
|
+
before do
|
20
|
+
allow(described_instance)
|
21
|
+
.to receive(:options).and_return(conf_repo: repo)
|
22
|
+
described_instance.list
|
23
|
+
end
|
24
|
+
|
25
|
+
it { is_expected.to have_received(:call).with(repository: repo) }
|
26
|
+
|
27
|
+
context 'success' do
|
28
|
+
subject { -> { described_instance.list } }
|
29
|
+
|
30
|
+
let(:applications) { 'blog: staging' }
|
31
|
+
let(:result) { spy(success?: true, applications: applications) }
|
32
|
+
|
33
|
+
it { is_expected.to output(/#{applications}/).to_stdout }
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'failure' do
|
37
|
+
subject { -> { described_instance.list } }
|
38
|
+
|
39
|
+
let(:result) { spy(success?: false) }
|
40
|
+
|
41
|
+
it { is_expected.to output(fail_text).to_stdout }
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'when using configuration file' do
|
46
|
+
before do
|
47
|
+
allow(described_instance).to receive(:options).and_return({})
|
48
|
+
described_instance.list
|
49
|
+
end
|
50
|
+
|
51
|
+
around do |example|
|
52
|
+
old_const = Pulsar::PULSAR_CONF
|
53
|
+
Pulsar.send(:remove_const, 'PULSAR_CONF')
|
54
|
+
Pulsar::PULSAR_CONF = RSpec.configuration.pulsar_dotenv_conf_path
|
55
|
+
example.run
|
56
|
+
Pulsar.send(:remove_const, 'PULSAR_CONF')
|
57
|
+
Pulsar::PULSAR_CONF = old_const
|
58
|
+
end
|
59
|
+
|
60
|
+
it { is_expected.to have_received(:call).with(repository: repo) }
|
61
|
+
|
62
|
+
context 'success' do
|
63
|
+
subject { -> { described_instance.list } }
|
64
|
+
|
65
|
+
let(:applications) { 'blog: staging' }
|
66
|
+
let(:result) { spy(success?: true, applications: applications) }
|
67
|
+
|
68
|
+
it { is_expected.to output(/#{applications}/).to_stdout }
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'failure' do
|
72
|
+
subject { -> { described_instance.list } }
|
73
|
+
|
74
|
+
let(:result) { spy(success?: false) }
|
75
|
+
|
76
|
+
it { is_expected.to output(fail_text).to_stdout }
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context 'when using PULSAR_CONF_REPO' do
|
81
|
+
before do
|
82
|
+
allow(described_instance).to receive(:options).and_return({})
|
83
|
+
ENV['PULSAR_CONF_REPO'] = repo
|
84
|
+
described_instance.list
|
85
|
+
end
|
86
|
+
|
87
|
+
it { is_expected.to have_received(:call).with(repository: repo) }
|
88
|
+
|
89
|
+
context 'success' do
|
90
|
+
subject { -> { described_instance.list } }
|
91
|
+
|
92
|
+
let(:applications) { 'blog: staging' }
|
93
|
+
let(:result) { spy(success?: true, applications: applications) }
|
94
|
+
|
95
|
+
it { is_expected.to output(/#{applications}/).to_stdout }
|
96
|
+
end
|
97
|
+
|
98
|
+
context 'failure' do
|
99
|
+
subject { -> { described_instance.list } }
|
100
|
+
|
101
|
+
let(:result) { spy(success?: false) }
|
102
|
+
|
103
|
+
it { is_expected.to output(fail_text).to_stdout }
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe 'Pulsar Constants' do
|
4
|
+
context Pulsar::PULSAR_HOME do
|
5
|
+
subject { Pulsar::PULSAR_HOME }
|
6
|
+
|
7
|
+
it { is_expected.to eql File.expand_path('~/.pulsar') }
|
8
|
+
end
|
9
|
+
|
10
|
+
context Pulsar::PULSAR_TMP do
|
11
|
+
subject { Pulsar::PULSAR_TMP }
|
12
|
+
|
13
|
+
it { is_expected.to eql "#{Pulsar::PULSAR_HOME}/tmp" }
|
14
|
+
end
|
15
|
+
|
16
|
+
context Pulsar::PULSAR_CONF do
|
17
|
+
subject { Pulsar::PULSAR_CONF }
|
18
|
+
|
19
|
+
it { is_expected.to eql "#{Pulsar::PULSAR_HOME}/config" }
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Pulsar::AddApplications do
|
4
|
+
subject { described_class.new }
|
5
|
+
|
6
|
+
it { is_expected.to be_kind_of(Interactor) }
|
7
|
+
|
8
|
+
describe '.call' do
|
9
|
+
subject { described_class.call(config_path: './my-conf') }
|
10
|
+
|
11
|
+
before do
|
12
|
+
allow(Dir).to receive(:[])
|
13
|
+
.and_return(%w(./blog/), %w(Capfile deploy.rb production.rb staging.rb))
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'success' do
|
17
|
+
it { is_expected.to be_a_success }
|
18
|
+
|
19
|
+
context 'returns a list of applications and stages' do
|
20
|
+
subject { described_class.call(config_path: './my-conf').applications }
|
21
|
+
|
22
|
+
it { is_expected.to eql(['blog: production, staging']) }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'failure' do
|
27
|
+
context 'when no config_path context is passed' do
|
28
|
+
subject { described_class.call }
|
29
|
+
|
30
|
+
it { is_expected.to be_a_failure }
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'when an exception is triggered' do
|
34
|
+
before { allow(Dir).to receive(:[]).and_raise(RuntimeError) }
|
35
|
+
|
36
|
+
it { is_expected.to be_a_failure }
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'when there are no applications' do
|
40
|
+
before { allow(Dir).to receive(:[]).and_return([]) }
|
41
|
+
|
42
|
+
it { is_expected.to be_a_failure }
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Pulsar::Cleanup do
|
4
|
+
subject { described_class.new }
|
5
|
+
|
6
|
+
it { is_expected.to be_kind_of(Interactor) }
|
7
|
+
|
8
|
+
describe '.call' do
|
9
|
+
subject { FileUtils }
|
10
|
+
|
11
|
+
let(:run_path) { './some-path' }
|
12
|
+
|
13
|
+
before do
|
14
|
+
allow(subject).to receive(:rm_rf)
|
15
|
+
|
16
|
+
described_class.call(run_path: run_path)
|
17
|
+
end
|
18
|
+
|
19
|
+
it { is_expected.to have_received(:rm_rf).with(run_path) }
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Pulsar::CopyInitialRepository do
|
4
|
+
subject { described_class.new }
|
5
|
+
|
6
|
+
it { is_expected.to be_kind_of(Interactor) }
|
7
|
+
|
8
|
+
describe '.call' do
|
9
|
+
subject { described_class.call(directory: './pulsar-conf') }
|
10
|
+
|
11
|
+
let(:initial_repo) { './../../../lib/pulsar/generators/initial_repo/' }
|
12
|
+
|
13
|
+
context 'success' do
|
14
|
+
before { allow(FileUtils).to receive(:cp_r) }
|
15
|
+
|
16
|
+
it { is_expected.to be_a_success }
|
17
|
+
|
18
|
+
it 'copies a template directory to destination' do
|
19
|
+
subject
|
20
|
+
|
21
|
+
expect(FileUtils)
|
22
|
+
.to have_received(:cp_r)
|
23
|
+
.with(File.expand_path(initial_repo), subject.directory)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'failure' do
|
28
|
+
context 'when no directory context is passed' do
|
29
|
+
subject { described_class.call }
|
30
|
+
|
31
|
+
it { is_expected.to be_a_failure }
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'when an exception is triggered' do
|
35
|
+
before { allow(FileUtils).to receive(:cp_r).and_raise(RuntimeError) }
|
36
|
+
|
37
|
+
it { is_expected.to be_a_failure }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Pulsar::CloneRepository do
|
4
|
+
subject { described_class.new }
|
5
|
+
|
6
|
+
it { is_expected.to be_kind_of(Interactor) }
|
7
|
+
|
8
|
+
describe '.call' do
|
9
|
+
subject do
|
10
|
+
described_class.call(
|
11
|
+
config_path: run_path,
|
12
|
+
repository: repo,
|
13
|
+
repository_type: type
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
let(:repo) { './my-conf' }
|
18
|
+
let(:run_path) { "#{Pulsar::PULSAR_TMP}/run-#{Time.now.to_f}/conf" }
|
19
|
+
|
20
|
+
context 'success' do
|
21
|
+
context 'when repository_type is :folder' do
|
22
|
+
let(:type) { :folder }
|
23
|
+
|
24
|
+
before do
|
25
|
+
expect(FileUtils).to receive(:cp_r).with("#{repo}/.", run_path).ordered
|
26
|
+
end
|
27
|
+
|
28
|
+
it { is_expected.to be_a_success }
|
29
|
+
|
30
|
+
context 'returns a config_path path' do
|
31
|
+
subject do
|
32
|
+
described_class
|
33
|
+
.call(config_path: run_path, repository: repo, repository_type: type)
|
34
|
+
.config_path
|
35
|
+
end
|
36
|
+
|
37
|
+
it { is_expected.to match run_path }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'when repository_type is a :git' do
|
42
|
+
let(:type) { :git }
|
43
|
+
|
44
|
+
before do
|
45
|
+
expect(Rake).to receive(:sh)
|
46
|
+
.with(/git clone --quiet --depth 1 #{repo} #{run_path}/).ordered
|
47
|
+
end
|
48
|
+
|
49
|
+
it { is_expected.to be_a_success }
|
50
|
+
|
51
|
+
context 'returns a config_path path' do
|
52
|
+
subject do
|
53
|
+
described_class
|
54
|
+
.call(config_path: run_path, repository: repo, repository_type: type)
|
55
|
+
.config_path
|
56
|
+
end
|
57
|
+
|
58
|
+
it { is_expected.to match run_path }
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context 'when repository_type is a :github' do
|
63
|
+
let(:type) { :github }
|
64
|
+
let(:repo) { 'github-account/my-conf' }
|
65
|
+
|
66
|
+
let(:github_regex) do
|
67
|
+
/git clone --quiet --depth 1 git@github.com:#{repo}.git #{run_path}/
|
68
|
+
end
|
69
|
+
|
70
|
+
before do
|
71
|
+
expect(Rake).to receive(:sh).with(github_regex).ordered
|
72
|
+
end
|
73
|
+
|
74
|
+
it { is_expected.to be_a_success }
|
75
|
+
|
76
|
+
context 'returns a config_path path' do
|
77
|
+
subject do
|
78
|
+
described_class
|
79
|
+
.call(config_path: run_path, repository: repo, repository_type: type)
|
80
|
+
.config_path
|
81
|
+
end
|
82
|
+
|
83
|
+
it { is_expected.to match run_path }
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context 'failure' do
|
89
|
+
context 'when no config_path context is passed' do
|
90
|
+
subject do
|
91
|
+
described_class.call(repository: './some-path', repository_type: :something)
|
92
|
+
end
|
93
|
+
|
94
|
+
it { is_expected.to be_a_failure }
|
95
|
+
end
|
96
|
+
|
97
|
+
context 'when no repository context is passed' do
|
98
|
+
subject do
|
99
|
+
described_class.call(config_path: './some-path', repository_type: :something)
|
100
|
+
end
|
101
|
+
|
102
|
+
it { is_expected.to be_a_failure }
|
103
|
+
end
|
104
|
+
|
105
|
+
context 'when no repository_type context is passed' do
|
106
|
+
subject do
|
107
|
+
described_class.call(config_path: './some-path', repository: './some-path')
|
108
|
+
end
|
109
|
+
|
110
|
+
it { is_expected.to be_a_failure }
|
111
|
+
end
|
112
|
+
|
113
|
+
context 'when an exception is triggered' do
|
114
|
+
let(:type) { :folder }
|
115
|
+
|
116
|
+
before { allow(FileUtils).to receive(:cp_r).and_raise(RuntimeError) }
|
117
|
+
|
118
|
+
it { is_expected.to be_a_failure }
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Pulsar::CopyEnvironmentFile do
|
4
|
+
subject { described_class.new }
|
5
|
+
|
6
|
+
it { is_expected.to be_kind_of(Interactor) }
|
7
|
+
|
8
|
+
describe '.call' do
|
9
|
+
subject { command }
|
10
|
+
|
11
|
+
let(:command) { described_class.call(args) }
|
12
|
+
let(:cap_path) { "#{Pulsar::PULSAR_TMP}/cap-path" }
|
13
|
+
let(:args) do
|
14
|
+
{
|
15
|
+
config_path: RSpec.configuration.pulsar_conf_path,
|
16
|
+
cap_path: cap_path, application: 'blog', environment: 'production'
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'success' do
|
21
|
+
it { is_expected.to be_a_success }
|
22
|
+
|
23
|
+
context 'creates a Capfile' do
|
24
|
+
subject { File }
|
25
|
+
|
26
|
+
it { is_expected.to exist(command.environment_file_path) }
|
27
|
+
|
28
|
+
context 'with the required Capistrano path' do
|
29
|
+
subject { command.environment_file_path }
|
30
|
+
|
31
|
+
it { is_expected.to eql "#{cap_path}/config/deploy/production.rb" }
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'with contents combined from pulsar configuration repo' do
|
35
|
+
subject { File.read(command.environment_file_path) }
|
36
|
+
|
37
|
+
it { is_expected.to match(/# Production config/) }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'failure' do
|
43
|
+
context 'when no config_path context is passed' do
|
44
|
+
subject { described_class.call }
|
45
|
+
|
46
|
+
it { is_expected.to be_a_failure }
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'when no application context is passed' do
|
50
|
+
subject { described_class.call(config_path: './my-conf') }
|
51
|
+
|
52
|
+
it { is_expected.to be_a_failure }
|
53
|
+
end
|
54
|
+
|
55
|
+
context 'when no cap_path context is passed' do
|
56
|
+
subject do
|
57
|
+
described_class.call(config_path: './my-conf', application: 'blog')
|
58
|
+
end
|
59
|
+
|
60
|
+
it { is_expected.to be_a_failure }
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'when no environment context is passed' do
|
64
|
+
subject do
|
65
|
+
described_class.call(
|
66
|
+
cap_path: './some-path', config_path: './my-conf', application: 'blog'
|
67
|
+
)
|
68
|
+
end
|
69
|
+
|
70
|
+
it { is_expected.to be_a_failure }
|
71
|
+
end
|
72
|
+
|
73
|
+
context 'when an exception is triggered' do
|
74
|
+
before { allow(FileUtils).to receive(:mkdir_p).and_raise(RuntimeError) }
|
75
|
+
|
76
|
+
it { is_expected.to be_a_failure }
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|