capistrano 2.1.0 → 3.0.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.
Files changed (166) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +20 -0
  3. data/.travis.yml +7 -0
  4. data/CHANGELOG.md +89 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +674 -0
  7. data/README.md +226 -0
  8. data/Rakefile +5 -0
  9. data/bin/cap +2 -3
  10. data/bin/capify +7 -77
  11. data/capistrano-public_cert.pem +22 -0
  12. data/capistrano.gemspec +35 -0
  13. data/features/deploy.feature +52 -0
  14. data/features/installation.feature +16 -0
  15. data/features/remote_file_task.feature +14 -0
  16. data/features/step_definitions/assertions.rb +90 -0
  17. data/features/step_definitions/cap_commands.rb +8 -0
  18. data/features/step_definitions/setup.rb +25 -0
  19. data/features/support/env.rb +12 -0
  20. data/features/support/remote_command_helpers.rb +20 -0
  21. data/lib/Capfile +3 -0
  22. data/lib/capistrano/all.rb +16 -0
  23. data/lib/capistrano/application.rb +60 -0
  24. data/lib/capistrano/configuration/question.rb +42 -0
  25. data/lib/capistrano/configuration/server.rb +133 -0
  26. data/lib/capistrano/configuration/servers/role_filter.rb +86 -0
  27. data/lib/capistrano/configuration/servers.rb +53 -58
  28. data/lib/capistrano/configuration.rb +84 -30
  29. data/lib/capistrano/console.rb +1 -0
  30. data/lib/capistrano/defaults.rb +13 -0
  31. data/lib/capistrano/deploy.rb +3 -0
  32. data/lib/capistrano/dotfile.rb +3 -0
  33. data/lib/capistrano/dsl/env.rb +64 -0
  34. data/lib/capistrano/dsl/paths.rb +94 -0
  35. data/lib/capistrano/dsl/stages.rb +15 -0
  36. data/lib/capistrano/dsl/task_enhancements.rb +53 -0
  37. data/lib/capistrano/dsl.rb +48 -0
  38. data/lib/capistrano/git.rb +1 -0
  39. data/lib/capistrano/hg.rb +1 -0
  40. data/lib/capistrano/i18n.rb +34 -0
  41. data/lib/capistrano/install.rb +1 -0
  42. data/lib/capistrano/setup.rb +21 -0
  43. data/lib/capistrano/tasks/console.rake +21 -0
  44. data/lib/capistrano/tasks/deploy.rake +204 -0
  45. data/lib/capistrano/tasks/framework.rake +67 -0
  46. data/lib/capistrano/tasks/git.rake +62 -0
  47. data/lib/capistrano/tasks/hg.rake +39 -0
  48. data/lib/capistrano/tasks/install.rake +39 -0
  49. data/lib/capistrano/templates/Capfile +26 -0
  50. data/lib/capistrano/templates/deploy.rb.erb +40 -0
  51. data/lib/capistrano/templates/stage.rb.erb +42 -0
  52. data/lib/capistrano/version.rb +1 -20
  53. data/lib/capistrano/version_validator.rb +37 -0
  54. data/lib/capistrano.rb +0 -2
  55. data/spec/integration/dsl_spec.rb +344 -0
  56. data/spec/integration_spec_helper.rb +7 -0
  57. data/spec/lib/capistrano/application_spec.rb +61 -0
  58. data/spec/lib/capistrano/configuration/question_spec.rb +54 -0
  59. data/spec/lib/capistrano/configuration/server_spec.rb +249 -0
  60. data/spec/lib/capistrano/configuration/servers/role_filter_spec.rb +140 -0
  61. data/spec/lib/capistrano/configuration/servers_spec.rb +184 -0
  62. data/spec/lib/capistrano/configuration_spec.rb +101 -0
  63. data/spec/lib/capistrano/dsl/env_spec.rb +10 -0
  64. data/spec/lib/capistrano/dsl/paths_spec.rb +69 -0
  65. data/spec/lib/capistrano/dsl_spec.rb +63 -0
  66. data/spec/lib/capistrano/version_validator_spec.rb +103 -0
  67. data/spec/lib/capistrano_spec.rb +8 -0
  68. data/spec/spec_helper.rb +15 -0
  69. data/spec/support/.gitignore +1 -0
  70. data/spec/support/Vagrantfile +13 -0
  71. data/spec/support/matchers.rb +5 -0
  72. data/spec/support/tasks/database.cap +11 -0
  73. data/spec/support/test_app.rb +138 -0
  74. metadata +251 -179
  75. data/CHANGELOG +0 -512
  76. data/MIT-LICENSE +0 -20
  77. data/README +0 -43
  78. data/examples/sample.rb +0 -14
  79. data/lib/capistrano/callback.rb +0 -45
  80. data/lib/capistrano/cli/execute.rb +0 -82
  81. data/lib/capistrano/cli/help.rb +0 -102
  82. data/lib/capistrano/cli/help.txt +0 -53
  83. data/lib/capistrano/cli/options.rb +0 -183
  84. data/lib/capistrano/cli/ui.rb +0 -28
  85. data/lib/capistrano/cli.rb +0 -47
  86. data/lib/capistrano/command.rb +0 -161
  87. data/lib/capistrano/configuration/actions/file_transfer.rb +0 -35
  88. data/lib/capistrano/configuration/actions/inspect.rb +0 -46
  89. data/lib/capistrano/configuration/actions/invocation.rb +0 -134
  90. data/lib/capistrano/configuration/callbacks.rb +0 -148
  91. data/lib/capistrano/configuration/connections.rb +0 -159
  92. data/lib/capistrano/configuration/execution.rb +0 -126
  93. data/lib/capistrano/configuration/loading.rb +0 -198
  94. data/lib/capistrano/configuration/namespaces.rb +0 -196
  95. data/lib/capistrano/configuration/roles.rb +0 -51
  96. data/lib/capistrano/configuration/variables.rb +0 -127
  97. data/lib/capistrano/errors.rb +0 -15
  98. data/lib/capistrano/extensions.rb +0 -57
  99. data/lib/capistrano/gateway.rb +0 -131
  100. data/lib/capistrano/logger.rb +0 -59
  101. data/lib/capistrano/recipes/compat.rb +0 -32
  102. data/lib/capistrano/recipes/deploy/dependencies.rb +0 -44
  103. data/lib/capistrano/recipes/deploy/local_dependency.rb +0 -46
  104. data/lib/capistrano/recipes/deploy/remote_dependency.rb +0 -96
  105. data/lib/capistrano/recipes/deploy/scm/accurev.rb +0 -169
  106. data/lib/capistrano/recipes/deploy/scm/base.rb +0 -192
  107. data/lib/capistrano/recipes/deploy/scm/bzr.rb +0 -86
  108. data/lib/capistrano/recipes/deploy/scm/cvs.rb +0 -151
  109. data/lib/capistrano/recipes/deploy/scm/darcs.rb +0 -85
  110. data/lib/capistrano/recipes/deploy/scm/git.rb +0 -191
  111. data/lib/capistrano/recipes/deploy/scm/mercurial.rb +0 -129
  112. data/lib/capistrano/recipes/deploy/scm/perforce.rb +0 -126
  113. data/lib/capistrano/recipes/deploy/scm/subversion.rb +0 -114
  114. data/lib/capistrano/recipes/deploy/scm.rb +0 -19
  115. data/lib/capistrano/recipes/deploy/strategy/base.rb +0 -64
  116. data/lib/capistrano/recipes/deploy/strategy/checkout.rb +0 -20
  117. data/lib/capistrano/recipes/deploy/strategy/copy.rb +0 -144
  118. data/lib/capistrano/recipes/deploy/strategy/export.rb +0 -20
  119. data/lib/capistrano/recipes/deploy/strategy/remote.rb +0 -52
  120. data/lib/capistrano/recipes/deploy/strategy/remote_cache.rb +0 -47
  121. data/lib/capistrano/recipes/deploy/strategy.rb +0 -19
  122. data/lib/capistrano/recipes/deploy/templates/maintenance.rhtml +0 -53
  123. data/lib/capistrano/recipes/deploy.rb +0 -494
  124. data/lib/capistrano/recipes/standard.rb +0 -37
  125. data/lib/capistrano/recipes/templates/maintenance.rhtml +0 -53
  126. data/lib/capistrano/recipes/upgrade.rb +0 -33
  127. data/lib/capistrano/server_definition.rb +0 -51
  128. data/lib/capistrano/shell.rb +0 -256
  129. data/lib/capistrano/ssh.rb +0 -109
  130. data/lib/capistrano/task_definition.rb +0 -69
  131. data/lib/capistrano/upload.rb +0 -146
  132. data/test/cli/execute_test.rb +0 -132
  133. data/test/cli/help_test.rb +0 -139
  134. data/test/cli/options_test.rb +0 -226
  135. data/test/cli/ui_test.rb +0 -28
  136. data/test/cli_test.rb +0 -17
  137. data/test/command_test.rb +0 -309
  138. data/test/configuration/actions/file_transfer_test.rb +0 -40
  139. data/test/configuration/actions/inspect_test.rb +0 -62
  140. data/test/configuration/actions/invocation_test.rb +0 -202
  141. data/test/configuration/callbacks_test.rb +0 -206
  142. data/test/configuration/connections_test.rb +0 -288
  143. data/test/configuration/execution_test.rb +0 -159
  144. data/test/configuration/loading_test.rb +0 -127
  145. data/test/configuration/namespace_dsl_test.rb +0 -297
  146. data/test/configuration/roles_test.rb +0 -47
  147. data/test/configuration/servers_test.rb +0 -90
  148. data/test/configuration/variables_test.rb +0 -180
  149. data/test/configuration_test.rb +0 -81
  150. data/test/deploy/scm/accurev_test.rb +0 -23
  151. data/test/deploy/scm/base_test.rb +0 -55
  152. data/test/deploy/scm/git_test.rb +0 -112
  153. data/test/deploy/strategy/copy_test.rb +0 -147
  154. data/test/extensions_test.rb +0 -69
  155. data/test/fixtures/cli_integration.rb +0 -5
  156. data/test/fixtures/config.rb +0 -5
  157. data/test/fixtures/custom.rb +0 -3
  158. data/test/gateway_test.rb +0 -167
  159. data/test/logger_test.rb +0 -123
  160. data/test/server_definition_test.rb +0 -108
  161. data/test/shell_test.rb +0 -64
  162. data/test/ssh_test.rb +0 -97
  163. data/test/task_definition_test.rb +0 -101
  164. data/test/upload_test.rb +0 -131
  165. data/test/utils.rb +0 -42
  166. data/test/version_test.rb +0 -24
@@ -0,0 +1,39 @@
1
+ require 'erb'
2
+ require 'pathname'
3
+ desc 'Install Capistrano, cap install STAGES=staging,production'
4
+ task :install do
5
+ envs = ENV['STAGES'] || 'staging,production'
6
+
7
+ tasks_dir = Pathname.new('lib/capistrano/tasks')
8
+ config_dir = Pathname.new('config')
9
+ deploy_dir = config_dir.join('deploy')
10
+
11
+ deploy_rb = File.expand_path("../../templates/deploy.rb.erb", __FILE__)
12
+ stage_rb = File.expand_path("../../templates/stage.rb.erb", __FILE__)
13
+ capfile = File.expand_path("../../templates/Capfile", __FILE__)
14
+
15
+ mkdir_p deploy_dir
16
+
17
+ template = File.read(deploy_rb)
18
+ file = config_dir.join('deploy.rb')
19
+ File.open(file, 'w+') do |f|
20
+ f.write(ERB.new(template).result(binding))
21
+ puts I18n.t(:written_file, scope: :capistrano, file: file)
22
+ end
23
+
24
+ template = File.read(stage_rb)
25
+ envs.split(',').each do |stage|
26
+ file = deploy_dir.join("#{stage}.rb")
27
+ File.open(file, 'w+') do |f|
28
+ f.write(ERB.new(template).result(binding))
29
+ puts I18n.t(:written_file, scope: :capistrano, file: file)
30
+ end
31
+ end
32
+
33
+ mkdir_p tasks_dir
34
+
35
+ FileUtils.cp(capfile, 'Capfile')
36
+
37
+
38
+ puts I18n.t :capified, scope: :capistrano
39
+ end
@@ -0,0 +1,26 @@
1
+ # Load DSL and Setup Up Stages
2
+ require 'capistrano/setup'
3
+
4
+ # Includes default deployment tasks
5
+ require 'capistrano/deploy'
6
+
7
+ # Includes tasks from other gems included in your Gemfile
8
+ #
9
+ # For documentation on these, see for example:
10
+ #
11
+ # https://github.com/capistrano/rvm
12
+ # https://github.com/capistrano/rbenv
13
+ # https://github.com/capistrano/chruby
14
+ # https://github.com/capistrano/bundler
15
+ # https://github.com/capistrano/rails/tree/master/assets
16
+ # https://github.com/capistrano/rails/tree/master/migrations
17
+ #
18
+ # require 'capistrano/rvm'
19
+ # require 'capistrano/rbenv'
20
+ # require 'capistrano/chruby'
21
+ # require 'capistrano/bundler'
22
+ # require 'capistrano/rails/assets'
23
+ # require 'capistrano/rails/migrations'
24
+
25
+ # Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
26
+ Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }
@@ -0,0 +1,40 @@
1
+ set :application, 'my app name'
2
+ set :repo_url, 'git@example.com:me/my_repo.git'
3
+
4
+ # ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }
5
+
6
+ # set :deploy_to, '/var/www/my_app'
7
+ # set :scm, :git
8
+
9
+ # set :format, :pretty
10
+ # set :log_level, :debug
11
+ # set :pty, true
12
+
13
+ # set :linked_files, %w{config/database.yml}
14
+ # set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
15
+
16
+ # set :default_env, { path: "/opt/ruby/bin:$PATH" }
17
+ # set :keep_releases, 5
18
+
19
+ namespace :deploy do
20
+
21
+ desc 'Restart application'
22
+ task :restart do
23
+ on roles(:app), in: :sequence, wait: 5 do
24
+ # Your restart mechanism here, for example:
25
+ # execute :touch, release_path.join('tmp/restart.txt')
26
+ end
27
+ end
28
+
29
+ after :restart, :clear_cache do
30
+ on roles(:web), in: :groups, limit: 3, wait: 10 do
31
+ # Here we can do anything such as:
32
+ # within release_path do
33
+ # execute :rake, 'cache:clear'
34
+ # end
35
+ end
36
+ end
37
+
38
+ after :finishing, 'deploy:cleanup'
39
+
40
+ end
@@ -0,0 +1,42 @@
1
+ set :stage, :<%= stage %>
2
+
3
+ # Simple Role Syntax
4
+ # ==================
5
+ # Supports bulk-adding hosts to roles, the primary
6
+ # server in each group is considered to be the first
7
+ # unless any hosts have the primary property set.
8
+ role :app, %w{deploy@example.com}
9
+ role :web, %w{deploy@example.com}
10
+ role :db, %w{deploy@example.com}
11
+
12
+ # Extended Server Syntax
13
+ # ======================
14
+ # This can be used to drop a more detailed server
15
+ # definition into the server list. The second argument
16
+ # something that quacks like a has can be used to set
17
+ # extended properties on the server.
18
+ server 'example.com', user: 'deploy', roles: %w{web app}, my_property: :my_value
19
+
20
+ # you can set custom ssh options
21
+ # it's possible to pass any option but you need to keep in mind that net/ssh understand limited list of options
22
+ # you can see them in [net/ssh documentation](http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start)
23
+ # set it globally
24
+ # set :ssh_options, {
25
+ # keys: %w(/home/rlisowski/.ssh/id_rsa),
26
+ # forward_agent: false,
27
+ # auth_methods: %w(password)
28
+ # }
29
+ # and/or per server
30
+ # server 'example.com',
31
+ # user: 'user_name',
32
+ # roles: %w{web app},
33
+ # ssh_options: {
34
+ # user: 'user_name', # overrides user setting above
35
+ # keys: %w(/home/user_name/.ssh/id_rsa),
36
+ # forward_agent: false,
37
+ # auth_methods: %w(publickey password)
38
+ # # password: 'please use keys'
39
+ # }
40
+ # setting per server overrides global ssh_options
41
+
42
+ # fetch(:default_env).merge!(rails_env: :<%= stage %>)
@@ -1,22 +1,3 @@
1
1
  module Capistrano
2
- module Version #:nodoc:
3
- # A method for comparing versions of required modules. It expects two
4
- # arrays of integers as parameters, the first being the minimum version
5
- # required, and the second being the actual version available. It returns
6
- # true if the actual version is at least equal to the required version.
7
- def self.check(required, actual) #:nodoc:
8
- required = required.map { |v| "%06d" % v }.join(".")
9
- actual = actual.map { |v| "%06d" % v }.join(".")
10
- return actual >= required
11
- end
12
-
13
- MAJOR = 2
14
- MINOR = 1
15
- TINY = 0
16
-
17
- STRING = [MAJOR, MINOR, TINY].join(".")
18
-
19
- SSH_REQUIRED = [1,0,10]
20
- SFTP_REQUIRED = [1,1,0]
21
- end
2
+ VERSION = "3.0.0"
22
3
  end
@@ -0,0 +1,37 @@
1
+ module Capistrano
2
+ class VersionValidator
3
+
4
+ def initialize(version)
5
+ @version = version
6
+ end
7
+
8
+ def verify
9
+ if match?
10
+ self
11
+ else
12
+ fail "Capfile locked at #{version}, but #{current_version} is loaded"
13
+ end
14
+ end
15
+
16
+ private
17
+ attr_reader :version
18
+
19
+
20
+ def match?
21
+ available =~ requested
22
+ end
23
+
24
+ def current_version
25
+ VERSION
26
+ end
27
+
28
+ def available
29
+ Gem::Dependency.new('cap', version)
30
+ end
31
+
32
+ def requested
33
+ Gem::Dependency.new('cap', current_version)
34
+ end
35
+
36
+ end
37
+ end
data/lib/capistrano.rb CHANGED
@@ -1,2 +0,0 @@
1
- require 'capistrano/configuration'
2
- require 'capistrano/extensions'
@@ -0,0 +1,344 @@
1
+ require 'spec_helper'
2
+
3
+ describe Capistrano::DSL do
4
+
5
+ let(:dsl) { Class.new.extend Capistrano::DSL }
6
+
7
+ describe 'setting and fetching hosts' do
8
+ describe 'when defining a host using the `server` syntax' do
9
+ before do
10
+ dsl.server 'example1.com', roles: %w{web}, active: true
11
+ dsl.server 'example2.com', roles: %w{web}
12
+ dsl.server 'example3.com', roles: %w{app web}, active: true
13
+ dsl.server 'example4.com', roles: %w{app}, primary: true
14
+ end
15
+
16
+ describe 'fetching all servers' do
17
+ subject { dsl.roles(:all) }
18
+
19
+ it 'returns all servers' do
20
+ expect(subject.map(&:hostname)).to eq %w{example1.com example2.com example3.com example4.com}
21
+ end
22
+ end
23
+
24
+ describe 'fetching servers by multiple roles' do
25
+ it "does not confuse the last role with options" do
26
+ expect(dsl.roles(:app, :web).count).to eq 4
27
+ expect(dsl.roles(:app, :web, filter: :active).count).to eq 2
28
+ end
29
+ end
30
+
31
+ describe 'fetching servers by role' do
32
+ subject { dsl.roles(:app) }
33
+
34
+ it 'returns the servers' do
35
+ expect(subject.map(&:hostname)).to eq %w{example3.com example4.com}
36
+ end
37
+ end
38
+
39
+ describe 'fetching filtered servers by role' do
40
+ subject { dsl.roles(:app, filter: :active) }
41
+
42
+ it 'returns the servers' do
43
+ expect(subject.map(&:hostname)).to eq %w{example3.com}
44
+ end
45
+ end
46
+
47
+ describe 'fetching selected servers by role' do
48
+ subject { dsl.roles(:app, select: :active) }
49
+
50
+ it 'returns the servers' do
51
+ expect(subject.map(&:hostname)).to eq %w{example3.com}
52
+ end
53
+ end
54
+
55
+ describe 'fetching the primary server by role' do
56
+ context 'when inferring primary status based on order' do
57
+ subject { dsl.primary(:web) }
58
+ it 'returns the servers' do
59
+ expect(subject.hostname).to eq 'example1.com'
60
+ end
61
+ end
62
+
63
+ context 'when the attribute `primary` is explicity set' do
64
+ subject { dsl.primary(:app) }
65
+ it 'returns the servers' do
66
+ expect(subject.hostname).to eq 'example4.com'
67
+ end
68
+ end
69
+ end
70
+
71
+ end
72
+
73
+ describe 'when defining hosts using the `role` syntax' do
74
+ before do
75
+ dsl.role :web, %w{example1.com example2.com example3.com}
76
+ dsl.role :web, %w{example1.com}, active: true
77
+ dsl.role :app, %w{example3.com example4.com}
78
+ dsl.role :app, %w{example3.com}, active: true
79
+ dsl.role :app, %w{example4.com}, primary: true
80
+ end
81
+
82
+ describe 'fetching all servers' do
83
+ subject { dsl.roles(:all) }
84
+
85
+ it 'returns all servers' do
86
+ expect(subject.map(&:hostname)).to eq %w{example1.com example2.com example3.com example4.com}
87
+ end
88
+ end
89
+
90
+ describe 'fetching servers by role' do
91
+ subject { dsl.roles(:app) }
92
+
93
+ it 'returns the servers' do
94
+ expect(subject.map(&:hostname)).to eq %w{example3.com example4.com}
95
+ end
96
+ end
97
+
98
+ describe 'fetching filtered servers by role' do
99
+ subject { dsl.roles(:app, filter: :active) }
100
+
101
+ it 'returns the servers' do
102
+ expect(subject.map(&:hostname)).to eq %w{example3.com}
103
+ end
104
+ end
105
+
106
+ describe 'fetching selected servers by role' do
107
+ subject { dsl.roles(:app, select: :active) }
108
+
109
+ it 'returns the servers' do
110
+ expect(subject.map(&:hostname)).to eq %w{example3.com}
111
+ end
112
+ end
113
+
114
+ describe 'fetching the primary server by role' do
115
+ context 'when inferring primary status based on order' do
116
+ subject { dsl.primary(:web) }
117
+ it 'returns the servers' do
118
+ expect(subject.hostname).to eq 'example1.com'
119
+ end
120
+ end
121
+
122
+ context 'when the attribute `primary` is explicity set' do
123
+ subject { dsl.primary(:app) }
124
+ it 'returns the servers' do
125
+ expect(subject.hostname).to eq 'example4.com'
126
+ end
127
+ end
128
+ end
129
+
130
+ end
131
+
132
+ end
133
+
134
+ describe 'setting and fetching variables' do
135
+
136
+ before do
137
+ dsl.set :scm, :git
138
+ end
139
+
140
+ context 'without a default' do
141
+ context 'when the variables is defined' do
142
+ it 'returns the variable' do
143
+ expect(dsl.fetch(:scm)).to eq :git
144
+ end
145
+ end
146
+
147
+ context 'when the variables is undefined' do
148
+ it 'returns nil' do
149
+ expect(dsl.fetch(:source_control)).to be_nil
150
+ end
151
+ end
152
+ end
153
+
154
+ context 'with a default' do
155
+ context 'when the variables is defined' do
156
+ it 'returns the variable' do
157
+ expect(dsl.fetch(:scm, :svn)).to eq :git
158
+ end
159
+ end
160
+
161
+ context 'when the variables is undefined' do
162
+ it 'returns the default' do
163
+ expect(dsl.fetch(:source_control, :svn)).to eq :svn
164
+ end
165
+ end
166
+ end
167
+
168
+ context 'with a block' do
169
+ context 'when the variables is defined' do
170
+ it 'returns the variable' do
171
+ expect(dsl.fetch(:scm) { :svn }).to eq :git
172
+ end
173
+ end
174
+
175
+ context 'when the variables is undefined' do
176
+ it 'calls the block' do
177
+ expect(dsl.fetch(:source_control) { :svn }).to eq :svn
178
+ end
179
+ end
180
+ end
181
+
182
+ end
183
+
184
+ describe 'asking for a variable' do
185
+ before do
186
+ dsl.ask(:scm, :svn)
187
+ $stdout.stubs(:puts)
188
+ end
189
+
190
+ context 'variable is provided' do
191
+ before do
192
+ $stdin.expects(:gets).returns('git')
193
+ end
194
+
195
+ it 'sets the input as the variable' do
196
+ expect(dsl.fetch(:scm)).to eq 'git'
197
+ end
198
+ end
199
+
200
+ context 'variable is not provided' do
201
+ before do
202
+ $stdin.expects(:gets).returns('')
203
+ end
204
+
205
+ it 'sets the variable as the default' do
206
+ expect(dsl.fetch(:scm)).to eq :svn
207
+ end
208
+ end
209
+ end
210
+
211
+ describe 'checking for presence' do
212
+ subject { dsl.any? :linked_files }
213
+
214
+ before do
215
+ dsl.set(:linked_files, linked_files)
216
+ end
217
+
218
+ context 'variable is an non-empty array' do
219
+ let(:linked_files) { %w{1} }
220
+
221
+ it { should be_true }
222
+ end
223
+
224
+ context 'variable is an empty array' do
225
+ let(:linked_files) { [] }
226
+ it { should be_false }
227
+ end
228
+
229
+ context 'variable exists, is not an array' do
230
+ let(:linked_files) { stub }
231
+ it { should be_true }
232
+ end
233
+
234
+ context 'variable is nil' do
235
+ let(:linked_files) { nil }
236
+ it { should be_false }
237
+ end
238
+ end
239
+
240
+ describe 'configuration SSHKit' do
241
+ let(:config) { SSHKit.config }
242
+ let(:backend) { SSHKit.config.backend.config }
243
+ let(:default_env) { { rails_env: :production } }
244
+
245
+ before do
246
+ dsl.set(:format, :dot)
247
+ dsl.set(:log_level, :debug)
248
+ dsl.set(:default_env, default_env)
249
+ dsl.set(:pty, true)
250
+ dsl.set(:connection_timeout, 10)
251
+ dsl.set(:ssh_options, {
252
+ keys: %w(/home/user/.ssh/id_rsa),
253
+ forward_agent: false,
254
+ auth_methods: %w(publickey password)
255
+ })
256
+ dsl.configure_backend
257
+ end
258
+
259
+ it 'sets the output' do
260
+ expect(config.output).to be_a SSHKit::Formatter::Dot
261
+ end
262
+
263
+ it 'sets the output verbosity' do
264
+ expect(config.output_verbosity).to eq 0
265
+ end
266
+
267
+ it 'sets the default env' do
268
+ expect(config.default_env).to eq default_env
269
+ end
270
+
271
+ it 'sets the backend pty' do
272
+ expect(backend.pty).to be_true
273
+ end
274
+
275
+ it 'sets the backend connection timeout' do
276
+ expect(backend.connection_timeout).to eq 10
277
+ end
278
+
279
+ it 'sets the backend ssh_options' do
280
+ expect(backend.ssh_options[:keys]).to eq %w(/home/user/.ssh/id_rsa)
281
+ expect(backend.ssh_options[:forward_agent]).to eq false
282
+ expect(backend.ssh_options[:auth_methods]).to eq %w(publickey password)
283
+ end
284
+
285
+ end
286
+
287
+ describe 'release path' do
288
+
289
+ before do
290
+ dsl.set(:deploy_to, '/var/www')
291
+ end
292
+
293
+ describe 'fetching release path' do
294
+ subject { dsl.release_path }
295
+
296
+ context 'where no release path has been set' do
297
+ before do
298
+ dsl.delete(:release_path)
299
+ end
300
+
301
+ it 'returns the `current_path` value' do
302
+ expect(subject.to_s).to eq '/var/www/current'
303
+ end
304
+ end
305
+
306
+ context 'where the release path has been set' do
307
+ before do
308
+ dsl.set(:release_path, '/var/www/release_path')
309
+ end
310
+
311
+ it 'returns the set `release_path` value' do
312
+ expect(subject.to_s).to eq '/var/www/release_path'
313
+ end
314
+ end
315
+ end
316
+
317
+ describe 'setting release path' do
318
+ let(:now) { Time.parse("Oct 21 16:29:00 2015") }
319
+ subject { dsl.release_path }
320
+
321
+ context 'without a timestamp' do
322
+ before do
323
+ dsl.env.expects(:timestamp).returns(now)
324
+ dsl.set_release_path
325
+ end
326
+
327
+ it 'returns the release path with the current env timestamp' do
328
+ expect(subject.to_s).to eq '/var/www/releases/20151021162900'
329
+ end
330
+ end
331
+
332
+ context 'with a timestamp' do
333
+ before do
334
+ dsl.set_release_path('timestamp')
335
+ end
336
+
337
+ it 'returns the release path with the timestamp' do
338
+ expect(subject.to_s).to eq '/var/www/releases/timestamp'
339
+ end
340
+ end
341
+ end
342
+
343
+ end
344
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+ require 'support/test_app'
3
+ require 'support/matchers'
4
+
5
+ include TestApp
6
+
7
+
@@ -0,0 +1,61 @@
1
+ require 'spec_helper'
2
+
3
+ describe Capistrano::Application do
4
+
5
+ it "provides a --trace option which enables SSHKit/NetSSH trace output"
6
+
7
+ it "provides a --format option which enables the choice of output formatting"
8
+
9
+ it "identifies itself as cap and not rake" do
10
+ pending "Waiting for: https://github.com/jimweirich/rake/pull/204"
11
+ out, _ = capture_io do
12
+ flags '--help', '-h'
13
+ end
14
+ out.should match(/\bcap [ -f capfile ]\b/)
15
+ end
16
+
17
+ it "overrides the rake method, but still prints the rake version" do
18
+ out, _ = capture_io do
19
+ flags '--version', '-V'
20
+ end
21
+ out.should match(/\bCapistrano Version\b/)
22
+ out.should match(/\b#{Capistrano::VERSION}\b/)
23
+ out.should match(/\bRake Version\b/)
24
+ out.should match(/\b#{RAKEVERSION}\b/)
25
+ end
26
+
27
+ def flags(*sets)
28
+ sets.each do |set|
29
+ ARGV.clear
30
+ @exit = catch(:system_exit) { command_line(*set) }
31
+ end
32
+ yield(subject.options) if block_given?
33
+ end
34
+
35
+ def command_line(*options)
36
+ options.each { |opt| ARGV << opt }
37
+ def subject.exit(*args)
38
+ throw(:system_exit, :exit)
39
+ end
40
+ subject.instance_eval do
41
+ handle_options
42
+ end
43
+ subject.options
44
+ end
45
+
46
+ def capture_io
47
+ require 'stringio'
48
+
49
+ orig_stdout, orig_stderr = $stdout, $stderr
50
+ captured_stdout, captured_stderr = StringIO.new, StringIO.new
51
+ $stdout, $stderr = captured_stdout, captured_stderr
52
+
53
+ yield
54
+
55
+ return captured_stdout.string, captured_stderr.string
56
+ ensure
57
+ $stdout = orig_stdout
58
+ $stderr = orig_stderr
59
+ end
60
+
61
+ end
@@ -0,0 +1,54 @@
1
+ require 'spec_helper'
2
+
3
+ module Capistrano
4
+ class Configuration
5
+
6
+ describe Question do
7
+
8
+ let(:question) { Question.new(env, key, default) }
9
+ let(:default) { :default }
10
+ let(:key) { :branch }
11
+ let(:env) { stub }
12
+
13
+ describe '.new' do
14
+ it 'takes a key, default' do
15
+ question
16
+ end
17
+ end
18
+
19
+ describe '#call' do
20
+ subject { question.call }
21
+
22
+ context 'value is entered' do
23
+ let(:branch) { 'branch' }
24
+
25
+ before do
26
+ $stdout.expects(:puts).with('Please enter branch: |default|')
27
+ $stdin.expects(:gets).returns(branch)
28
+ end
29
+
30
+ it 'sets the value' do
31
+ env.expects(:set).with(key, branch)
32
+ question.call
33
+ end
34
+ end
35
+
36
+ context 'value is not entered' do
37
+ let(:branch) { default }
38
+
39
+ before do
40
+ $stdout.expects(:puts).with('Please enter branch: |default|')
41
+ $stdin.expects(:gets).returns('')
42
+ end
43
+
44
+ it 'sets the default as the value' do
45
+ env.expects(:set).with(key, branch)
46
+ question.call
47
+ end
48
+
49
+ end
50
+ end
51
+ end
52
+
53
+ end
54
+ end