mina 1.2.4 → 1.2.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +11 -3
  3. data/.gitignore +0 -1
  4. data/.rspec +1 -1
  5. data/.rubocop.yml +28 -1126
  6. data/CHANGELOG.md +89 -8
  7. data/Gemfile +2 -0
  8. data/Gemfile.lock +73 -0
  9. data/Rakefile +2 -0
  10. data/Readme.md +8 -12
  11. data/bin/mina +2 -0
  12. data/data/deploy.rb +6 -4
  13. data/docs/3rd_party_plugins.md +1 -0
  14. data/docs/assets/images/mina.png +0 -0
  15. data/docs/default_plugins.md +1 -1
  16. data/docs/how_mina_works.md +2 -2
  17. data/lib/Minafile +1 -0
  18. data/lib/mina/application.rb +45 -35
  19. data/lib/mina/backend/local.rb +2 -0
  20. data/lib/mina/backend/remote.rb +3 -1
  21. data/lib/mina/commands.rb +10 -7
  22. data/lib/mina/configuration.rb +6 -3
  23. data/lib/mina/dsl.rb +2 -2
  24. data/lib/mina/helpers/internal.rb +8 -8
  25. data/lib/mina/helpers/output.rb +5 -3
  26. data/lib/mina/runner/exec.rb +2 -0
  27. data/lib/mina/runner/pretty.rb +25 -19
  28. data/lib/mina/runner/printer.rb +2 -0
  29. data/lib/mina/runner/system.rb +2 -0
  30. data/lib/mina/runner.rb +9 -10
  31. data/lib/mina/version.rb +3 -1
  32. data/lib/mina/windows_patches.rb +4 -2
  33. data/lib/mina.rb +4 -3
  34. data/mina.gemspec +8 -7
  35. data/spec/configs/default.rb +8 -0
  36. data/spec/configs/dsl.rb +55 -0
  37. data/spec/configs/e2e.rb +25 -0
  38. data/spec/e2e/docker-compose.yml +21 -0
  39. data/spec/e2e/e2e_run.sh +11 -0
  40. data/spec/e2e/e2e_spec.rb +35 -0
  41. data/spec/e2e/ssh +27 -0
  42. data/spec/e2e/ssh.pub +1 -0
  43. data/spec/lib/mina/application_spec.rb +94 -35
  44. data/spec/lib/mina/backend/local_spec.rb +5 -2
  45. data/spec/lib/mina/backend/remote_spec.rb +5 -3
  46. data/spec/lib/mina/commands_spec.rb +7 -7
  47. data/spec/lib/mina/configuration_spec.rb +63 -3
  48. data/spec/lib/mina/dsl_spec.rb +94 -0
  49. data/spec/lib/mina/helpers/internal_spec.rb +88 -10
  50. data/spec/lib/mina/helpers/output_spec.rb +13 -10
  51. data/spec/lib/mina/runner/exec_spec.rb +19 -0
  52. data/spec/lib/mina/runner/pretty_spec.rb +17 -0
  53. data/spec/lib/mina/runner/printer_spec.rb +19 -0
  54. data/spec/lib/mina/runner/system_spec.rb +19 -0
  55. data/spec/lib/mina/runner_spec.rb +6 -10
  56. data/spec/spec_helper.rb +33 -14
  57. data/spec/support/outputs/bundle_clean.txt +2 -2
  58. data/spec/support/outputs/chruby_with_env.txt +7 -0
  59. data/spec/support/outputs/chruby_without_env.txt +2 -0
  60. data/spec/support/outputs/debug_configuration_variables.txt +11 -0
  61. data/spec/support/outputs/dsl_deploy.txt +4 -0
  62. data/spec/support/outputs/dsl_in_path.txt +1 -0
  63. data/spec/support/outputs/dsl_local_run.txt +5 -0
  64. data/spec/support/outputs/dsl_on.txt +6 -0
  65. data/spec/support/outputs/dsl_remote_run.txt +5 -0
  66. data/spec/support/outputs/dsl_reset.txt +2 -0
  67. data/spec/support/outputs/e2e_deploy_after_setup.txt +1 -0
  68. data/spec/support/outputs/e2e_deploy_without_setup.txt +1 -0
  69. data/spec/support/outputs/e2e_setup.txt +1 -0
  70. data/spec/support/outputs/environment.txt +1 -0
  71. data/spec/support/outputs/git_ensure_pushed.txt +15 -0
  72. data/spec/support/outputs/rails_assets_precompile_force_precompile.txt +2 -0
  73. data/spec/support/outputs/rails_assets_precompile_outside_deploy_block.txt +1 -0
  74. data/spec/support/outputs/rails_assets_precompile_with_diff.txt +7 -0
  75. data/spec/support/outputs/rails_console.txt +1 -0
  76. data/spec/support/outputs/rails_db_migrate_force_migrate.txt +2 -0
  77. data/spec/support/outputs/rails_db_migrate_outside_deploy_block.txt +1 -0
  78. data/spec/support/outputs/rails_db_migrate_with_diff.txt +7 -0
  79. data/spec/support/outputs/rails_log.txt +1 -0
  80. data/spec/support/outputs/rails_with_arguments.txt +1 -0
  81. data/spec/support/outputs/rails_without_arguments.txt +1 -0
  82. data/spec/support/outputs/rake_with_arguments.txt +1 -0
  83. data/spec/support/outputs/rake_without_arguments.txt +1 -0
  84. data/spec/support/outputs/rbenv_load.txt +9 -1
  85. data/spec/support/outputs/rvm_use_with_env.txt +8 -0
  86. data/spec/support/outputs/rvm_use_without_env.txt +2 -0
  87. data/spec/support/outputs/rvm_wrapper_with_arguments.txt +8 -0
  88. data/spec/support/outputs/rvm_wrapper_without_arguments.txt +2 -0
  89. data/spec/support/outputs/ry_with_env.txt +13 -0
  90. data/spec/support/outputs/ry_without_env.txt +13 -0
  91. data/spec/support/outputs/ssh.txt +1 -0
  92. data/spec/support/outputs/ssh_keyscan_domain.txt +3 -0
  93. data/spec/support/rake_example_group.rb +23 -19
  94. data/spec/tasks/bundler_spec.rb +6 -0
  95. data/spec/tasks/chruby_spec.rb +29 -0
  96. data/spec/tasks/default_spec.rb +79 -7
  97. data/spec/tasks/deploy_spec.rb +6 -0
  98. data/spec/tasks/git_spec.rb +12 -0
  99. data/spec/tasks/init_spec.rb +13 -4
  100. data/spec/tasks/rails_spec.rb +126 -15
  101. data/spec/tasks/rbenv_spec.rb +15 -0
  102. data/spec/tasks/rvm_spec.rb +51 -0
  103. data/spec/tasks/ry_spec.rb +43 -0
  104. data/tasks/mina/bundler.rb +7 -5
  105. data/tasks/mina/chruby.rb +7 -5
  106. data/tasks/mina/default.rb +19 -12
  107. data/tasks/mina/deploy.rb +26 -24
  108. data/tasks/mina/git.rb +28 -16
  109. data/tasks/mina/install.rb +3 -1
  110. data/tasks/mina/rails.rb +29 -27
  111. data/tasks/mina/rbenv.rb +8 -6
  112. data/tasks/mina/rvm.rb +13 -11
  113. data/tasks/mina/ry.rb +11 -11
  114. data/test_env/config/deploy.rb +9 -8
  115. metadata +64 -32
  116. data/spec/support/outputs/chruby.txt +0 -9
  117. data/spec/support/outputs/console.txt +0 -1
  118. data/spec/support/outputs/log.txt +0 -1
  119. data/spec/support/outputs/rails_db_migrate.txt +0 -1
  120. data/spec/support/outputs/rvm_use.txt +0 -1
  121. data/spec/support/outputs/ry.txt +0 -15
  122. data/spec/tasks/ruby_managers_spec.rb +0 -33
@@ -0,0 +1 @@
1
+ \(cd /path && echo Hello there && cd -\)
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env bash
2
+ # Executing the following:
3
+ #
4
+ echo "-----> I am a comment"
5
+ echo Hello there
@@ -0,0 +1,6 @@
1
+ # ============================
2
+ # === Start up server => \(in deployer\)
3
+ \(
4
+ cd ".*/deploy/current"
5
+ echo Hello there
6
+ \) &&
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env bash
2
+ # Executing the following via 'ssh localhost -p 22 -tt':
3
+ #
4
+ echo "-----> I am a comment"
5
+ echo Hello there
@@ -0,0 +1,2 @@
1
+ ^((?!echo Hello there).)*$
2
+ echo New command
@@ -0,0 +1 @@
1
+ (?m)Cloning the Git repository.*Done\. Deployed version 1
@@ -0,0 +1 @@
1
+ The directory '/app/releases' does not exist on the server\.
@@ -0,0 +1 @@
1
+ Setting up /app
@@ -0,0 +1 @@
1
+ environment is DEPRECATED! Please use local_environment and remote_environment
@@ -0,0 +1,15 @@
1
+ echo "-----> Ensuring everything is pushed to git"
2
+ if \[ \$\(git branch --list master \| wc -l\) -eq 0 \]; then
3
+ echo "! Branch master doesn't exist"
4
+ exit 1
5
+ fi
6
+
7
+ if \[ \$\(git branch -r --list origin/master \| wc -l\) -eq 0 \]; then
8
+ echo "! Branch origin/master doesn't exist"
9
+ exit 1
10
+ fi
11
+
12
+ if \[ \$\(git log origin/master..master \| wc -l\) -ne 0 \]; then
13
+ echo "! Your branch master needs to be pushed to origin before deploying"
14
+ exit 1
15
+ fi
@@ -0,0 +1,2 @@
1
+ echo "-----> Precompiling asset files"
2
+ RAILS_ENV="production" bundle exec rake assets:precompile
@@ -0,0 +1 @@
1
+ Can't be run outside deploy do block. Please use mina 'rake\[assets_precompile\]' instead
@@ -0,0 +1,7 @@
1
+ if diff -qrN ".*/deploy/current/vendor/assets/" "\./vendor/assets/" 2>/dev/null && diff -qrN ".*/deploy/current/app/assets/" "\./app/assets/" 2>/dev/null
2
+ then
3
+ echo "-----> Skipping asset precompilation"
4
+ else
5
+ echo "-----> Precompiling asset files"
6
+ RAILS_ENV="production" bundle exec rake assets:precompile
7
+ fi
@@ -0,0 +1 @@
1
+ \(cd .*/deploy/current && RAILS_ENV="production" bundle exec rails console && cd -\)
@@ -0,0 +1,2 @@
1
+ echo "-----> Migrating database"
2
+ RAILS_ENV="production" bundle exec rake db:migrate
@@ -0,0 +1 @@
1
+ Can't be run outside deploy do block\. Please use mina 'rake\[db_migrate\]' instead
@@ -0,0 +1,7 @@
1
+ if diff -qrN ".*/deploy/current/db/migrate" "\./db/migrate" 2>/dev/null
2
+ then
3
+ echo "-----> DB migrations unchanged; skipping DB migration"
4
+ else
5
+ echo "-----> Migrating database"
6
+ RAILS_ENV="production" bundle exec rake db:migrate
7
+ fi
@@ -0,0 +1 @@
1
+ \(cd .*/deploy/shared/log && tail -f production\.log && cd -\)
@@ -0,0 +1 @@
1
+ \(cd .*/deploy/current && RAILS_ENV="production" bundle exec rails db:rollback STEP=2 && cd -\)
@@ -0,0 +1 @@
1
+ You need to provide arguments. Try: mina "rails\[console\]"
@@ -0,0 +1 @@
1
+ \(cd .*/deploy/current && RAILS_ENV="production" bundle exec rake db:primary:migrate && cd -\)
@@ -0,0 +1 @@
1
+ You need to provide arguments. Try: mina "rake\[db:migrate\]"
@@ -1 +1,9 @@
1
- echo\ "\-\-\-\-\->\ Loading\ rbenv"\nexport\ RBENV_ROOT="\$HOME/\.rbenv"\nexport\ PATH="\$HOME/\.rbenv/bin:\$PATH"\s*if\ !\ which\ rbenv\ >/dev/null;\ then\s*echo\ "!\ rbenv\ not\ found"\s*echo\ "!\ If\ rbenv\ is\ installed,\ check\ your\ :rbenv_path\ setting\."\s*exit\ 1\s*fi\s*eval\ "\$\(rbenv\ init\ \-\)"
1
+ echo "-----> Loading rbenv"
2
+ export RBENV_ROOT="\$HOME/\.rbenv"
3
+ export PATH="\$HOME/\.rbenv/bin:\$PATH"
4
+ if ! which rbenv >/dev/null; then
5
+ echo "! rbenv not found"
6
+ echo "! If rbenv is installed, check your :rbenv_path setting\."
7
+ exit 1
8
+ fi
9
+ eval "\$\(rbenv init -\)"
@@ -0,0 +1,8 @@
1
+ echo "-----> Using RVM environment \\"3\.0\.0\\""
2
+ if \[\[ ! -s "\$HOME/\.rvm/scripts/rvm" \]\]; then
3
+ echo "! Ruby Version Manager not found"
4
+ echo "! If RVM is installed, check your :rvm_use_path setting\."
5
+ exit 1
6
+ fi
7
+ source \$HOME/\.rvm/scripts/rvm
8
+ rvm use "3\.0\.0" --create
@@ -0,0 +1,2 @@
1
+ Task 'rvm:use' needs an RVM environment name as an argument\.
2
+ Example: invoke :'rvm:use', 'ruby-1\.9\.2@default'
@@ -0,0 +1,8 @@
1
+ echo "-----> creating RVM wrapper "myapp_unicorn" using \\"3\.0\.0\\""
2
+ if \[\[ ! -s "\$HOME/\.rvm/scripts/rvm" \]\]; then
3
+ echo "! Ruby Version Manager not found"
4
+ echo "! If RVM is installed, check your :rvm_use_path setting\."
5
+ exit 1
6
+ fi
7
+ source \$HOME/\.rvm/scripts/rvm
8
+ rvm wrapper 3\.0\.0 myapp unicorn \|\| exit 1
@@ -0,0 +1,2 @@
1
+ Task 'rvm:wrapper' needs an RVM environment name, a wrapper name and the binary name as arguments
2
+ Example: invoke :'rvm:wrapper', 'ruby-1\.9\.2@myapp,myapp,unicorn_rails'
@@ -0,0 +1,13 @@
1
+ echo "-----> ry to version: \\\"3\.0\.0\\\""
2
+ echo "-----> Loading ry"
3
+ if \[\[ ! -e "\$HOME/\.local/bin" \]\]; then
4
+ echo "! ry not found"
5
+ echo "! If ry is installed, check your :ry_path setting."
6
+ exit 1
7
+ fi
8
+ export PATH="\$HOME/\.local/bin:\$PATH"
9
+ eval "\$\(ry setup\)"
10
+ RY_RUBY="3\.0\.0"
11
+ if \[ -n "\$RY_RUBY" \]; then
12
+ ry use \$RY_RUBY \|\| exit 1
13
+ fi
@@ -0,0 +1,13 @@
1
+ echo "-----> ry to version: \\"\*\*not specified\*\*\\""
2
+ echo "-----> Loading ry"
3
+ if \[\[ ! -e "\$HOME/\.local/bin" \]\]; then
4
+ echo "! ry not found"
5
+ echo "! If ry is installed, check your :ry_path setting."
6
+ exit 1
7
+ fi
8
+ export PATH="\$HOME/\.local/bin:\$PATH"
9
+ eval "\$\(ry setup\)"
10
+ RY_RUBY=""
11
+ if \[ -n "\$RY_RUBY" \]; then
12
+ ry use \$RY_RUBY \|\| exit 1
13
+ fi
@@ -0,0 +1 @@
1
+ cd .*/deploy && exec \$SHELL
@@ -0,0 +1,3 @@
1
+ if ! ssh-keygen -H -F localhost &>/dev/null; then
2
+ ssh-keyscan -p 22 localhost >> ~/.ssh/known_hosts
3
+ fi
@@ -1,25 +1,29 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RakeExampleGroup
2
- extend RSpec::Matchers::DSL
3
-
4
- def self.included(klass)
5
- klass.instance_eval do
6
- let(:rake) { Rake.application }
7
- let(:task_name) { self.class.description }
8
- let(:run_commands) { rake['run_commands']}
9
- let(:reset!) { rake['reset!'] }
10
- subject { rake[task_name] }
11
-
12
- after do
13
- subject.reenable
14
- run_commands.reenable
15
- reset!.invoke
16
- reset!.reenable
17
- end
18
- end
4
+ extend RSpec::SharedContext
5
+
6
+ subject(:task) { rake[task_name] }
7
+
8
+ let(:rake) { Rake.application }
9
+ let(:task_name) { self.class.description }
10
+ let(:run_commands) { rake['run_commands'] }
11
+ let(:reset!) { rake['reset!'] }
12
+
13
+ after do
14
+ reset!.invoke
15
+ end
16
+
17
+ def load_default_config
18
+ load_config 'default'
19
+ end
20
+
21
+ def load_config(config_name)
22
+ Rake.load_rakefile(Dir.pwd + "/spec/configs/#{config_name}.rb")
19
23
  end
20
24
 
21
- def invoke_all(args = nil)
22
- subject.invoke(args)
25
+ def invoke_all(*args)
26
+ task.invoke(*args)
23
27
  run_commands.invoke
24
28
  end
25
29
 
@@ -1,6 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  RSpec.describe 'bundler', type: :rake do
6
+ before do
7
+ load_default_config
8
+ end
9
+
4
10
  describe 'bundle:install' do
5
11
  it 'bundle install' do
6
12
  expect { invoke_all }.to output(output_file('bundle_install')).to_stdout
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe 'chruby', type: :rake do
6
+ before do
7
+ load_default_config
8
+ end
9
+
10
+ describe 'chruby' do
11
+ let(:task_name) { 'chruby' }
12
+
13
+ context 'without an argument' do
14
+ it 'exits with an error message' do
15
+ expect do
16
+ invoke_all
17
+ end.to raise_error(SystemExit).and output(output_file('chruby_without_env')).to_stdout
18
+ end
19
+ end
20
+
21
+ context 'with an argument' do
22
+ it 'sets ruby version' do
23
+ expect do
24
+ invoke_all('123')
25
+ end.to output(output_file('chruby_with_env')).to_stdout
26
+ end
27
+ end
28
+ end
29
+ end
@@ -1,6 +1,18 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  RSpec.describe 'default', type: :rake do
6
+ before do
7
+ load_default_config
8
+ end
9
+
10
+ describe 'environment' do
11
+ it 'outputs a deprecation warning' do
12
+ expect { invoke_all }.to output(output_file('environment')).to_stdout
13
+ end
14
+ end
15
+
4
16
  describe 'ssh_keyscan_repo' do
5
17
  it 'scans ssh' do
6
18
  Mina::Configuration.instance.set(:repository, 'git@github.com/exapmle')
@@ -8,29 +20,89 @@ RSpec.describe 'default', type: :rake do
8
20
  end
9
21
  end
10
22
 
23
+ describe 'ssh_keyscan_domain' do
24
+ let(:task_name) { 'ssh_keyscan_domain' }
25
+
26
+ context "when domain isn't set" do
27
+ before do
28
+ Mina::Configuration.instance.remove(:domain)
29
+ end
30
+
31
+ it 'exits with an error message' do
32
+ expect do
33
+ invoke_all
34
+ end.to raise_error(SystemExit)
35
+ .and output(/domain must be defined!/).to_stdout
36
+ end
37
+ end
38
+
39
+ context "when port isn't set" do
40
+ before do
41
+ Mina::Configuration.instance.remove(:port)
42
+ end
43
+
44
+ it 'exits with an error message' do
45
+ expect do
46
+ invoke_all
47
+ end.to raise_error(SystemExit)
48
+ .and output(/port must be defined!/).to_stdout
49
+ end
50
+ end
51
+
52
+ context 'when conditions are met' do
53
+ it 'scans ssh' do
54
+ expect do
55
+ invoke_all
56
+ end.to output(output_file('ssh_keyscan_domain')).to_stdout
57
+ end
58
+ end
59
+ end
60
+
11
61
  describe 'run' do
12
62
  it 'runs command' do
13
- subject.invoke('ls -al')
63
+ task.invoke('ls -al')
14
64
  expect { run_commands.invoke }.to output(output_file('run')).to_stdout
15
65
  end
16
66
 
17
67
  it 'exits if no command given' do
18
- expect { subject.invoke }.to raise_error(SystemExit)
68
+ expect { task.invoke }.to raise_error(SystemExit)
69
+ .and output(/You need to provide a command/).to_stdout
19
70
  end
20
71
  end
21
72
 
22
73
  describe 'ssh' do
23
- it 'runs ssh' do
24
- expect_any_instance_of(Kernel).to receive(:exec)
25
- subject.invoke
74
+ it 'opens an SSH connection when :deploy_to exists' do
75
+ expect do
76
+ invoke_all
77
+ end.to change { Mina::Configuration.instance.fetch(:execution_mode) }.to(:exec)
78
+ .and output(output_file('ssh')).to_stdout
79
+ end
80
+
81
+ it "exits with an error message when :deploy_to isn't set" do
82
+ Mina::Configuration.instance.remove(:deploy_to)
83
+
84
+ expect do
85
+ invoke_all
86
+ end.to raise_error(SystemExit)
87
+ .and output(/deploy_to must be defined!/).to_stdout
26
88
  end
27
89
  end
28
90
 
29
91
  describe 'debug_configuration_variables' do
30
- it 'prints configrtion variables' do
92
+ before do
31
93
  Mina::Configuration.instance.set(:debug_configuration_variables, true)
32
- expect { invoke_all }.to output(/------- Printing current config variables -------/).to_stdout
94
+ ENV['keep_releases'] = '1234'
95
+ end
96
+
97
+ after do
33
98
  Mina::Configuration.instance.remove(:debug_configuration_variables)
99
+ ENV.delete('keep_releases')
100
+ end
101
+
102
+ it 'prints configuration variables' do
103
+ expect do
104
+ invoke_all
105
+ end.to output(output_file('debug_configuration_variables')).to_stdout
34
106
  end
35
107
  end
36
108
  end
@@ -1,6 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  RSpec.describe 'deploy', type: :rake do
6
+ before do
7
+ load_default_config
8
+ end
9
+
4
10
  describe 'deploy:force_unlock' do
5
11
  it 'deploy force_unlock' do
6
12
  expect { invoke_all }.to output(output_file('deploy_force_unlock')).to_stdout
@@ -1,6 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  RSpec.describe 'git', type: :rake do
6
+ before do
7
+ load_default_config
8
+ end
9
+
4
10
  describe 'git:clone' do
5
11
  it 'git clone' do
6
12
  expect { invoke_all }.to output(output_file('git_clone')).to_stdout
@@ -18,4 +24,10 @@ RSpec.describe 'git', type: :rake do
18
24
  expect { invoke_all }.to output(output_file('git_revision')).to_stdout
19
25
  end
20
26
  end
27
+
28
+ describe 'git:ensure_pushed' do
29
+ it 'git ensure pushed' do
30
+ expect { invoke_all }.to output(output_file('git_ensure_pushed')).to_stdout
31
+ end
32
+ end
21
33
  end
@@ -1,16 +1,25 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  RSpec.describe 'init', type: :rake do
6
+ before do
7
+ load_default_config
8
+ end
9
+
4
10
  it 'creates new deploy rb' do
5
11
  allow(File).to receive(:exist?).and_return(true)
6
- expect(FileUtils).to receive(:mkdir_p)
7
- expect(FileUtils).to receive(:cp)
12
+ allow(File).to receive(:exist?).with('./config/deploy.rb').and_return(false)
13
+ allow(FileUtils).to receive(:mkdir_p).and_return(true)
14
+ allow(FileUtils).to receive(:cp).and_return(true)
8
15
 
9
- expect { subject.invoke }.to output("-----> Created ./config/deploy.rb\nEdit this file, then run `mina setup` after.\n").to_stdout
16
+ expect do
17
+ task.invoke
18
+ end.to output("-----> Created ./config/deploy.rb\nEdit this file, then run `mina setup` after.\n").to_stdout
10
19
  end
11
20
 
12
21
  it 'doesnt create deploy rb if already exists' do
13
22
  allow(File).to receive(:exist?).and_return(false)
14
- expect { subject.invoke }.to raise_error(SystemExit)
23
+ expect { task.invoke }.to raise_error(SystemExit).and output(/You already have/).to_stdout
15
24
  end
16
25
  end
@@ -1,23 +1,63 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  RSpec.describe 'rails', type: :rake do
6
+ before do
7
+ load_default_config
8
+ end
9
+
4
10
  describe 'console' do
5
11
  it 'starts console' do
6
- expect { invoke_all }.to output(output_file('console')).to_stdout
12
+ expect { invoke_all }.to output(output_file('rails_console')).to_stdout
7
13
  end
8
14
  end
9
15
 
10
16
  describe 'log' do
11
17
  it 'tails log' do
12
- expect { invoke_all }.to output(output_file('log')).to_stdout
18
+ expect { invoke_all }.to output(output_file('rails_log')).to_stdout
13
19
  end
14
20
  end
15
21
 
16
22
  describe 'rails:db_migrate' do
17
- it 'rails db migrate' do
18
- Mina::Configuration.instance.set(:deploy_block, true)
19
- expect { invoke_all }.to output(output_file('rails_db_migrate')).to_stdout
20
- Mina::Configuration.instance.set(:deploy_block, false)
23
+ let(:task_name) { 'rails:db_migrate' }
24
+
25
+ context 'when outside deploy block' do
26
+ before do
27
+ Mina::Configuration.instance.remove(:deploy_block)
28
+ end
29
+
30
+ it 'exits with an error message' do
31
+ expect do
32
+ invoke_all
33
+ end.to raise_error(SystemExit)
34
+ .and output(output_file('rails_db_migrate_outside_deploy_block')).to_stdout
35
+ end
36
+ end
37
+
38
+ context 'with force_migrate flag' do
39
+ before do
40
+ Mina::Configuration.instance.set(:force_migrate, true)
41
+ Mina::Configuration.instance.set(:deploy_block, true)
42
+ end
43
+
44
+ it 'runs rails db:migrate' do
45
+ expect do
46
+ invoke_all
47
+ end.to output(output_file('rails_db_migrate_force_migrate')).to_stdout
48
+ end
49
+ end
50
+
51
+ context 'without force_migrate flag' do
52
+ before do
53
+ Mina::Configuration.instance.set(:deploy_block, true)
54
+ end
55
+
56
+ it 'runs rails db:migrate but checks for changes first' do
57
+ expect do
58
+ invoke_all
59
+ end.to output(output_file('rails_db_migrate_with_diff')).to_stdout
60
+ end
21
61
  end
22
62
  end
23
63
 
@@ -34,10 +74,44 @@ RSpec.describe 'rails', type: :rake do
34
74
  end
35
75
 
36
76
  describe 'rails:assets_precompile' do
37
- it 'rails assets precompile' do
38
- Mina::Configuration.instance.set(:deploy_block, true)
39
- expect { invoke_all }.to output(output_file('rails_assets_precompile')).to_stdout
40
- Mina::Configuration.instance.set(:deploy_block, false)
77
+ let(:task_name) { 'rails:assets_precompile' }
78
+
79
+ context 'when outside deploy block' do
80
+ before do
81
+ Mina::Configuration.instance.remove(:deploy_block)
82
+ end
83
+
84
+ it 'exits with an error message' do
85
+ expect do
86
+ invoke_all
87
+ end.to raise_error(SystemExit)
88
+ .and output(output_file('rails_assets_precompile_outside_deploy_block')).to_stdout
89
+ end
90
+ end
91
+
92
+ context 'with force_asset_precompile flag' do
93
+ before do
94
+ Mina::Configuration.instance.set(:force_asset_precompile, true)
95
+ Mina::Configuration.instance.set(:deploy_block, true)
96
+ end
97
+
98
+ it 'runs rails assets:precompile' do
99
+ expect do
100
+ invoke_all
101
+ end.to output(output_file('rails_assets_precompile_force_precompile')).to_stdout
102
+ end
103
+ end
104
+
105
+ context 'without force_asset_precompile flag' do
106
+ before do
107
+ Mina::Configuration.instance.set(:deploy_block, true)
108
+ end
109
+
110
+ it 'runs rails assets:precompile but checks for changes first' do
111
+ expect do
112
+ invoke_all
113
+ end.to output(output_file('rails_assets_precompile_with_diff')).to_stdout
114
+ end
41
115
  end
42
116
  end
43
117
 
@@ -52,9 +126,46 @@ RSpec.describe 'rails', type: :rake do
52
126
  expect { invoke_all }.to output(output_file('rails_db_schema_load')).to_stdout
53
127
  end
54
128
  end
55
- # describe 'rollback' do
56
- # it 'rollback' do
57
- # expect { invoke_all }.to output(output_file('rollback')).to_stdout
58
- # end
59
- # end
129
+
130
+ describe 'rails' do
131
+ let(:task_name) { 'rails' }
132
+
133
+ context 'without arguments' do
134
+ it 'exits with an error message' do
135
+ expect do
136
+ invoke_all
137
+ end.to raise_error(SystemExit)
138
+ .and output(output_file('rails_without_arguments')).to_stdout
139
+ end
140
+ end
141
+
142
+ context 'with arguments' do
143
+ it 'executes the arguments' do
144
+ expect do
145
+ invoke_all('db:rollback STEP=2')
146
+ end.to output(output_file('rails_with_arguments')).to_stdout
147
+ end
148
+ end
149
+ end
150
+
151
+ describe 'rake' do
152
+ let(:task_name) { 'rake' }
153
+
154
+ context 'without arguments' do
155
+ it 'exits with an error message' do
156
+ expect do
157
+ invoke_all
158
+ end.to raise_error(SystemExit)
159
+ .and output(output_file('rake_without_arguments')).to_stdout
160
+ end
161
+ end
162
+
163
+ context 'with arguments' do
164
+ it 'executes the arguments' do
165
+ expect do
166
+ invoke_all('db:primary:migrate')
167
+ end.to output(output_file('rake_with_arguments')).to_stdout
168
+ end
169
+ end
170
+ end
60
171
  end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe 'rbenv', type: :rake do
6
+ before do
7
+ load_default_config
8
+ end
9
+
10
+ describe 'rbenv:load' do
11
+ it 'loads rbenv' do
12
+ expect { invoke_all }.to output(output_file('rbenv_load')).to_stdout
13
+ end
14
+ end
15
+ end