Skip to content

Commit

Permalink
Merge pull request #1867 from capistrano/allow-cap-t-without-capfile
Browse files Browse the repository at this point in the history
Allow `cap -T` to run without Capfile present
  • Loading branch information
mattbrictson committed Mar 20, 2017
2 parents 9c58ce9 + 27a8fbe commit 7748180
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ gem "capistrano", :github => "capistrano/capistrano"
https://github.com/capistrano/capistrano/compare/v3.7.2...HEAD

* Your contribution here!
* [#1867](https://github.com/capistrano/capistrano/pull/1867): Allow `cap -T` to run without Capfile present - [@mattbrictson](https://github.com/mattbrictson)

## `3.8.0` (2017-03-10)

Expand Down
11 changes: 8 additions & 3 deletions features/installation.feature
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
Feature: Installation

Background:
Given a test app with the default configuration
Given a test app without any configuration

Scenario: The "install" task documentation can be viewed
When I run "cap -T"
Then the task is successful
And contains "cap install" in the output

Scenario: With default stages
When I run cap "install"
When I run "cap install"
Then the deploy.rb file is created
And the default stage files are created
And the tasks folder is created

Scenario: With specified stages
When I run cap "install STAGES=qa,production"
When I run "cap install STAGES=qa,production"
Then the deploy.rb file is created
And the specified stage files are created
And the tasks folder is created
4 changes: 4 additions & 0 deletions features/step_definitions/setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
TestApp.install
end

Given(/^a test app without any configuration$/) do
TestApp.create_test_app
end

Given(/^servers with the roles app and web$/) do
begin
vagrant_cli_command("up")
Expand Down
2 changes: 1 addition & 1 deletion lib/capistrano/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def backtrace_pattern
end

def load_imports
if options.show_tasks
if options.show_tasks && Rake::Task.task_defined?("load:defaults")
invoke "load:defaults"
set(:stage, "")
Dir[deploy_config_path].each { |f| add_import f }
Expand Down
14 changes: 10 additions & 4 deletions spec/support/test_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ def create_test_app
end

Dir.chdir(test_app_path) do
`bundle`
run "bundle"
end
end

def install_test_app_with(config)
create_test_app
Dir.chdir(test_app_path) do
`bundle exec cap install STAGES=#{stage}`
run "cap install STAGES=#{stage}"
end
write_local_deploy_file(config)
end
Expand Down Expand Up @@ -91,14 +91,15 @@ def create_shared_file(path)
end

def cap(task, subdirectory=nil)
run "bundle exec cap #{stage} #{task}", subdirectory
run "cap #{stage} #{task} --trace", subdirectory
end

def run(command, subdirectory=nil)
output = nil
command = "bundle exec #{command}" unless command =~ /^bundle\b/
dir = subdirectory ? test_app_path.join(subdirectory) : test_app_path
Dir.chdir(dir) do
output = `#{command}`
output = with_clean_bundler_env { `#{command}` }
end
[$CHILD_STATUS.success?, output]
end
Expand Down Expand Up @@ -187,4 +188,9 @@ def move_configuration_to_custom_location(location)
def git_wrapper_path
"/tmp/git-ssh-my_app_name-#{stage}-#{current_user}.sh"
end

def with_clean_bundler_env(&block)
return yield unless defined?(Bundler)
Bundler.with_clean_env(&block)
end
end

0 comments on commit 7748180

Please sign in to comment.