Fix Style/StringLiterals
This commit is contained in:
parent
24d788ebd0
commit
b53e550fc0
6
Gemfile
6
Gemfile
|
@ -1,9 +1,9 @@
|
||||||
source 'https://rubygems.org'
|
source "https://rubygems.org"
|
||||||
|
|
||||||
# Specify your gem's dependencies in capistrano.gemspec
|
# Specify your gem's dependencies in capistrano.gemspec
|
||||||
gemspec
|
gemspec
|
||||||
|
|
||||||
group :cucumber do
|
group :cucumber do
|
||||||
gem 'cucumber'
|
gem "cucumber"
|
||||||
gem 'rspec', '~> 3.0.0'
|
gem "rspec", "~> 3.0.0"
|
||||||
end
|
end
|
||||||
|
|
2
bin/cap
2
bin/cap
|
@ -1,3 +1,3 @@
|
||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
require 'capistrano/all'
|
require "capistrano/all"
|
||||||
Capistrano::Application.new.run
|
Capistrano::Application.new.run
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# -*- encoding: utf-8 -*-
|
# -*- encoding: utf-8 -*-
|
||||||
lib = File.expand_path('../lib', __FILE__)
|
lib = File.expand_path("../lib", __FILE__)
|
||||||
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
||||||
require 'capistrano/version'
|
require "capistrano/version"
|
||||||
|
|
||||||
Gem::Specification.new do |gem|
|
Gem::Specification.new do |gem|
|
||||||
gem.name = "capistrano"
|
gem.name = "capistrano"
|
||||||
|
@ -13,19 +13,19 @@ Gem::Specification.new do |gem|
|
||||||
gem.homepage = "http://capistranorb.com/"
|
gem.homepage = "http://capistranorb.com/"
|
||||||
|
|
||||||
gem.files = `git ls-files`.split($/)
|
gem.files = `git ls-files`.split($/)
|
||||||
gem.executables = ['cap', 'capify']
|
gem.executables = ["cap", "capify"]
|
||||||
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
||||||
gem.require_paths = ["lib"]
|
gem.require_paths = ["lib"]
|
||||||
|
|
||||||
gem.licenses = ['MIT']
|
gem.licenses = ["MIT"]
|
||||||
|
|
||||||
gem.required_ruby_version = '>= 1.9.3'
|
gem.required_ruby_version = ">= 1.9.3"
|
||||||
gem.add_dependency 'airbrussh', '>= 1.0.0.beta1'
|
gem.add_dependency "airbrussh", ">= 1.0.0.beta1"
|
||||||
gem.add_dependency 'i18n'
|
gem.add_dependency "i18n"
|
||||||
gem.add_dependency 'rake', '>= 10.0.0'
|
gem.add_dependency "rake", ">= 10.0.0"
|
||||||
gem.add_dependency 'sshkit', '>= 1.9.0.rc1'
|
gem.add_dependency "sshkit", ">= 1.9.0.rc1"
|
||||||
|
|
||||||
gem.add_development_dependency 'rspec'
|
gem.add_development_dependency "rspec"
|
||||||
gem.add_development_dependency 'mocha'
|
gem.add_development_dependency "mocha"
|
||||||
gem.add_development_dependency 'rubocop'
|
gem.add_development_dependency "rubocop"
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
Then(/^references in the remote repo are listed$/) do
|
Then(/^references in the remote repo are listed$/) do
|
||||||
expect(@output).to include('refs/heads/master')
|
expect(@output).to include("refs/heads/master")
|
||||||
end
|
end
|
||||||
|
|
||||||
Then(/^the shared path is created$/) do
|
Then(/^the shared path is created$/) do
|
||||||
|
@ -49,25 +49,25 @@ Then(/^the current directory will be a symlink to the release$/) do
|
||||||
end
|
end
|
||||||
|
|
||||||
Then(/^the deploy\.rb file is created$/) do
|
Then(/^the deploy\.rb file is created$/) do
|
||||||
file = TestApp.test_app_path.join('config/deploy.rb')
|
file = TestApp.test_app_path.join("config/deploy.rb")
|
||||||
expect(File.exist?(file)).to be true
|
expect(File.exist?(file)).to be true
|
||||||
end
|
end
|
||||||
|
|
||||||
Then(/^the default stage files are created$/) do
|
Then(/^the default stage files are created$/) do
|
||||||
staging = TestApp.test_app_path.join('config/deploy/staging.rb')
|
staging = TestApp.test_app_path.join("config/deploy/staging.rb")
|
||||||
production = TestApp.test_app_path.join('config/deploy/production.rb')
|
production = TestApp.test_app_path.join("config/deploy/production.rb")
|
||||||
expect(File.exist?(staging)).to be true
|
expect(File.exist?(staging)).to be true
|
||||||
expect(File.exist?(production)).to be true
|
expect(File.exist?(production)).to be true
|
||||||
end
|
end
|
||||||
|
|
||||||
Then(/^the tasks folder is created$/) do
|
Then(/^the tasks folder is created$/) do
|
||||||
path = TestApp.test_app_path.join('lib/capistrano/tasks')
|
path = TestApp.test_app_path.join("lib/capistrano/tasks")
|
||||||
expect(Dir.exist?(path)).to be true
|
expect(Dir.exist?(path)).to be true
|
||||||
end
|
end
|
||||||
|
|
||||||
Then(/^the specified stage files are created$/) do
|
Then(/^the specified stage files are created$/) do
|
||||||
qa = TestApp.test_app_path.join('config/deploy/qa.rb')
|
qa = TestApp.test_app_path.join("config/deploy/qa.rb")
|
||||||
production = TestApp.test_app_path.join('config/deploy/production.rb')
|
production = TestApp.test_app_path.join("config/deploy/production.rb")
|
||||||
expect(File.exist?(qa)).to be true
|
expect(File.exist?(qa)).to be true
|
||||||
expect(File.exist?(production)).to be true
|
expect(File.exist?(production)).to be true
|
||||||
end
|
end
|
||||||
|
@ -91,18 +91,18 @@ Then(/^the task fails$/) do
|
||||||
end
|
end
|
||||||
|
|
||||||
Then(/^the failure task will run$/) do
|
Then(/^the failure task will run$/) do
|
||||||
failed = TestApp.shared_path.join('failed')
|
failed = TestApp.shared_path.join("failed")
|
||||||
run_vagrant_command(test_file_exists(failed))
|
run_vagrant_command(test_file_exists(failed))
|
||||||
end
|
end
|
||||||
|
|
||||||
Then(/^the failure task will not run$/) do
|
Then(/^the failure task will not run$/) do
|
||||||
failed = TestApp.shared_path.join('failed')
|
failed = TestApp.shared_path.join("failed")
|
||||||
expect { run_vagrant_command(test_file_exists(failed)) }
|
expect { run_vagrant_command(test_file_exists(failed)) }
|
||||||
.to raise_error(VagrantHelpers::VagrantSSHCommandError)
|
.to raise_error(VagrantHelpers::VagrantSSHCommandError)
|
||||||
end
|
end
|
||||||
|
|
||||||
When(/^an error is raised$/) do
|
When(/^an error is raised$/) do
|
||||||
error = TestApp.shared_path.join('fail')
|
error = TestApp.shared_path.join("fail")
|
||||||
run_vagrant_command(test_file_exists(error))
|
run_vagrant_command(test_file_exists(error))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ Given(/^a test app with the default configuration$/) do
|
||||||
end
|
end
|
||||||
|
|
||||||
Given(/^servers with the roles app and web$/) do
|
Given(/^servers with the roles app and web$/) do
|
||||||
vagrant_cli_command('up') rescue nil
|
vagrant_cli_command("up") rescue nil
|
||||||
end
|
end
|
||||||
|
|
||||||
Given(/^a linked file "(.*?)"$/) do |file|
|
Given(/^a linked file "(.*?)"$/) do |file|
|
||||||
|
@ -24,11 +24,11 @@ Given(/^file "(.*?)" does not exist in shared path$/) do |file|
|
||||||
end
|
end
|
||||||
|
|
||||||
Given(/^a custom task to generate a file$/) do
|
Given(/^a custom task to generate a file$/) do
|
||||||
TestApp.copy_task_to_test_app('spec/support/tasks/database.rake')
|
TestApp.copy_task_to_test_app("spec/support/tasks/database.rake")
|
||||||
end
|
end
|
||||||
|
|
||||||
Given(/^a task which executes as root$/) do
|
Given(/^a task which executes as root$/) do
|
||||||
TestApp.copy_task_to_test_app('spec/support/tasks/root.rake')
|
TestApp.copy_task_to_test_app("spec/support/tasks/root.rake")
|
||||||
end
|
end
|
||||||
|
|
||||||
Given(/config stage file has line "(.*?)"/) do |line|
|
Given(/config stage file has line "(.*?)"/) do |line|
|
||||||
|
@ -36,15 +36,15 @@ Given(/config stage file has line "(.*?)"/) do |line|
|
||||||
end
|
end
|
||||||
|
|
||||||
Given(/^the configuration is in a custom location$/) do
|
Given(/^the configuration is in a custom location$/) do
|
||||||
TestApp.move_configuration_to_custom_location('app')
|
TestApp.move_configuration_to_custom_location("app")
|
||||||
end
|
end
|
||||||
|
|
||||||
Given(/^a custom task that will simulate a failure$/) do
|
Given(/^a custom task that will simulate a failure$/) do
|
||||||
safely_remove_file(TestApp.shared_path.join('failed'))
|
safely_remove_file(TestApp.shared_path.join("failed"))
|
||||||
TestApp.copy_task_to_test_app('spec/support/tasks/fail.rake')
|
TestApp.copy_task_to_test_app("spec/support/tasks/fail.rake")
|
||||||
end
|
end
|
||||||
|
|
||||||
Given(/^a custom task to run in the event of a failure$/) do
|
Given(/^a custom task to run in the event of a failure$/) do
|
||||||
safely_remove_file(TestApp.shared_path.join('failed'))
|
safely_remove_file(TestApp.shared_path.join("failed"))
|
||||||
TestApp.copy_task_to_test_app('spec/support/tasks/failed.rake')
|
TestApp.copy_task_to_test_app("spec/support/tasks/failed.rake")
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
PROJECT_ROOT = File.expand_path('../../../', __FILE__)
|
PROJECT_ROOT = File.expand_path("../../../", __FILE__)
|
||||||
VAGRANT_ROOT = File.join(PROJECT_ROOT, 'spec/support')
|
VAGRANT_ROOT = File.join(PROJECT_ROOT, "spec/support")
|
||||||
VAGRANT_BIN = ENV['VAGRANT_BIN'] || "vagrant"
|
VAGRANT_BIN = ENV["VAGRANT_BIN"] || "vagrant"
|
||||||
|
|
||||||
at_exit do
|
at_exit do
|
||||||
if ENV['KEEP_RUNNING']
|
if ENV["KEEP_RUNNING"]
|
||||||
VagrantHelpers.run_vagrant_command("rm -rf /home/vagrant/var")
|
VagrantHelpers.run_vagrant_command("rm -rf /home/vagrant/var")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
require_relative '../../spec/support/test_app'
|
require_relative "../../spec/support/test_app"
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
module RemoteCommandHelpers
|
module RemoteCommandHelpers
|
||||||
def test_dir_exists(path)
|
def test_dir_exists(path)
|
||||||
exists?('d', path)
|
exists?("d", path)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_symlink_exists(path)
|
def test_symlink_exists(path)
|
||||||
exists?('L', path)
|
exists?("L", path)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_file_exists(path)
|
def test_file_exists(path)
|
||||||
exists?('f', path)
|
exists?("f", path)
|
||||||
end
|
end
|
||||||
|
|
||||||
def exists?(type, path)
|
def exists?(type, path)
|
||||||
|
|
|
@ -4,7 +4,7 @@ module VagrantHelpers
|
||||||
class VagrantSSHCommandError < RuntimeError; end
|
class VagrantSSHCommandError < RuntimeError; end
|
||||||
|
|
||||||
at_exit do
|
at_exit do
|
||||||
if ENV['KEEP_RUNNING']
|
if ENV["KEEP_RUNNING"]
|
||||||
puts "Vagrant vm will be left up because KEEP_RUNNING is set."
|
puts "Vagrant vm will be left up because KEEP_RUNNING is set."
|
||||||
puts "Rerun without KEEP_RUNNING set to cleanup the vm."
|
puts "Rerun without KEEP_RUNNING set to cleanup the vm."
|
||||||
else
|
else
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
#!/usr/bin/env cap
|
#!/usr/bin/env cap
|
||||||
include Capistrano::DSL
|
include Capistrano::DSL
|
||||||
require 'capistrano/install'
|
require "capistrano/install"
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
require 'rake'
|
require "rake"
|
||||||
require 'sshkit'
|
require "sshkit"
|
||||||
|
|
||||||
require 'io/console'
|
require "io/console"
|
||||||
|
|
||||||
Rake.application.options.trace = true
|
Rake.application.options.trace = true
|
||||||
|
|
||||||
require 'capistrano/version'
|
require "capistrano/version"
|
||||||
require 'capistrano/version_validator'
|
require "capistrano/version_validator"
|
||||||
require 'capistrano/i18n'
|
require "capistrano/i18n"
|
||||||
require 'capistrano/dsl'
|
require "capistrano/dsl"
|
||||||
require 'capistrano/application'
|
require "capistrano/application"
|
||||||
require 'capistrano/configuration'
|
require "capistrano/configuration"
|
||||||
|
|
||||||
module Capistrano
|
module Capistrano
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ module Capistrano
|
||||||
end
|
end
|
||||||
|
|
||||||
def handle_options
|
def handle_options
|
||||||
options.rakelib = ['rakelib']
|
options.rakelib = ["rakelib"]
|
||||||
options.trace_output = $stderr
|
options.trace_output = $stderr
|
||||||
|
|
||||||
OptionParser.new do |opts|
|
OptionParser.new do |opts|
|
||||||
|
@ -48,7 +48,7 @@ module Capistrano
|
||||||
end
|
end
|
||||||
|
|
||||||
standard_rake_options.each { |args| opts.on(*args) }
|
standard_rake_options.each { |args| opts.on(*args) }
|
||||||
opts.environment('RAKEOPT')
|
opts.environment("RAKEOPT")
|
||||||
end.parse!
|
end.parse!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ module Capistrano
|
||||||
def display_error_message(ex)
|
def display_error_message(ex)
|
||||||
unless options.backtrace
|
unless options.backtrace
|
||||||
Rake.application.options.suppress_backtrace_pattern = backtrace_pattern if backtrace_pattern
|
Rake.application.options.suppress_backtrace_pattern = backtrace_pattern if backtrace_pattern
|
||||||
trace '(Backtrace restricted to imported tasks)'
|
trace "(Backtrace restricted to imported tasks)"
|
||||||
end
|
end
|
||||||
|
|
||||||
super
|
super
|
||||||
|
@ -90,8 +90,8 @@ module Capistrano
|
||||||
|
|
||||||
def load_imports
|
def load_imports
|
||||||
if options.show_tasks
|
if options.show_tasks
|
||||||
invoke 'load:defaults'
|
invoke "load:defaults"
|
||||||
set(:stage, '')
|
set(:stage, "")
|
||||||
Dir[deploy_config_path].each { |f| add_import f }
|
Dir[deploy_config_path].each { |f| add_import f }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -100,11 +100,11 @@ module Capistrano
|
||||||
|
|
||||||
# allows the `cap install` task to load without a capfile
|
# allows the `cap install` task to load without a capfile
|
||||||
def capfile
|
def capfile
|
||||||
File.expand_path(File.join(File.dirname(__FILE__),'..','Capfile'))
|
File.expand_path(File.join(File.dirname(__FILE__),"..","Capfile"))
|
||||||
end
|
end
|
||||||
|
|
||||||
def version
|
def version
|
||||||
['--version', '-V',
|
["--version", "-V",
|
||||||
"Display the program version.",
|
"Display the program version.",
|
||||||
lambda { |_value|
|
lambda { |_value|
|
||||||
puts "Capistrano Version: #{Capistrano::VERSION} (Rake Version: #{RAKEVERSION})"
|
puts "Capistrano Version: #{Capistrano::VERSION} (Rake Version: #{RAKEVERSION})"
|
||||||
|
@ -114,7 +114,7 @@ module Capistrano
|
||||||
end
|
end
|
||||||
|
|
||||||
def dry_run
|
def dry_run
|
||||||
['--dry-run', '-n',
|
["--dry-run", "-n",
|
||||||
"Do a dry run without executing actions",
|
"Do a dry run without executing actions",
|
||||||
lambda { |_value|
|
lambda { |_value|
|
||||||
Configuration.env.set(:sshkit_backend, SSHKit::Backend::Printer)
|
Configuration.env.set(:sshkit_backend, SSHKit::Backend::Printer)
|
||||||
|
@ -123,7 +123,7 @@ module Capistrano
|
||||||
end
|
end
|
||||||
|
|
||||||
def roles
|
def roles
|
||||||
['--roles ROLES', '-r',
|
["--roles ROLES", "-r",
|
||||||
"Run SSH commands only on hosts matching these roles",
|
"Run SSH commands only on hosts matching these roles",
|
||||||
lambda { |value|
|
lambda { |value|
|
||||||
Configuration.env.add_cmdline_filter(:role, value)
|
Configuration.env.add_cmdline_filter(:role, value)
|
||||||
|
@ -132,7 +132,7 @@ module Capistrano
|
||||||
end
|
end
|
||||||
|
|
||||||
def hostfilter
|
def hostfilter
|
||||||
['--hosts HOSTS', '-z',
|
["--hosts HOSTS", "-z",
|
||||||
"Run SSH commands only on matching hosts",
|
"Run SSH commands only on matching hosts",
|
||||||
lambda { |value|
|
lambda { |value|
|
||||||
Configuration.env.add_cmdline_filter(:host, value)
|
Configuration.env.add_cmdline_filter(:host, value)
|
||||||
|
@ -141,7 +141,7 @@ module Capistrano
|
||||||
end
|
end
|
||||||
|
|
||||||
def print_config_variables
|
def print_config_variables
|
||||||
['--print-config-variables', '-p',
|
["--print-config-variables", "-p",
|
||||||
"Display the defined config variables before starting the deployment tasks.",
|
"Display the defined config variables before starting the deployment tasks.",
|
||||||
lambda { |_value|
|
lambda { |_value|
|
||||||
Configuration.env.set(:print_config_variables, true)
|
Configuration.env.set(:print_config_variables, true)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
require_relative 'configuration/filter'
|
require_relative "configuration/filter"
|
||||||
require_relative 'configuration/question'
|
require_relative "configuration/question"
|
||||||
require_relative 'configuration/server'
|
require_relative "configuration/server"
|
||||||
require_relative 'configuration/servers'
|
require_relative "configuration/servers"
|
||||||
|
|
||||||
module Capistrano
|
module Capistrano
|
||||||
class ValidationError < Exception; end
|
class ValidationError < Exception; end
|
||||||
|
@ -132,8 +132,8 @@ module Capistrano
|
||||||
|
|
||||||
def setup_filters
|
def setup_filters
|
||||||
@filters = cmdline_filters.clone
|
@filters = cmdline_filters.clone
|
||||||
@filters << Filter.new(:role, ENV['ROLES']) if ENV['ROLES']
|
@filters << Filter.new(:role, ENV["ROLES"]) if ENV["ROLES"]
|
||||||
@filters << Filter.new(:host, ENV['HOSTS']) if ENV['HOSTS']
|
@filters << Filter.new(:host, ENV["HOSTS"]) if ENV["HOSTS"]
|
||||||
fh = fetch_for(:filter,{}) || {}
|
fh = fetch_for(:filter,{}) || {}
|
||||||
@filters << Filter.new(:host, fh[:hosts]) if fh[:hosts]
|
@filters << Filter.new(:host, fh[:hosts]) if fh[:hosts]
|
||||||
@filters << Filter.new(:role, fh[:roles]) if fh[:roles]
|
@filters << Filter.new(:role, fh[:roles]) if fh[:roles]
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
require 'capistrano/configuration'
|
require "capistrano/configuration"
|
||||||
require 'capistrano/configuration/empty_filter'
|
require "capistrano/configuration/empty_filter"
|
||||||
require 'capistrano/configuration/host_filter'
|
require "capistrano/configuration/host_filter"
|
||||||
require 'capistrano/configuration/null_filter'
|
require "capistrano/configuration/null_filter"
|
||||||
require 'capistrano/configuration/role_filter'
|
require "capistrano/configuration/role_filter"
|
||||||
|
|
||||||
module Capistrano
|
module Capistrano
|
||||||
class Configuration
|
class Configuration
|
||||||
|
@ -12,7 +12,7 @@ module Capistrano
|
||||||
av = Array(values)
|
av = Array(values)
|
||||||
@strategy = case
|
@strategy = case
|
||||||
when av.size == 0 then EmptyFilter.new
|
when av.size == 0 then EmptyFilter.new
|
||||||
when av.include?(:all), av.include?('all') then NullFilter.new
|
when av.include?(:all), av.include?("all") then NullFilter.new
|
||||||
when type == :host then HostFilter.new(values)
|
when type == :host then HostFilter.new(values)
|
||||||
when type == :role then RoleFilter.new(values)
|
when type == :role then RoleFilter.new(values)
|
||||||
else NullFilter.new
|
else NullFilter.new
|
||||||
|
|
|
@ -3,7 +3,7 @@ module Capistrano
|
||||||
class HostFilter
|
class HostFilter
|
||||||
def initialize values
|
def initialize values
|
||||||
av = Array(values).dup
|
av = Array(values).dup
|
||||||
av.map! { |v| (v.is_a?(String) && v =~ /^(?<name>[-A-Za-z0-9.]+)(,\g<name>)*$/) ? v.split(',') : v }
|
av.map! { |v| (v.is_a?(String) && v =~ /^(?<name>[-A-Za-z0-9.]+)(,\g<name>)*$/) ? v.split(",") : v }
|
||||||
av.flatten!
|
av.flatten!
|
||||||
@rex = regex_matcher(av)
|
@rex = regex_matcher(av)
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,7 +3,7 @@ module Capistrano
|
||||||
class RoleFilter
|
class RoleFilter
|
||||||
def initialize values
|
def initialize values
|
||||||
av = Array(values).dup
|
av = Array(values).dup
|
||||||
av.map! { |v| v.is_a?(String) ? v.split(',') : v }
|
av.map! { |v| v.is_a?(String) ? v.split(",") : v }
|
||||||
av.flatten!
|
av.flatten!
|
||||||
@rex = regex_matcher(av)
|
@rex = regex_matcher(av)
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
require 'set'
|
require "set"
|
||||||
module Capistrano
|
module Capistrano
|
||||||
class Configuration
|
class Configuration
|
||||||
class Server < SSHKit::Host
|
class Server < SSHKit::Host
|
||||||
|
@ -122,7 +122,7 @@ module Capistrano
|
||||||
private
|
private
|
||||||
|
|
||||||
def lvalue(key)
|
def lvalue(key)
|
||||||
key.to_s.chomp('=').to_sym
|
key.to_s.chomp("=").to_sym
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
require 'set'
|
require "set"
|
||||||
require 'capistrano/configuration'
|
require "capistrano/configuration"
|
||||||
require 'capistrano/configuration/filter'
|
require "capistrano/configuration/filter"
|
||||||
|
|
||||||
module Capistrano
|
module Capistrano
|
||||||
class Configuration
|
class Configuration
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
validate :application do |_key, value|
|
validate :application do |_key, value|
|
||||||
changed_value = value.gsub(/[^A-Z0-9\.\-]/i, '_')
|
changed_value = value.gsub(/[^A-Z0-9\.\-]/i, "_")
|
||||||
if value != changed_value
|
if value != changed_value
|
||||||
warn %(The :application value "#{value}" is invalid!)
|
warn %(The :application value "#{value}" is invalid!)
|
||||||
warn "Use only letters, numbers, hyphens, dots, and underscores. For example:"
|
warn "Use only letters, numbers, hyphens, dots, and underscores. For example:"
|
||||||
|
@ -9,7 +9,7 @@ validate :application do |_key, value|
|
||||||
end
|
end
|
||||||
|
|
||||||
set_if_empty :scm, :git
|
set_if_empty :scm, :git
|
||||||
set_if_empty :branch, 'master'
|
set_if_empty :branch, "master"
|
||||||
set_if_empty :deploy_to, -> { "/var/www/#{fetch(:application)}" }
|
set_if_empty :deploy_to, -> { "/var/www/#{fetch(:application)}" }
|
||||||
set_if_empty :tmp_dir, "/tmp"
|
set_if_empty :tmp_dir, "/tmp"
|
||||||
|
|
||||||
|
@ -21,4 +21,4 @@ set_if_empty :log_level, :debug
|
||||||
|
|
||||||
set_if_empty :pty, false
|
set_if_empty :pty, false
|
||||||
|
|
||||||
set_if_empty :local_user, -> { ENV['USER'] || ENV['LOGNAME'] || ENV['USERNAME'] }
|
set_if_empty :local_user, -> { ENV["USER"] || ENV["LOGNAME"] || ENV["USERNAME"] }
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
require 'capistrano/framework'
|
require "capistrano/framework"
|
||||||
|
|
||||||
load File.expand_path("../tasks/deploy.rake", __FILE__)
|
load File.expand_path("../tasks/deploy.rake", __FILE__)
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
dotfile = Pathname.new(File.join(Dir.home, '.capfile'))
|
dotfile = Pathname.new(File.join(Dir.home, ".capfile"))
|
||||||
load dotfile if dotfile.file?
|
load dotfile if dotfile.file?
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
require 'capistrano/dsl/task_enhancements'
|
require "capistrano/dsl/task_enhancements"
|
||||||
require 'capistrano/dsl/paths'
|
require "capistrano/dsl/paths"
|
||||||
require 'capistrano/dsl/stages'
|
require "capistrano/dsl/stages"
|
||||||
require 'capistrano/dsl/env'
|
require "capistrano/dsl/env"
|
||||||
require 'capistrano/configuration/filter'
|
require "capistrano/configuration/filter"
|
||||||
|
|
||||||
module Capistrano
|
module Capistrano
|
||||||
module DSL
|
module DSL
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
require 'pathname'
|
require "pathname"
|
||||||
module Capistrano
|
module Capistrano
|
||||||
module DSL
|
module DSL
|
||||||
module Paths
|
module Paths
|
||||||
|
@ -12,11 +12,11 @@ module Capistrano
|
||||||
end
|
end
|
||||||
|
|
||||||
def current_path
|
def current_path
|
||||||
deploy_path.join('current')
|
deploy_path.join("current")
|
||||||
end
|
end
|
||||||
|
|
||||||
def releases_path
|
def releases_path
|
||||||
deploy_path.join('releases')
|
deploy_path.join("releases")
|
||||||
end
|
end
|
||||||
|
|
||||||
def release_path
|
def release_path
|
||||||
|
@ -29,16 +29,16 @@ module Capistrano
|
||||||
end
|
end
|
||||||
|
|
||||||
def stage_config_path
|
def stage_config_path
|
||||||
Pathname.new fetch(:stage_config_path, 'config/deploy')
|
Pathname.new fetch(:stage_config_path, "config/deploy")
|
||||||
end
|
end
|
||||||
|
|
||||||
def deploy_config_path
|
def deploy_config_path
|
||||||
Pathname.new fetch(:deploy_config_path, 'config/deploy.rb')
|
Pathname.new fetch(:deploy_config_path, "config/deploy.rb")
|
||||||
end
|
end
|
||||||
|
|
||||||
def repo_url
|
def repo_url
|
||||||
require 'cgi'
|
require "cgi"
|
||||||
require 'uri'
|
require "uri"
|
||||||
if fetch(:git_http_username) and fetch(:git_http_password)
|
if fetch(:git_http_username) and fetch(:git_http_password)
|
||||||
URI.parse(fetch(:repo_url)).tap do |repo_uri|
|
URI.parse(fetch(:repo_url)).tap do |repo_uri|
|
||||||
repo_uri.user = fetch(:git_http_username)
|
repo_uri.user = fetch(:git_http_username)
|
||||||
|
@ -54,15 +54,15 @@ module Capistrano
|
||||||
end
|
end
|
||||||
|
|
||||||
def repo_path
|
def repo_path
|
||||||
Pathname.new(fetch(:repo_path, ->(){deploy_path.join('repo')}))
|
Pathname.new(fetch(:repo_path, ->(){deploy_path.join("repo")}))
|
||||||
end
|
end
|
||||||
|
|
||||||
def shared_path
|
def shared_path
|
||||||
deploy_path.join('shared')
|
deploy_path.join("shared")
|
||||||
end
|
end
|
||||||
|
|
||||||
def revision_log
|
def revision_log
|
||||||
deploy_path.join('revisions.log')
|
deploy_path.join("revisions.log")
|
||||||
end
|
end
|
||||||
|
|
||||||
def now
|
def now
|
||||||
|
|
|
@ -3,11 +3,11 @@ module Capistrano
|
||||||
module Stages
|
module Stages
|
||||||
|
|
||||||
def stages
|
def stages
|
||||||
Dir[stage_definitions].map { |f| File.basename(f, '.rb') }
|
Dir[stage_definitions].map { |f| File.basename(f, ".rb") }
|
||||||
end
|
end
|
||||||
|
|
||||||
def stage_definitions
|
def stage_definitions
|
||||||
stage_config_path.join('*.rb')
|
stage_config_path.join("*.rb")
|
||||||
end
|
end
|
||||||
|
|
||||||
def stage_set?
|
def stage_set?
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
require 'capistrano/upload_task'
|
require "capistrano/upload_task"
|
||||||
|
|
||||||
module Capistrano
|
module Capistrano
|
||||||
module TaskEnhancements
|
module TaskEnhancements
|
||||||
|
@ -54,7 +54,7 @@ module Capistrano
|
||||||
|
|
||||||
def exit_deploy_because_of_exception(ex)
|
def exit_deploy_because_of_exception(ex)
|
||||||
warn t(:deploy_failed, :ex => ex.message)
|
warn t(:deploy_failed, :ex => ex.message)
|
||||||
invoke 'deploy:failed'
|
invoke "deploy:failed"
|
||||||
exit(false)
|
exit(false)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
load File.expand_path("../tasks/framework.rake", __FILE__)
|
load File.expand_path("../tasks/framework.rake", __FILE__)
|
||||||
require 'capistrano/install'
|
require "capistrano/install"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
load File.expand_path("../tasks/git.rake", __FILE__)
|
load File.expand_path("../tasks/git.rake", __FILE__)
|
||||||
|
|
||||||
require 'capistrano/scm'
|
require "capistrano/scm"
|
||||||
|
|
||||||
class Capistrano::Git < Capistrano::SCM
|
class Capistrano::Git < Capistrano::SCM
|
||||||
|
|
||||||
|
@ -23,28 +23,28 @@ class Capistrano::Git < Capistrano::SCM
|
||||||
|
|
||||||
def clone
|
def clone
|
||||||
if (depth = fetch(:git_shallow_clone))
|
if (depth = fetch(:git_shallow_clone))
|
||||||
git :clone, '--mirror', '--depth', depth, '--no-single-branch', repo_url, repo_path
|
git :clone, "--mirror", "--depth", depth, "--no-single-branch", repo_url, repo_path
|
||||||
else
|
else
|
||||||
git :clone, '--mirror', repo_url, repo_path
|
git :clone, "--mirror", repo_url, repo_path
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
# Note: Requires git version 1.9 or greater
|
# Note: Requires git version 1.9 or greater
|
||||||
if (depth = fetch(:git_shallow_clone))
|
if (depth = fetch(:git_shallow_clone))
|
||||||
git :fetch, '--depth', depth, 'origin', fetch(:branch)
|
git :fetch, "--depth", depth, "origin", fetch(:branch)
|
||||||
else
|
else
|
||||||
git :remote, :update, '--prune'
|
git :remote, :update, "--prune"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def release
|
def release
|
||||||
if (tree = fetch(:repo_tree))
|
if (tree = fetch(:repo_tree))
|
||||||
tree = tree.slice %r#^/?(.*?)/?$#, 1
|
tree = tree.slice %r#^/?(.*?)/?$#, 1
|
||||||
components = tree.split('/').size
|
components = tree.split("/").size
|
||||||
git :archive, fetch(:branch), tree, "| tar -x --strip-components #{components} -f - -C", release_path
|
git :archive, fetch(:branch), tree, "| tar -x --strip-components #{components} -f - -C", release_path
|
||||||
else
|
else
|
||||||
git :archive, fetch(:branch), '| tar -x -f - -C', release_path
|
git :archive, fetch(:branch), "| tar -x -f - -C", release_path
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
load File.expand_path("../tasks/hg.rake", __FILE__)
|
load File.expand_path("../tasks/hg.rake", __FILE__)
|
||||||
|
|
||||||
require 'capistrano/scm'
|
require "capistrano/scm"
|
||||||
|
|
||||||
class Capistrano::Hg < Capistrano::SCM
|
class Capistrano::Hg < Capistrano::SCM
|
||||||
# execute hg in context with arguments
|
# execute hg in context with arguments
|
||||||
|
@ -29,7 +29,7 @@ class Capistrano::Hg < Capistrano::SCM
|
||||||
def release
|
def release
|
||||||
if (tree = fetch(:repo_tree))
|
if (tree = fetch(:repo_tree))
|
||||||
tree = tree.slice %r#^/?(.*?)/?$#, 1
|
tree = tree.slice %r#^/?(.*?)/?$#, 1
|
||||||
components = tree.split('/').size
|
components = tree.split("/").size
|
||||||
hg "archive --type tgz -p . -I", tree, "--rev", fetch(:branch), "| tar -x --strip-components #{components} -f - -C", release_path
|
hg "archive --type tgz -p . -I", tree, "--rev", fetch(:branch), "| tar -x --strip-components #{components} -f - -C", release_path
|
||||||
else
|
else
|
||||||
hg "archive", release_path, "--rev", fetch(:branch)
|
hg "archive", release_path, "--rev", fetch(:branch)
|
||||||
|
|
|
@ -1,32 +1,32 @@
|
||||||
require 'i18n'
|
require "i18n"
|
||||||
|
|
||||||
en = {
|
en = {
|
||||||
:starting => 'Starting',
|
:starting => "Starting",
|
||||||
:capified => 'Capified',
|
:capified => "Capified",
|
||||||
:start => 'Start',
|
:start => "Start",
|
||||||
:update => 'Update',
|
:update => "Update",
|
||||||
:finalize => 'Finalise',
|
:finalize => "Finalise",
|
||||||
:finishing => 'Finishing',
|
:finishing => "Finishing",
|
||||||
:finished => 'Finished',
|
:finished => "Finished",
|
||||||
:stage_not_set => 'Stage not set, please call something such as `cap production deploy`, where production is a stage you have defined.',
|
:stage_not_set => "Stage not set, please call something such as `cap production deploy`, where production is a stage you have defined.",
|
||||||
:written_file => 'create %{file}',
|
:written_file => "create %{file}",
|
||||||
:question => 'Please enter %{key} (%{default_value}): ',
|
:question => "Please enter %{key} (%{default_value}): ",
|
||||||
:keeping_releases => 'Keeping %{keep_releases} of %{releases} deployed releases on %{host}',
|
:keeping_releases => "Keeping %{keep_releases} of %{releases} deployed releases on %{host}",
|
||||||
:no_old_releases => 'No old releases (keeping newest %{keep_releases}) on %{host}',
|
:no_old_releases => "No old releases (keeping newest %{keep_releases}) on %{host}",
|
||||||
:linked_file_does_not_exist => 'linked file %{file} does not exist on %{host}',
|
:linked_file_does_not_exist => "linked file %{file} does not exist on %{host}",
|
||||||
:cannot_rollback => 'There are no older releases to rollback to',
|
:cannot_rollback => "There are no older releases to rollback to",
|
||||||
:mirror_exists => 'The repository mirror is at %{at}',
|
:mirror_exists => "The repository mirror is at %{at}",
|
||||||
:revision_log_message => 'Branch %{branch} (at %{sha}) deployed as release %{release} by %{user}',
|
:revision_log_message => "Branch %{branch} (at %{sha}) deployed as release %{release} by %{user}",
|
||||||
:rollback_log_message => '%{user} rolled back to release %{release}',
|
:rollback_log_message => "%{user} rolled back to release %{release}",
|
||||||
:deploy_failed => 'The deploy has failed with an error: %{ex}',
|
:deploy_failed => "The deploy has failed with an error: %{ex}",
|
||||||
:console => {
|
:console => {
|
||||||
:welcome => 'capistrano console - enter command to execute on %{stage}',
|
:welcome => "capistrano console - enter command to execute on %{stage}",
|
||||||
:bye => 'bye'
|
:bye => "bye"
|
||||||
},
|
},
|
||||||
:error => {
|
:error => {
|
||||||
:user => {
|
:user => {
|
||||||
:does_not_exist => 'User %{user} does not exists',
|
:does_not_exist => "User %{user} does not exists",
|
||||||
:cannot_switch => 'Cannot switch to user %{user}'
|
:cannot_switch => "Cannot switch to user %{user}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
load File.expand_path(File.join(File.dirname(__FILE__),'tasks/install.rake'))
|
load File.expand_path(File.join(File.dirname(__FILE__),"tasks/install.rake"))
|
||||||
|
|
|
@ -3,7 +3,7 @@ include Capistrano::DSL
|
||||||
|
|
||||||
namespace :load do
|
namespace :load do
|
||||||
task :defaults do
|
task :defaults do
|
||||||
load 'capistrano/defaults.rb'
|
load "capistrano/defaults.rb"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ stages.each do |stage|
|
||||||
Rake::Task.define_task(stage) do
|
Rake::Task.define_task(stage) do
|
||||||
set(:stage, stage.to_sym)
|
set(:stage, stage.to_sym)
|
||||||
|
|
||||||
invoke 'load:defaults'
|
invoke "load:defaults"
|
||||||
Rake.application["load:defaults"].extend(Capistrano::ImmutableTask)
|
Rake.application["load:defaults"].extend(Capistrano::ImmutableTask)
|
||||||
load deploy_config_path
|
load deploy_config_path
|
||||||
load stage_config_path.join("#{stage}.rb")
|
load stage_config_path.join("#{stage}.rb")
|
||||||
|
@ -30,4 +30,4 @@ stages.each do |stage|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
require 'capistrano/dotfile'
|
require "capistrano/dotfile"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
load File.expand_path("../tasks/svn.rake", __FILE__)
|
load File.expand_path("../tasks/svn.rake", __FILE__)
|
||||||
|
|
||||||
require 'capistrano/scm'
|
require "capistrano/scm"
|
||||||
|
|
||||||
class Capistrano::Svn < Capistrano::SCM
|
class Capistrano::Svn < Capistrano::SCM
|
||||||
|
|
||||||
|
@ -19,8 +19,8 @@ class Capistrano::Svn < Capistrano::SCM
|
||||||
end
|
end
|
||||||
|
|
||||||
def check
|
def check
|
||||||
svn_username = fetch(:svn_username) ? "--username #{fetch(:svn_username)}" : ''
|
svn_username = fetch(:svn_username) ? "--username #{fetch(:svn_username)}" : ""
|
||||||
svn_password = fetch(:svn_password) ? "--password #{fetch(:svn_password)}" : ''
|
svn_password = fetch(:svn_password) ? "--password #{fetch(:svn_password)}" : ""
|
||||||
test! :svn, :info, repo_url, svn_username, svn_password
|
test! :svn, :info, repo_url, svn_username, svn_password
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ class Capistrano::Svn < Capistrano::SCM
|
||||||
end
|
end
|
||||||
|
|
||||||
def release
|
def release
|
||||||
svn :export, '--force', '.', release_path
|
svn :export, "--force", ".", release_path
|
||||||
end
|
end
|
||||||
|
|
||||||
def fetch_revision
|
def fetch_revision
|
||||||
|
|
|
@ -1,20 +1,20 @@
|
||||||
desc 'Execute remote commands'
|
desc "Execute remote commands"
|
||||||
task :console do
|
task :console do
|
||||||
stage = fetch(:stage)
|
stage = fetch(:stage)
|
||||||
puts I18n.t('console.welcome', :scope => :capistrano, :stage => stage)
|
puts I18n.t("console.welcome", :scope => :capistrano, :stage => stage)
|
||||||
loop do
|
loop do
|
||||||
print "#{stage}> "
|
print "#{stage}> "
|
||||||
|
|
||||||
if (input = $stdin.gets)
|
if (input = $stdin.gets)
|
||||||
command = input.chomp
|
command = input.chomp
|
||||||
else
|
else
|
||||||
command = 'exit'
|
command = "exit"
|
||||||
end
|
end
|
||||||
|
|
||||||
next if command.empty?
|
next if command.empty?
|
||||||
|
|
||||||
if %w{quit exit q}.include? command
|
if %w{quit exit q}.include? command
|
||||||
puts t('console.bye')
|
puts t("console.bye")
|
||||||
break
|
break
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
namespace :deploy do
|
namespace :deploy do
|
||||||
|
|
||||||
task :starting do
|
task :starting do
|
||||||
invoke 'deploy:print_config_variables' if fetch(:print_config_variables, false)
|
invoke "deploy:print_config_variables" if fetch(:print_config_variables, false)
|
||||||
invoke 'deploy:check'
|
invoke "deploy:check"
|
||||||
invoke 'deploy:set_previous_revision'
|
invoke "deploy:set_previous_revision"
|
||||||
end
|
end
|
||||||
|
|
||||||
task :print_config_variables do
|
task :print_config_variables do
|
||||||
|
|
||||||
puts
|
puts
|
||||||
puts '------- Printing current config variables -------'
|
puts "------- Printing current config variables -------"
|
||||||
env.keys.each do |config_variable_key|
|
env.keys.each do |config_variable_key|
|
||||||
if is_question?(config_variable_key)
|
if is_question?(config_variable_key)
|
||||||
puts "#{config_variable_key.inspect} => Question (awaits user input on next fetch(#{config_variable_key.inspect}))"
|
puts "#{config_variable_key.inspect} => Question (awaits user input on next fetch(#{config_variable_key.inspect}))"
|
||||||
|
@ -19,7 +19,7 @@ namespace :deploy do
|
||||||
end
|
end
|
||||||
|
|
||||||
puts
|
puts
|
||||||
puts '------- Printing current config variables of SSHKit mechanism -------'
|
puts "------- Printing current config variables of SSHKit mechanism -------"
|
||||||
puts env.backend.config.inspect
|
puts env.backend.config.inspect
|
||||||
# puts env.backend.config.backend.config.ssh_options.inspect
|
# puts env.backend.config.backend.config.ssh_options.inspect
|
||||||
# puts env.backend.config.command_map.defaults.inspect
|
# puts env.backend.config.command_map.defaults.inspect
|
||||||
|
@ -30,63 +30,63 @@ namespace :deploy do
|
||||||
task :updating => :new_release_path do
|
task :updating => :new_release_path do
|
||||||
invoke "#{scm}:create_release"
|
invoke "#{scm}:create_release"
|
||||||
invoke "deploy:set_current_revision"
|
invoke "deploy:set_current_revision"
|
||||||
invoke 'deploy:symlink:shared'
|
invoke "deploy:symlink:shared"
|
||||||
end
|
end
|
||||||
|
|
||||||
task :reverting do
|
task :reverting do
|
||||||
invoke 'deploy:revert_release'
|
invoke "deploy:revert_release"
|
||||||
end
|
end
|
||||||
|
|
||||||
task :publishing do
|
task :publishing do
|
||||||
invoke 'deploy:symlink:release'
|
invoke "deploy:symlink:release"
|
||||||
end
|
end
|
||||||
|
|
||||||
task :finishing do
|
task :finishing do
|
||||||
invoke 'deploy:cleanup'
|
invoke "deploy:cleanup"
|
||||||
end
|
end
|
||||||
|
|
||||||
task :finishing_rollback do
|
task :finishing_rollback do
|
||||||
invoke 'deploy:cleanup_rollback'
|
invoke "deploy:cleanup_rollback"
|
||||||
end
|
end
|
||||||
|
|
||||||
task :finished do
|
task :finished do
|
||||||
invoke 'deploy:log_revision'
|
invoke "deploy:log_revision"
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'Check required files and directories exist'
|
desc "Check required files and directories exist"
|
||||||
task :check do
|
task :check do
|
||||||
invoke "#{scm}:check"
|
invoke "#{scm}:check"
|
||||||
invoke 'deploy:check:directories'
|
invoke "deploy:check:directories"
|
||||||
invoke 'deploy:check:linked_dirs'
|
invoke "deploy:check:linked_dirs"
|
||||||
invoke 'deploy:check:make_linked_dirs'
|
invoke "deploy:check:make_linked_dirs"
|
||||||
invoke 'deploy:check:linked_files'
|
invoke "deploy:check:linked_files"
|
||||||
end
|
end
|
||||||
|
|
||||||
namespace :check do
|
namespace :check do
|
||||||
desc 'Check shared and release directories exist'
|
desc "Check shared and release directories exist"
|
||||||
task :directories do
|
task :directories do
|
||||||
on release_roles :all do
|
on release_roles :all do
|
||||||
execute :mkdir, '-p', shared_path, releases_path
|
execute :mkdir, "-p", shared_path, releases_path
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'Check directories to be linked exist in shared'
|
desc "Check directories to be linked exist in shared"
|
||||||
task :linked_dirs do
|
task :linked_dirs do
|
||||||
next unless any? :linked_dirs
|
next unless any? :linked_dirs
|
||||||
on release_roles :all do
|
on release_roles :all do
|
||||||
execute :mkdir, '-p', linked_dirs(shared_path)
|
execute :mkdir, "-p", linked_dirs(shared_path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'Check directories of files to be linked exist in shared'
|
desc "Check directories of files to be linked exist in shared"
|
||||||
task :make_linked_dirs do
|
task :make_linked_dirs do
|
||||||
next unless any? :linked_files
|
next unless any? :linked_files
|
||||||
on release_roles :all do |_host|
|
on release_roles :all do |_host|
|
||||||
execute :mkdir, '-p', linked_file_dirs(shared_path)
|
execute :mkdir, "-p", linked_file_dirs(shared_path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'Check files to be linked exist in shared'
|
desc "Check files to be linked exist in shared"
|
||||||
task :linked_files do
|
task :linked_files do
|
||||||
next unless any? :linked_files
|
next unless any? :linked_files
|
||||||
on release_roles :all do |host|
|
on release_roles :all do |host|
|
||||||
|
@ -101,45 +101,45 @@ namespace :deploy do
|
||||||
end
|
end
|
||||||
|
|
||||||
namespace :symlink do
|
namespace :symlink do
|
||||||
desc 'Symlink release to current'
|
desc "Symlink release to current"
|
||||||
task :release do
|
task :release do
|
||||||
on release_roles :all do
|
on release_roles :all do
|
||||||
tmp_current_path = release_path.parent.join(current_path.basename)
|
tmp_current_path = release_path.parent.join(current_path.basename)
|
||||||
execute :ln, '-s', release_path, tmp_current_path
|
execute :ln, "-s", release_path, tmp_current_path
|
||||||
execute :mv, tmp_current_path, current_path.parent
|
execute :mv, tmp_current_path, current_path.parent
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'Symlink files and directories from shared to release'
|
desc "Symlink files and directories from shared to release"
|
||||||
task :shared do
|
task :shared do
|
||||||
invoke 'deploy:symlink:linked_files'
|
invoke "deploy:symlink:linked_files"
|
||||||
invoke 'deploy:symlink:linked_dirs'
|
invoke "deploy:symlink:linked_dirs"
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'Symlink linked directories'
|
desc "Symlink linked directories"
|
||||||
task :linked_dirs do
|
task :linked_dirs do
|
||||||
next unless any? :linked_dirs
|
next unless any? :linked_dirs
|
||||||
on release_roles :all do
|
on release_roles :all do
|
||||||
execute :mkdir, '-p', linked_dir_parents(release_path)
|
execute :mkdir, "-p", linked_dir_parents(release_path)
|
||||||
|
|
||||||
fetch(:linked_dirs).each do |dir|
|
fetch(:linked_dirs).each do |dir|
|
||||||
target = release_path.join(dir)
|
target = release_path.join(dir)
|
||||||
source = shared_path.join(dir)
|
source = shared_path.join(dir)
|
||||||
unless test "[ -L #{target} ]"
|
unless test "[ -L #{target} ]"
|
||||||
if test "[ -d #{target} ]"
|
if test "[ -d #{target} ]"
|
||||||
execute :rm, '-rf', target
|
execute :rm, "-rf", target
|
||||||
end
|
end
|
||||||
execute :ln, '-s', source, target
|
execute :ln, "-s", source, target
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'Symlink linked files'
|
desc "Symlink linked files"
|
||||||
task :linked_files do
|
task :linked_files do
|
||||||
next unless any? :linked_files
|
next unless any? :linked_files
|
||||||
on release_roles :all do
|
on release_roles :all do
|
||||||
execute :mkdir, '-p', linked_file_dirs(release_path)
|
execute :mkdir, "-p", linked_file_dirs(release_path)
|
||||||
|
|
||||||
fetch(:linked_files).each do |file|
|
fetch(:linked_files).each do |file|
|
||||||
target = release_path.join(file)
|
target = release_path.join(file)
|
||||||
|
@ -148,17 +148,17 @@ namespace :deploy do
|
||||||
if test "[ -f #{target} ]"
|
if test "[ -f #{target} ]"
|
||||||
execute :rm, target
|
execute :rm, target
|
||||||
end
|
end
|
||||||
execute :ln, '-s', source, target
|
execute :ln, "-s", source, target
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'Clean up old releases'
|
desc "Clean up old releases"
|
||||||
task :cleanup do
|
task :cleanup do
|
||||||
on release_roles :all do |host|
|
on release_roles :all do |host|
|
||||||
releases = capture(:ls, '-xtr', releases_path).split
|
releases = capture(:ls, "-xtr", releases_path).split
|
||||||
if releases.count >= fetch(:keep_releases)
|
if releases.count >= fetch(:keep_releases)
|
||||||
info t(:keeping_releases, :host => host.to_s, :keep_releases => fetch(:keep_releases), :releases => releases.count)
|
info t(:keeping_releases, :host => host.to_s, :keep_releases => fetch(:keep_releases), :releases => releases.count)
|
||||||
directories = (releases - releases.last(fetch(:keep_releases)))
|
directories = (releases - releases.last(fetch(:keep_releases)))
|
||||||
|
@ -166,7 +166,7 @@ namespace :deploy do
|
||||||
directories_str = directories.map do |release|
|
directories_str = directories.map do |release|
|
||||||
releases_path.join(release)
|
releases_path.join(release)
|
||||||
end.join(" ")
|
end.join(" ")
|
||||||
execute :rm, '-rf', directories_str
|
execute :rm, "-rf", directories_str
|
||||||
else
|
else
|
||||||
info t(:no_old_releases, :host => host.to_s, :keep_releases => fetch(:keep_releases))
|
info t(:no_old_releases, :host => host.to_s, :keep_releases => fetch(:keep_releases))
|
||||||
end
|
end
|
||||||
|
@ -174,23 +174,23 @@ namespace :deploy do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'Remove and archive rolled-back release.'
|
desc "Remove and archive rolled-back release."
|
||||||
task :cleanup_rollback do
|
task :cleanup_rollback do
|
||||||
on release_roles(:all) do
|
on release_roles(:all) do
|
||||||
last_release = capture(:ls, '-xt', releases_path).split.first
|
last_release = capture(:ls, "-xt", releases_path).split.first
|
||||||
last_release_path = releases_path.join(last_release)
|
last_release_path = releases_path.join(last_release)
|
||||||
if test "[ `readlink #{current_path}` != #{last_release_path} ]"
|
if test "[ `readlink #{current_path}` != #{last_release_path} ]"
|
||||||
execute :tar, '-czf',
|
execute :tar, "-czf",
|
||||||
deploy_path.join("rolled-back-release-#{last_release}.tar.gz"),
|
deploy_path.join("rolled-back-release-#{last_release}.tar.gz"),
|
||||||
last_release_path
|
last_release_path
|
||||||
execute :rm, '-rf', last_release_path
|
execute :rm, "-rf", last_release_path
|
||||||
else
|
else
|
||||||
debug 'Last release is the current release, skip cleanup_rollback.'
|
debug "Last release is the current release, skip cleanup_rollback."
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'Log details of the deploy'
|
desc "Log details of the deploy"
|
||||||
task :log_revision do
|
task :log_revision do
|
||||||
on release_roles(:all) do
|
on release_roles(:all) do
|
||||||
within releases_path do
|
within releases_path do
|
||||||
|
@ -199,7 +199,7 @@ namespace :deploy do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'Revert to previous release timestamp'
|
desc "Revert to previous release timestamp"
|
||||||
task :revert_release => :rollback_release_path do
|
task :revert_release => :rollback_release_path do
|
||||||
on release_roles(:all) do
|
on release_roles(:all) do
|
||||||
set(:revision_log_message, rollback_log_message)
|
set(:revision_log_message, rollback_log_message)
|
||||||
|
@ -212,7 +212,7 @@ namespace :deploy do
|
||||||
|
|
||||||
task :rollback_release_path do
|
task :rollback_release_path do
|
||||||
on release_roles(:all) do
|
on release_roles(:all) do
|
||||||
releases = capture(:ls, '-xt', releases_path).split
|
releases = capture(:ls, "-xt", releases_path).split
|
||||||
if releases.count < 2
|
if releases.count < 2
|
||||||
error t(:cannot_rollback)
|
error t(:cannot_rollback)
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -235,9 +235,9 @@ namespace :deploy do
|
||||||
|
|
||||||
task :set_previous_revision do
|
task :set_previous_revision do
|
||||||
on release_roles(:all) do
|
on release_roles(:all) do
|
||||||
target = release_path.join('REVISION')
|
target = release_path.join("REVISION")
|
||||||
if test "[ -f #{target} ]"
|
if test "[ -f #{target} ]"
|
||||||
set(:previous_revision, capture(:cat, target, '2>/dev/null'))
|
set(:previous_revision, capture(:cat, target, "2>/dev/null"))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,50 +1,50 @@
|
||||||
namespace :deploy do
|
namespace :deploy do
|
||||||
|
|
||||||
desc 'Start a deployment, make sure server(s) ready.'
|
desc "Start a deployment, make sure server(s) ready."
|
||||||
task :starting do
|
task :starting do
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'Started'
|
desc "Started"
|
||||||
task :started do
|
task :started do
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'Update server(s) by setting up a new release.'
|
desc "Update server(s) by setting up a new release."
|
||||||
task :updating do
|
task :updating do
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'Updated'
|
desc "Updated"
|
||||||
task :updated do
|
task :updated do
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'Revert server(s) to previous release.'
|
desc "Revert server(s) to previous release."
|
||||||
task :reverting do
|
task :reverting do
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'Reverted'
|
desc "Reverted"
|
||||||
task :reverted do
|
task :reverted do
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'Publish the release.'
|
desc "Publish the release."
|
||||||
task :publishing do
|
task :publishing do
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'Published'
|
desc "Published"
|
||||||
task :published do
|
task :published do
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'Finish the deployment, clean up server(s).'
|
desc "Finish the deployment, clean up server(s)."
|
||||||
task :finishing do
|
task :finishing do
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'Finish the rollback, clean up server(s).'
|
desc "Finish the rollback, clean up server(s)."
|
||||||
task :finishing_rollback do
|
task :finishing_rollback do
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'Finished'
|
desc "Finished"
|
||||||
task :finished do
|
task :finished do
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'Rollback to previous release.'
|
desc "Rollback to previous release."
|
||||||
task :rollback do
|
task :rollback do
|
||||||
%w{ starting started
|
%w{ starting started
|
||||||
reverting reverted
|
reverting reverted
|
||||||
|
@ -55,7 +55,7 @@ namespace :deploy do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'Deploy a new release.'
|
desc "Deploy a new release."
|
||||||
task :deploy do
|
task :deploy do
|
||||||
set(:deploying, true)
|
set(:deploying, true)
|
||||||
%w{ starting started
|
%w{ starting started
|
||||||
|
|
|
@ -11,7 +11,7 @@ namespace :git do
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
desc 'Upload the git wrapper script, this script guarantees that we can script git without getting an interactive prompt'
|
desc "Upload the git wrapper script, this script guarantees that we can script git without getting an interactive prompt"
|
||||||
task :wrapper do
|
task :wrapper do
|
||||||
on release_roles :all do
|
on release_roles :all do
|
||||||
execute :mkdir, "-p", "#{fetch(:tmp_dir)}/#{fetch(:application)}/"
|
execute :mkdir, "-p", "#{fetch(:tmp_dir)}/#{fetch(:application)}/"
|
||||||
|
@ -20,7 +20,7 @@ namespace :git do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'Check that the repository is reachable'
|
desc "Check that the repository is reachable"
|
||||||
task :check => :'git:wrapper' do
|
task :check => :'git:wrapper' do
|
||||||
fetch(:branch)
|
fetch(:branch)
|
||||||
on release_roles :all do
|
on release_roles :all do
|
||||||
|
@ -30,7 +30,7 @@ namespace :git do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'Clone the repo to the cache'
|
desc "Clone the repo to the cache"
|
||||||
task :clone => :'git:wrapper' do
|
task :clone => :'git:wrapper' do
|
||||||
on release_roles :all do
|
on release_roles :all do
|
||||||
if strategy.test
|
if strategy.test
|
||||||
|
@ -45,7 +45,7 @@ namespace :git do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'Update the repo mirror to reflect the origin state'
|
desc "Update the repo mirror to reflect the origin state"
|
||||||
task :update => :'git:clone' do
|
task :update => :'git:clone' do
|
||||||
on release_roles :all do
|
on release_roles :all do
|
||||||
within repo_path do
|
within repo_path do
|
||||||
|
@ -56,19 +56,19 @@ namespace :git do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'Copy repo to releases'
|
desc "Copy repo to releases"
|
||||||
task :create_release => :'git:update' do
|
task :create_release => :'git:update' do
|
||||||
on release_roles :all do
|
on release_roles :all do
|
||||||
with fetch(:git_environmental_variables) do
|
with fetch(:git_environmental_variables) do
|
||||||
within repo_path do
|
within repo_path do
|
||||||
execute :mkdir, '-p', release_path
|
execute :mkdir, "-p", release_path
|
||||||
strategy.release
|
strategy.release
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'Determine the revision that will be deployed'
|
desc "Determine the revision that will be deployed"
|
||||||
task :set_current_revision do
|
task :set_current_revision do
|
||||||
on release_roles :all do
|
on release_roles :all do
|
||||||
within repo_path do
|
within repo_path do
|
||||||
|
|
|
@ -3,14 +3,14 @@ namespace :hg do
|
||||||
@strategy ||= Capistrano::Hg.new(self, fetch(:hg_strategy, Capistrano::Hg::DefaultStrategy))
|
@strategy ||= Capistrano::Hg.new(self, fetch(:hg_strategy, Capistrano::Hg::DefaultStrategy))
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'Check that the repo is reachable'
|
desc "Check that the repo is reachable"
|
||||||
task :check do
|
task :check do
|
||||||
on release_roles :all do
|
on release_roles :all do
|
||||||
strategy.check
|
strategy.check
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'Clone the repo to the cache'
|
desc "Clone the repo to the cache"
|
||||||
task :clone do
|
task :clone do
|
||||||
on release_roles :all do
|
on release_roles :all do
|
||||||
if strategy.test
|
if strategy.test
|
||||||
|
@ -23,7 +23,7 @@ namespace :hg do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'Pull changes from the remote repo'
|
desc "Pull changes from the remote repo"
|
||||||
task :update => :'hg:clone' do
|
task :update => :'hg:clone' do
|
||||||
on release_roles :all do
|
on release_roles :all do
|
||||||
within repo_path do
|
within repo_path do
|
||||||
|
@ -32,7 +32,7 @@ namespace :hg do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'Copy repo to releases'
|
desc "Copy repo to releases"
|
||||||
task :create_release => :'hg:update' do
|
task :create_release => :'hg:update' do
|
||||||
on release_roles :all do
|
on release_roles :all do
|
||||||
within repo_path do
|
within repo_path do
|
||||||
|
@ -41,7 +41,7 @@ namespace :hg do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'Determine the revision that will be deployed'
|
desc "Determine the revision that will be deployed"
|
||||||
task :set_current_revision do
|
task :set_current_revision do
|
||||||
on release_roles :all do
|
on release_roles :all do
|
||||||
within repo_path do
|
within repo_path do
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
require 'erb'
|
require "erb"
|
||||||
require 'pathname'
|
require "pathname"
|
||||||
desc 'Install Capistrano, cap install STAGES=staging,production'
|
desc "Install Capistrano, cap install STAGES=staging,production"
|
||||||
task :install do
|
task :install do
|
||||||
envs = ENV['STAGES'] || 'staging,production'
|
envs = ENV["STAGES"] || "staging,production"
|
||||||
|
|
||||||
tasks_dir = Pathname.new('lib/capistrano/tasks')
|
tasks_dir = Pathname.new("lib/capistrano/tasks")
|
||||||
config_dir = Pathname.new('config')
|
config_dir = Pathname.new("config")
|
||||||
deploy_dir = config_dir.join('deploy')
|
deploy_dir = config_dir.join("deploy")
|
||||||
|
|
||||||
deploy_rb = File.expand_path("../../templates/deploy.rb.erb", __FILE__)
|
deploy_rb = File.expand_path("../../templates/deploy.rb.erb", __FILE__)
|
||||||
stage_rb = File.expand_path("../../templates/stage.rb.erb", __FILE__)
|
stage_rb = File.expand_path("../../templates/stage.rb.erb", __FILE__)
|
||||||
|
@ -14,14 +14,14 @@ task :install do
|
||||||
|
|
||||||
mkdir_p deploy_dir
|
mkdir_p deploy_dir
|
||||||
|
|
||||||
entries = [{:template => deploy_rb, :file => config_dir.join('deploy.rb')}]
|
entries = [{:template => deploy_rb, :file => config_dir.join("deploy.rb")}]
|
||||||
entries += envs.split(',').map { |stage| {:template => stage_rb, :file => deploy_dir.join("#{stage}.rb")} }
|
entries += envs.split(",").map { |stage| {:template => stage_rb, :file => deploy_dir.join("#{stage}.rb")} }
|
||||||
|
|
||||||
entries.each do |entry|
|
entries.each do |entry|
|
||||||
if File.exist?(entry[:file])
|
if File.exist?(entry[:file])
|
||||||
warn "[skip] #{entry[:file]} already exists"
|
warn "[skip] #{entry[:file]} already exists"
|
||||||
else
|
else
|
||||||
File.open(entry[:file], 'w+') do |f|
|
File.open(entry[:file], "w+") do |f|
|
||||||
f.write(ERB.new(File.read(entry[:template])).result(binding))
|
f.write(ERB.new(File.read(entry[:template])).result(binding))
|
||||||
puts I18n.t(:written_file, :scope => :capistrano, :file => entry[:file])
|
puts I18n.t(:written_file, :scope => :capistrano, :file => entry[:file])
|
||||||
end
|
end
|
||||||
|
@ -30,11 +30,11 @@ task :install do
|
||||||
|
|
||||||
mkdir_p tasks_dir
|
mkdir_p tasks_dir
|
||||||
|
|
||||||
if File.exist?('Capfile')
|
if File.exist?("Capfile")
|
||||||
warn "[skip] Capfile already exists"
|
warn "[skip] Capfile already exists"
|
||||||
else
|
else
|
||||||
FileUtils.cp(capfile, 'Capfile')
|
FileUtils.cp(capfile, "Capfile")
|
||||||
puts I18n.t(:written_file, :scope => :capistrano, :file => 'Capfile')
|
puts I18n.t(:written_file, :scope => :capistrano, :file => "Capfile")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,14 +3,14 @@ namespace :svn do
|
||||||
@strategy ||= Capistrano::Svn.new(self, fetch(:svn_strategy, Capistrano::Svn::DefaultStrategy))
|
@strategy ||= Capistrano::Svn.new(self, fetch(:svn_strategy, Capistrano::Svn::DefaultStrategy))
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'Check that the repo is reachable'
|
desc "Check that the repo is reachable"
|
||||||
task :check do
|
task :check do
|
||||||
on release_roles :all do
|
on release_roles :all do
|
||||||
strategy.check
|
strategy.check
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'Clone the repo to the cache'
|
desc "Clone the repo to the cache"
|
||||||
task :clone do
|
task :clone do
|
||||||
on release_roles :all do
|
on release_roles :all do
|
||||||
if strategy.test
|
if strategy.test
|
||||||
|
@ -23,7 +23,7 @@ namespace :svn do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'Pull changes from the remote repo'
|
desc "Pull changes from the remote repo"
|
||||||
task :update => :'svn:clone' do
|
task :update => :'svn:clone' do
|
||||||
on release_roles :all do
|
on release_roles :all do
|
||||||
within repo_path do
|
within repo_path do
|
||||||
|
@ -32,7 +32,7 @@ namespace :svn do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'Copy repo to releases'
|
desc "Copy repo to releases"
|
||||||
task :create_release => :'svn:update' do
|
task :create_release => :'svn:update' do
|
||||||
on release_roles :all do
|
on release_roles :all do
|
||||||
within repo_path do
|
within repo_path do
|
||||||
|
@ -41,7 +41,7 @@ namespace :svn do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'Determine the revision that will be deployed'
|
desc "Determine the revision that will be deployed"
|
||||||
task :set_current_revision do
|
task :set_current_revision do
|
||||||
on release_roles :all do
|
on release_roles :all do
|
||||||
within repo_path do
|
within repo_path do
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
# Load DSL and set up stages
|
# Load DSL and set up stages
|
||||||
require 'capistrano/setup'
|
require "capistrano/setup"
|
||||||
|
|
||||||
# Include default deployment tasks
|
# Include default deployment tasks
|
||||||
require 'capistrano/deploy'
|
require "capistrano/deploy"
|
||||||
|
|
||||||
# Include tasks from other gems included in your Gemfile
|
# Include tasks from other gems included in your Gemfile
|
||||||
#
|
#
|
||||||
|
@ -24,4 +24,4 @@ require 'capistrano/deploy'
|
||||||
# require 'capistrano/passenger'
|
# require 'capistrano/passenger'
|
||||||
|
|
||||||
# Load custom tasks from `lib/capistrano/tasks` if you have any defined
|
# Load custom tasks from `lib/capistrano/tasks` if you have any defined
|
||||||
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
|
Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r }
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
require 'rake/file_creation_task'
|
require "rake/file_creation_task"
|
||||||
|
|
||||||
module Capistrano
|
module Capistrano
|
||||||
class UploadTask < Rake::FileCreationTask
|
class UploadTask < Rake::FileCreationTask
|
||||||
|
|
|
@ -26,11 +26,11 @@ module Capistrano
|
||||||
end
|
end
|
||||||
|
|
||||||
def available
|
def available
|
||||||
Gem::Dependency.new('cap', version)
|
Gem::Dependency.new("cap", version)
|
||||||
end
|
end
|
||||||
|
|
||||||
def requested
|
def requested
|
||||||
Gem::Dependency.new('cap', current_version)
|
Gem::Dependency.new("cap", current_version)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
require 'spec_helper'
|
require "spec_helper"
|
||||||
|
|
||||||
describe Capistrano::DSL do
|
describe Capistrano::DSL do
|
||||||
|
|
||||||
|
@ -8,157 +8,157 @@ describe Capistrano::DSL do
|
||||||
Capistrano::Configuration.reset!
|
Capistrano::Configuration.reset!
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'setting and fetching hosts' do
|
describe "setting and fetching hosts" do
|
||||||
describe 'when defining a host using the `server` syntax' do
|
describe "when defining a host using the `server` syntax" do
|
||||||
before do
|
before do
|
||||||
dsl.server 'example1.com', :roles => %w{web}, :active => true
|
dsl.server "example1.com", :roles => %w{web}, :active => true
|
||||||
dsl.server 'example2.com', :roles => %w{web}
|
dsl.server "example2.com", :roles => %w{web}
|
||||||
dsl.server 'example3.com', :roles => %w{app web}, :active => true
|
dsl.server "example3.com", :roles => %w{app web}, :active => true
|
||||||
dsl.server 'example4.com', :roles => %w{app}, :primary => true
|
dsl.server "example4.com", :roles => %w{app}, :primary => true
|
||||||
dsl.server 'example5.com', :roles => %w{db}, :no_release => true, :active => true
|
dsl.server "example5.com", :roles => %w{db}, :no_release => true, :active => true
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'fetching all servers' do
|
describe "fetching all servers" do
|
||||||
subject { dsl.roles(:all) }
|
subject { dsl.roles(:all) }
|
||||||
|
|
||||||
it 'returns all servers' do
|
it "returns all servers" do
|
||||||
expect(subject.map(&:hostname)).to eq %w{example1.com example2.com example3.com example4.com example5.com}
|
expect(subject.map(&:hostname)).to eq %w{example1.com example2.com example3.com example4.com example5.com}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'fetching all release servers' do
|
describe "fetching all release servers" do
|
||||||
|
|
||||||
context 'with no additional options' do
|
context "with no additional options" do
|
||||||
subject { dsl.release_roles(:all) }
|
subject { dsl.release_roles(:all) }
|
||||||
|
|
||||||
it 'returns all release servers' do
|
it "returns all release servers" do
|
||||||
expect(subject.map(&:hostname)).to eq %w{example1.com example2.com example3.com example4.com}
|
expect(subject.map(&:hostname)).to eq %w{example1.com example2.com example3.com example4.com}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with property filter options' do
|
context "with property filter options" do
|
||||||
subject { dsl.release_roles(:all, :filter => :active) }
|
subject { dsl.release_roles(:all, :filter => :active) }
|
||||||
|
|
||||||
it 'returns all release servers that match the property filter' do
|
it "returns all release servers that match the property filter" do
|
||||||
expect(subject.map(&:hostname)).to eq %w{example1.com example3.com}
|
expect(subject.map(&:hostname)).to eq %w{example1.com example3.com}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'fetching servers by multiple roles' do
|
describe "fetching servers by multiple roles" do
|
||||||
it "does not confuse the last role with options" do
|
it "does not confuse the last role with options" do
|
||||||
expect(dsl.roles(:app, :web).count).to eq 4
|
expect(dsl.roles(:app, :web).count).to eq 4
|
||||||
expect(dsl.roles(:app, :web, :filter => :active).count).to eq 2
|
expect(dsl.roles(:app, :web, :filter => :active).count).to eq 2
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'fetching servers by role' do
|
describe "fetching servers by role" do
|
||||||
subject { dsl.roles(:app) }
|
subject { dsl.roles(:app) }
|
||||||
|
|
||||||
it 'returns the servers' do
|
it "returns the servers" do
|
||||||
expect(subject.map(&:hostname)).to eq %w{example3.com example4.com}
|
expect(subject.map(&:hostname)).to eq %w{example3.com example4.com}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'fetching servers by an array of roles' do
|
describe "fetching servers by an array of roles" do
|
||||||
subject { dsl.roles([:app]) }
|
subject { dsl.roles([:app]) }
|
||||||
|
|
||||||
it 'returns the servers' do
|
it "returns the servers" do
|
||||||
expect(subject.map(&:hostname)).to eq %w{example3.com example4.com}
|
expect(subject.map(&:hostname)).to eq %w{example3.com example4.com}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'fetching filtered servers by role' do
|
describe "fetching filtered servers by role" do
|
||||||
subject { dsl.roles(:app, :filter => :active) }
|
subject { dsl.roles(:app, :filter => :active) }
|
||||||
|
|
||||||
it 'returns the servers' do
|
it "returns the servers" do
|
||||||
expect(subject.map(&:hostname)).to eq %w{example3.com}
|
expect(subject.map(&:hostname)).to eq %w{example3.com}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'fetching selected servers by role' do
|
describe "fetching selected servers by role" do
|
||||||
subject { dsl.roles(:app, :select => :active) }
|
subject { dsl.roles(:app, :select => :active) }
|
||||||
|
|
||||||
it 'returns the servers' do
|
it "returns the servers" do
|
||||||
expect(subject.map(&:hostname)).to eq %w{example3.com}
|
expect(subject.map(&:hostname)).to eq %w{example3.com}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'fetching the primary server by role' do
|
describe "fetching the primary server by role" do
|
||||||
context 'when inferring primary status based on order' do
|
context "when inferring primary status based on order" do
|
||||||
subject { dsl.primary(:web) }
|
subject { dsl.primary(:web) }
|
||||||
it 'returns the servers' do
|
it "returns the servers" do
|
||||||
expect(subject.hostname).to eq 'example1.com'
|
expect(subject.hostname).to eq "example1.com"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when the attribute `primary` is explicitly set' do
|
context "when the attribute `primary` is explicitly set" do
|
||||||
subject { dsl.primary(:app) }
|
subject { dsl.primary(:app) }
|
||||||
it 'returns the servers' do
|
it "returns the servers" do
|
||||||
expect(subject.hostname).to eq 'example4.com'
|
expect(subject.hostname).to eq "example4.com"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'setting an internal host filter' do
|
describe "setting an internal host filter" do
|
||||||
subject { dsl.roles(:app) }
|
subject { dsl.roles(:app) }
|
||||||
it 'is ignored' do
|
it "is ignored" do
|
||||||
dsl.set :filter, { :host => 'example3.com' }
|
dsl.set :filter, { :host => "example3.com" }
|
||||||
expect(subject.map(&:hostname)).to eq(['example3.com', 'example4.com'])
|
expect(subject.map(&:hostname)).to eq(["example3.com", "example4.com"])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'setting an internal role filter' do
|
describe "setting an internal role filter" do
|
||||||
subject { dsl.roles(:app) }
|
subject { dsl.roles(:app) }
|
||||||
it 'ignores it' do
|
it "ignores it" do
|
||||||
dsl.set :filter, { :role => :web }
|
dsl.set :filter, { :role => :web }
|
||||||
expect(subject.map(&:hostname)).to eq(['example3.com','example4.com'])
|
expect(subject.map(&:hostname)).to eq(["example3.com","example4.com"])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'setting an internal host and role filter' do
|
describe "setting an internal host and role filter" do
|
||||||
subject { dsl.roles(:app) }
|
subject { dsl.roles(:app) }
|
||||||
it 'ignores it' do
|
it "ignores it" do
|
||||||
dsl.set :filter, { :role => :web, :host => 'example1.com' }
|
dsl.set :filter, { :role => :web, :host => "example1.com" }
|
||||||
expect(subject.map(&:hostname)).to eq(['example3.com','example4.com'])
|
expect(subject.map(&:hostname)).to eq(["example3.com","example4.com"])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'setting an internal regexp host filter' do
|
describe "setting an internal regexp host filter" do
|
||||||
subject { dsl.roles(:all) }
|
subject { dsl.roles(:all) }
|
||||||
it 'is ignored' do
|
it "is ignored" do
|
||||||
dsl.set :filter, { :host => /1/ }
|
dsl.set :filter, { :host => /1/ }
|
||||||
expect(subject.map(&:hostname)).to eq(%w{example1.com example2.com example3.com example4.com example5.com})
|
expect(subject.map(&:hostname)).to eq(%w{example1.com example2.com example3.com example4.com example5.com})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'setting an internal hosts filter' do
|
describe "setting an internal hosts filter" do
|
||||||
subject { dsl.roles(:app) }
|
subject { dsl.roles(:app) }
|
||||||
it 'is ignored' do
|
it "is ignored" do
|
||||||
dsl.set :filter, { :hosts => 'example3.com' }
|
dsl.set :filter, { :hosts => "example3.com" }
|
||||||
expect(subject.map(&:hostname)).to eq(['example3.com', 'example4.com'])
|
expect(subject.map(&:hostname)).to eq(["example3.com", "example4.com"])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'setting an internal roles filter' do
|
describe "setting an internal roles filter" do
|
||||||
subject { dsl.roles(:app) }
|
subject { dsl.roles(:app) }
|
||||||
it 'ignores it' do
|
it "ignores it" do
|
||||||
dsl.set :filter, { :roles => :web }
|
dsl.set :filter, { :roles => :web }
|
||||||
expect(subject.map(&:hostname)).to eq(['example3.com','example4.com'])
|
expect(subject.map(&:hostname)).to eq(["example3.com","example4.com"])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'setting an internal hosts and roles filter' do
|
describe "setting an internal hosts and roles filter" do
|
||||||
subject { dsl.roles(:app) }
|
subject { dsl.roles(:app) }
|
||||||
it 'ignores it' do
|
it "ignores it" do
|
||||||
dsl.set :filter, { :roles => :web, :hosts => 'example1.com' }
|
dsl.set :filter, { :roles => :web, :hosts => "example1.com" }
|
||||||
expect(subject.map(&:hostname)).to eq(['example3.com','example4.com'])
|
expect(subject.map(&:hostname)).to eq(["example3.com","example4.com"])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'setting an internal regexp hosts filter' do
|
describe "setting an internal regexp hosts filter" do
|
||||||
subject { dsl.roles(:all) }
|
subject { dsl.roles(:all) }
|
||||||
it 'is ignored' do
|
it "is ignored" do
|
||||||
dsl.set :filter, { :hosts => /1/ }
|
dsl.set :filter, { :hosts => /1/ }
|
||||||
expect(subject.map(&:hostname)).to eq(%w{example1.com example2.com example3.com example4.com example5.com})
|
expect(subject.map(&:hostname)).to eq(%w{example1.com example2.com example3.com example4.com example5.com})
|
||||||
end
|
end
|
||||||
|
@ -166,15 +166,15 @@ describe Capistrano::DSL do
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'when defining role with reserved name' do
|
describe "when defining role with reserved name" do
|
||||||
it 'fails with ArgumentError' do
|
it "fails with ArgumentError" do
|
||||||
expect {
|
expect {
|
||||||
dsl.role :all, %w{example1.com}
|
dsl.role :all, %w{example1.com}
|
||||||
}.to raise_error(ArgumentError, "all reserved name for role. Please choose another name")
|
}.to raise_error(ArgumentError, "all reserved name for role. Please choose another name")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'when defining hosts using the `role` syntax' do
|
describe "when defining hosts using the `role` syntax" do
|
||||||
before do
|
before do
|
||||||
dsl.role :web, %w{example1.com example2.com example3.com}
|
dsl.role :web, %w{example1.com example2.com example3.com}
|
||||||
dsl.role :web, %w{example1.com}, :active => true
|
dsl.role :web, %w{example1.com}, :active => true
|
||||||
|
@ -184,109 +184,109 @@ describe Capistrano::DSL do
|
||||||
dsl.role :db, %w{example5.com}, :no_release => true
|
dsl.role :db, %w{example5.com}, :no_release => true
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'fetching all servers' do
|
describe "fetching all servers" do
|
||||||
subject { dsl.roles(:all) }
|
subject { dsl.roles(:all) }
|
||||||
|
|
||||||
it 'returns all servers' do
|
it "returns all servers" do
|
||||||
expect(subject.map(&:hostname)).to eq %w{example1.com example2.com example3.com example4.com example5.com}
|
expect(subject.map(&:hostname)).to eq %w{example1.com example2.com example3.com example4.com example5.com}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'fetching all release servers' do
|
describe "fetching all release servers" do
|
||||||
|
|
||||||
context 'with no additional options' do
|
context "with no additional options" do
|
||||||
subject { dsl.release_roles(:all) }
|
subject { dsl.release_roles(:all) }
|
||||||
|
|
||||||
it 'returns all release servers' do
|
it "returns all release servers" do
|
||||||
expect(subject.map(&:hostname)).to eq %w{example1.com example2.com example3.com example4.com}
|
expect(subject.map(&:hostname)).to eq %w{example1.com example2.com example3.com example4.com}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with filter options' do
|
context "with filter options" do
|
||||||
subject { dsl.release_roles(:all, :filter => :active) }
|
subject { dsl.release_roles(:all, :filter => :active) }
|
||||||
|
|
||||||
it 'returns all release servers that match the filter' do
|
it "returns all release servers that match the filter" do
|
||||||
expect(subject.map(&:hostname)).to eq %w{example1.com example3.com}
|
expect(subject.map(&:hostname)).to eq %w{example1.com example3.com}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
describe 'fetching servers by role' do
|
describe "fetching servers by role" do
|
||||||
subject { dsl.roles(:app) }
|
subject { dsl.roles(:app) }
|
||||||
|
|
||||||
it 'returns the servers' do
|
it "returns the servers" do
|
||||||
expect(subject.map(&:hostname)).to eq %w{example3.com example4.com}
|
expect(subject.map(&:hostname)).to eq %w{example3.com example4.com}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'fetching servers by an array of roles' do
|
describe "fetching servers by an array of roles" do
|
||||||
subject { dsl.roles([:app]) }
|
subject { dsl.roles([:app]) }
|
||||||
|
|
||||||
it 'returns the servers' do
|
it "returns the servers" do
|
||||||
expect(subject.map(&:hostname)).to eq %w{example3.com example4.com}
|
expect(subject.map(&:hostname)).to eq %w{example3.com example4.com}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'fetching filtered servers by role' do
|
describe "fetching filtered servers by role" do
|
||||||
subject { dsl.roles(:app, :filter => :active) }
|
subject { dsl.roles(:app, :filter => :active) }
|
||||||
|
|
||||||
it 'returns the servers' do
|
it "returns the servers" do
|
||||||
expect(subject.map(&:hostname)).to eq %w{example3.com}
|
expect(subject.map(&:hostname)).to eq %w{example3.com}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'fetching selected servers by role' do
|
describe "fetching selected servers by role" do
|
||||||
subject { dsl.roles(:app, :select => :active) }
|
subject { dsl.roles(:app, :select => :active) }
|
||||||
|
|
||||||
it 'returns the servers' do
|
it "returns the servers" do
|
||||||
expect(subject.map(&:hostname)).to eq %w{example3.com}
|
expect(subject.map(&:hostname)).to eq %w{example3.com}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'fetching the primary server by role' do
|
describe "fetching the primary server by role" do
|
||||||
context 'when inferring primary status based on order' do
|
context "when inferring primary status based on order" do
|
||||||
subject { dsl.primary(:web) }
|
subject { dsl.primary(:web) }
|
||||||
it 'returns the servers' do
|
it "returns the servers" do
|
||||||
expect(subject.hostname).to eq 'example1.com'
|
expect(subject.hostname).to eq "example1.com"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when the attribute `primary` is explicity set' do
|
context "when the attribute `primary` is explicity set" do
|
||||||
subject { dsl.primary(:app) }
|
subject { dsl.primary(:app) }
|
||||||
it 'returns the servers' do
|
it "returns the servers" do
|
||||||
expect(subject.hostname).to eq 'example4.com'
|
expect(subject.hostname).to eq "example4.com"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'when defining a host using a combination of the `server` and `role` syntax' do
|
describe "when defining a host using a combination of the `server` and `role` syntax" do
|
||||||
|
|
||||||
before do
|
before do
|
||||||
dsl.server 'db@example1.com:1234', :roles => %w{db}, :active => true
|
dsl.server "db@example1.com:1234", :roles => %w{db}, :active => true
|
||||||
dsl.server 'root@example1.com:1234', :roles => %w{web}, :active => true
|
dsl.server "root@example1.com:1234", :roles => %w{web}, :active => true
|
||||||
dsl.server 'example1.com:5678', :roles => %w{web}, :active => true
|
dsl.server "example1.com:5678", :roles => %w{web}, :active => true
|
||||||
dsl.role :app, %w{deployer@example1.com:1234}
|
dsl.role :app, %w{deployer@example1.com:1234}
|
||||||
dsl.role :app, %w{example1.com:5678}
|
dsl.role :app, %w{example1.com:5678}
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'fetching all servers' do
|
describe "fetching all servers" do
|
||||||
it 'creates one server per hostname, ignoring user combinations' do
|
it "creates one server per hostname, ignoring user combinations" do
|
||||||
expect(dsl.roles(:all).size).to eq(2)
|
expect(dsl.roles(:all).size).to eq(2)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'fetching servers for a role' do
|
describe "fetching servers for a role" do
|
||||||
it 'roles defined using the `server` syntax are included' do
|
it "roles defined using the `server` syntax are included" do
|
||||||
as = dsl.roles(:web).map { |server| "#{server.user}@#{server.hostname}:#{server.port}" }
|
as = dsl.roles(:web).map { |server| "#{server.user}@#{server.hostname}:#{server.port}" }
|
||||||
expect(as.size).to eq(2)
|
expect(as.size).to eq(2)
|
||||||
expect(as[0]).to eq("deployer@example1.com:1234")
|
expect(as[0]).to eq("deployer@example1.com:1234")
|
||||||
expect(as[1]).to eq("@example1.com:5678")
|
expect(as[1]).to eq("@example1.com:5678")
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'roles defined using the `role` syntax are included' do
|
it "roles defined using the `role` syntax are included" do
|
||||||
as = dsl.roles(:app).map { |server| "#{server.user}@#{server.hostname}:#{server.port}" }
|
as = dsl.roles(:app).map { |server| "#{server.user}@#{server.hostname}:#{server.port}" }
|
||||||
expect(as.size).to eq(2)
|
expect(as.size).to eq(2)
|
||||||
expect(as[0]).to eq("deployer@example1.com:1234")
|
expect(as[0]).to eq("deployer@example1.com:1234")
|
||||||
|
@ -296,19 +296,19 @@ describe Capistrano::DSL do
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'when setting user and port' do
|
describe "when setting user and port" do
|
||||||
subject { dsl.roles(:all).map { |server| "#{server.user}@#{server.hostname}:#{server.port}" }.first }
|
subject { dsl.roles(:all).map { |server| "#{server.user}@#{server.hostname}:#{server.port}" }.first }
|
||||||
|
|
||||||
describe "using the :user property" do
|
describe "using the :user property" do
|
||||||
it "takes precedence over in the host string" do
|
it "takes precedence over in the host string" do
|
||||||
dsl.server 'db@example1.com:1234', :roles => %w{db}, :active => true, :user => 'brian'
|
dsl.server "db@example1.com:1234", :roles => %w{db}, :active => true, :user => "brian"
|
||||||
expect(subject).to eq("brian@example1.com:1234")
|
expect(subject).to eq("brian@example1.com:1234")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "using the :port property" do
|
describe "using the :port property" do
|
||||||
it "takes precedence over in the host string" do
|
it "takes precedence over in the host string" do
|
||||||
dsl.server 'db@example1.com:9090', :roles => %w{db}, :active => true, :port => 1234
|
dsl.server "db@example1.com:9090", :roles => %w{db}, :active => true, :port => 1234
|
||||||
expect(subject).to eq("db@example1.com:1234")
|
expect(subject).to eq("db@example1.com:1234")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -316,49 +316,49 @@ describe Capistrano::DSL do
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'setting and fetching variables' do
|
describe "setting and fetching variables" do
|
||||||
|
|
||||||
before do
|
before do
|
||||||
dsl.set :scm, :git
|
dsl.set :scm, :git
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'without a default' do
|
context "without a default" do
|
||||||
context 'when the variables is defined' do
|
context "when the variables is defined" do
|
||||||
it 'returns the variable' do
|
it "returns the variable" do
|
||||||
expect(dsl.fetch(:scm)).to eq :git
|
expect(dsl.fetch(:scm)).to eq :git
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when the variables is undefined' do
|
context "when the variables is undefined" do
|
||||||
it 'returns nil' do
|
it "returns nil" do
|
||||||
expect(dsl.fetch(:source_control)).to be_nil
|
expect(dsl.fetch(:source_control)).to be_nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with a default' do
|
context "with a default" do
|
||||||
context 'when the variables is defined' do
|
context "when the variables is defined" do
|
||||||
it 'returns the variable' do
|
it "returns the variable" do
|
||||||
expect(dsl.fetch(:scm, :svn)).to eq :git
|
expect(dsl.fetch(:scm, :svn)).to eq :git
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when the variables is undefined' do
|
context "when the variables is undefined" do
|
||||||
it 'returns the default' do
|
it "returns the default" do
|
||||||
expect(dsl.fetch(:source_control, :svn)).to eq :svn
|
expect(dsl.fetch(:source_control, :svn)).to eq :svn
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with a block' do
|
context "with a block" do
|
||||||
context 'when the variables is defined' do
|
context "when the variables is defined" do
|
||||||
it 'returns the variable' do
|
it "returns the variable" do
|
||||||
expect(dsl.fetch(:scm) { :svn }).to eq :git
|
expect(dsl.fetch(:scm) { :svn }).to eq :git
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when the variables is undefined' do
|
context "when the variables is undefined" do
|
||||||
it 'calls the block' do
|
it "calls the block" do
|
||||||
expect(dsl.fetch(:source_control) { :svn }).to eq :svn
|
expect(dsl.fetch(:source_control) { :svn }).to eq :svn
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -366,63 +366,63 @@ describe Capistrano::DSL do
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'asking for a variable' do
|
describe "asking for a variable" do
|
||||||
before do
|
before do
|
||||||
dsl.ask(:scm, :svn)
|
dsl.ask(:scm, :svn)
|
||||||
$stdout.stubs(:print)
|
$stdout.stubs(:print)
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'variable is provided' do
|
context "variable is provided" do
|
||||||
before do
|
before do
|
||||||
$stdin.expects(:gets).returns('git')
|
$stdin.expects(:gets).returns("git")
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'sets the input as the variable' do
|
it "sets the input as the variable" do
|
||||||
expect(dsl.fetch(:scm)).to eq 'git'
|
expect(dsl.fetch(:scm)).to eq "git"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'variable is not provided' do
|
context "variable is not provided" do
|
||||||
before do
|
before do
|
||||||
$stdin.expects(:gets).returns('')
|
$stdin.expects(:gets).returns("")
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'sets the variable as the default' do
|
it "sets the variable as the default" do
|
||||||
expect(dsl.fetch(:scm)).to eq :svn
|
expect(dsl.fetch(:scm)).to eq :svn
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'checking for presence' do
|
describe "checking for presence" do
|
||||||
subject { dsl.any? :linked_files }
|
subject { dsl.any? :linked_files }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
dsl.set(:linked_files, linked_files)
|
dsl.set(:linked_files, linked_files)
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'variable is an non-empty array' do
|
context "variable is an non-empty array" do
|
||||||
let(:linked_files) { %w{1} }
|
let(:linked_files) { %w{1} }
|
||||||
|
|
||||||
it { expect(subject).to be_truthy }
|
it { expect(subject).to be_truthy }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'variable is an empty array' do
|
context "variable is an empty array" do
|
||||||
let(:linked_files) { [] }
|
let(:linked_files) { [] }
|
||||||
it { expect(subject).to be_falsey }
|
it { expect(subject).to be_falsey }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'variable exists, is not an array' do
|
context "variable exists, is not an array" do
|
||||||
let(:linked_files) { stub }
|
let(:linked_files) { stub }
|
||||||
it { expect(subject).to be_truthy }
|
it { expect(subject).to be_truthy }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'variable is nil' do
|
context "variable is nil" do
|
||||||
let(:linked_files) { nil }
|
let(:linked_files) { nil }
|
||||||
it { expect(subject).to be_falsey }
|
it { expect(subject).to be_falsey }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'configuration SSHKit' do
|
describe "configuration SSHKit" do
|
||||||
let(:config) { SSHKit.config }
|
let(:config) { SSHKit.config }
|
||||||
let(:backend) { SSHKit.config.backend.config }
|
let(:backend) { SSHKit.config.backend.config }
|
||||||
let(:default_env) { { :rails_env => :production } }
|
let(:default_env) { { :rails_env => :production } }
|
||||||
|
@ -441,27 +441,27 @@ describe Capistrano::DSL do
|
||||||
dsl.configure_backend
|
dsl.configure_backend
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'sets the output' do
|
it "sets the output" do
|
||||||
expect(config.output).to be_a SSHKit::Formatter::Dot
|
expect(config.output).to be_a SSHKit::Formatter::Dot
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'sets the output verbosity' do
|
it "sets the output verbosity" do
|
||||||
expect(config.output_verbosity).to eq 0
|
expect(config.output_verbosity).to eq 0
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'sets the default env' do
|
it "sets the default env" do
|
||||||
expect(config.default_env).to eq default_env
|
expect(config.default_env).to eq default_env
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'sets the backend pty' do
|
it "sets the backend pty" do
|
||||||
expect(backend.pty).to be_truthy
|
expect(backend.pty).to be_truthy
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'sets the backend connection timeout' do
|
it "sets the backend connection timeout" do
|
||||||
expect(backend.connection_timeout).to eq 10
|
expect(backend.connection_timeout).to eq 10
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'sets the backend ssh_options' do
|
it "sets the backend ssh_options" do
|
||||||
expect(backend.ssh_options[:keys]).to eq %w(/home/user/.ssh/id_rsa)
|
expect(backend.ssh_options[:keys]).to eq %w(/home/user/.ssh/id_rsa)
|
||||||
expect(backend.ssh_options[:forward_agent]).to eq false
|
expect(backend.ssh_options[:forward_agent]).to eq false
|
||||||
expect(backend.ssh_options[:auth_methods]).to eq %w(publickey password)
|
expect(backend.ssh_options[:auth_methods]).to eq %w(publickey password)
|
||||||
|
@ -469,73 +469,73 @@ describe Capistrano::DSL do
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'on()' do
|
describe "on()" do
|
||||||
|
|
||||||
describe "when passed server objects" do
|
describe "when passed server objects" do
|
||||||
|
|
||||||
before do
|
before do
|
||||||
dsl.server 'example1.com', :roles => %w{web}, :active => true
|
dsl.server "example1.com", :roles => %w{web}, :active => true
|
||||||
dsl.server 'example2.com', :roles => %w{web}
|
dsl.server "example2.com", :roles => %w{web}
|
||||||
dsl.server 'example3.com', :roles => %w{app web}, :active => true
|
dsl.server "example3.com", :roles => %w{app web}, :active => true
|
||||||
dsl.server 'example4.com', :roles => %w{app}, :primary => true
|
dsl.server "example4.com", :roles => %w{app}, :primary => true
|
||||||
dsl.server 'example5.com', :roles => %w{db}, :no_release => true
|
dsl.server "example5.com", :roles => %w{db}, :no_release => true
|
||||||
@coordinator = mock('coordinator')
|
@coordinator = mock("coordinator")
|
||||||
@coordinator.expects(:each).returns(nil)
|
@coordinator.expects(:each).returns(nil)
|
||||||
ENV.delete 'ROLES'
|
ENV.delete "ROLES"
|
||||||
ENV.delete 'HOSTS'
|
ENV.delete "HOSTS"
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'filters by role from the :filter variable' do
|
it "filters by role from the :filter variable" do
|
||||||
hosts = dsl.roles(:web)
|
hosts = dsl.roles(:web)
|
||||||
all = dsl.roles(:all)
|
all = dsl.roles(:all)
|
||||||
SSHKit::Coordinator.expects(:new).with(hosts).returns(@coordinator)
|
SSHKit::Coordinator.expects(:new).with(hosts).returns(@coordinator)
|
||||||
dsl.set :filter, { :role => 'web' }
|
dsl.set :filter, { :role => "web" }
|
||||||
dsl.on(all)
|
dsl.on(all)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'filters by host and role from the :filter variable' do
|
it "filters by host and role from the :filter variable" do
|
||||||
all = dsl.roles(:all)
|
all = dsl.roles(:all)
|
||||||
SSHKit::Coordinator.expects(:new).with([]).returns(@coordinator)
|
SSHKit::Coordinator.expects(:new).with([]).returns(@coordinator)
|
||||||
dsl.set :filter, { :role => 'db', :host => 'example3.com' }
|
dsl.set :filter, { :role => "db", :host => "example3.com" }
|
||||||
dsl.on(all)
|
dsl.on(all)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'filters by roles from the :filter variable' do
|
it "filters by roles from the :filter variable" do
|
||||||
hosts = dsl.roles(:web)
|
hosts = dsl.roles(:web)
|
||||||
all = dsl.roles(:all)
|
all = dsl.roles(:all)
|
||||||
SSHKit::Coordinator.expects(:new).with(hosts).returns(@coordinator)
|
SSHKit::Coordinator.expects(:new).with(hosts).returns(@coordinator)
|
||||||
dsl.set :filter, { :roles => 'web' }
|
dsl.set :filter, { :roles => "web" }
|
||||||
dsl.on(all)
|
dsl.on(all)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'filters by hosts and roles from the :filter variable' do
|
it "filters by hosts and roles from the :filter variable" do
|
||||||
all = dsl.roles(:all)
|
all = dsl.roles(:all)
|
||||||
SSHKit::Coordinator.expects(:new).with([]).returns(@coordinator)
|
SSHKit::Coordinator.expects(:new).with([]).returns(@coordinator)
|
||||||
dsl.set :filter, { :roles => 'db', :hosts => 'example3.com' }
|
dsl.set :filter, { :roles => "db", :hosts => "example3.com" }
|
||||||
dsl.on(all)
|
dsl.on(all)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'filters from ENV[ROLES]' do
|
it "filters from ENV[ROLES]" do
|
||||||
hosts = dsl.roles(:db)
|
hosts = dsl.roles(:db)
|
||||||
all = dsl.roles(:all)
|
all = dsl.roles(:all)
|
||||||
SSHKit::Coordinator.expects(:new).with(hosts).returns(@coordinator)
|
SSHKit::Coordinator.expects(:new).with(hosts).returns(@coordinator)
|
||||||
ENV['ROLES'] = 'db'
|
ENV["ROLES"] = "db"
|
||||||
dsl.on(all)
|
dsl.on(all)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'filters from ENV[HOSTS]' do
|
it "filters from ENV[HOSTS]" do
|
||||||
hosts = dsl.roles(:db)
|
hosts = dsl.roles(:db)
|
||||||
all = dsl.roles(:all)
|
all = dsl.roles(:all)
|
||||||
SSHKit::Coordinator.expects(:new).with(hosts).returns(@coordinator)
|
SSHKit::Coordinator.expects(:new).with(hosts).returns(@coordinator)
|
||||||
ENV['HOSTS'] = 'example5.com'
|
ENV["HOSTS"] = "example5.com"
|
||||||
dsl.on(all)
|
dsl.on(all)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'filters by ENV[HOSTS] && ENV[ROLES]' do
|
it "filters by ENV[HOSTS] && ENV[ROLES]" do
|
||||||
all = dsl.roles(:all)
|
all = dsl.roles(:all)
|
||||||
SSHKit::Coordinator.expects(:new).with([]).returns(@coordinator)
|
SSHKit::Coordinator.expects(:new).with([]).returns(@coordinator)
|
||||||
ENV['HOSTS'] = 'example5.com'
|
ENV["HOSTS"] = "example5.com"
|
||||||
ENV['ROLES'] = 'web'
|
ENV["ROLES"] = "web"
|
||||||
dsl.on(all)
|
dsl.on(all)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -544,105 +544,105 @@ describe Capistrano::DSL do
|
||||||
describe "when passed server literal names" do
|
describe "when passed server literal names" do
|
||||||
|
|
||||||
before do
|
before do
|
||||||
ENV.delete 'ROLES'
|
ENV.delete "ROLES"
|
||||||
ENV.delete 'HOSTS'
|
ENV.delete "HOSTS"
|
||||||
@coordinator = mock('coordinator')
|
@coordinator = mock("coordinator")
|
||||||
@coordinator.expects(:each).returns(nil)
|
@coordinator.expects(:each).returns(nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "selects nothing when a role filter is present" do
|
it "selects nothing when a role filter is present" do
|
||||||
dsl.set :filter, { :role => 'web' }
|
dsl.set :filter, { :role => "web" }
|
||||||
SSHKit::Coordinator.expects(:new).with([]).returns(@coordinator)
|
SSHKit::Coordinator.expects(:new).with([]).returns(@coordinator)
|
||||||
dsl.on('my.server')
|
dsl.on("my.server")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "selects using the string when a host filter is present" do
|
it "selects using the string when a host filter is present" do
|
||||||
dsl.set :filter, { :host => 'server.local' }
|
dsl.set :filter, { :host => "server.local" }
|
||||||
SSHKit::Coordinator.expects(:new).with(['server.local']).returns(@coordinator)
|
SSHKit::Coordinator.expects(:new).with(["server.local"]).returns(@coordinator)
|
||||||
dsl.on('server.local')
|
dsl.on("server.local")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "doesn't select when a host filter is present that doesn't match" do
|
it "doesn't select when a host filter is present that doesn't match" do
|
||||||
dsl.set :filter, { :host => 'ruby.local' }
|
dsl.set :filter, { :host => "ruby.local" }
|
||||||
SSHKit::Coordinator.expects(:new).with([]).returns(@coordinator)
|
SSHKit::Coordinator.expects(:new).with([]).returns(@coordinator)
|
||||||
dsl.on('server.local')
|
dsl.on("server.local")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "selects nothing when a roles filter is present" do
|
it "selects nothing when a roles filter is present" do
|
||||||
dsl.set :filter, { :roles => 'web' }
|
dsl.set :filter, { :roles => "web" }
|
||||||
SSHKit::Coordinator.expects(:new).with([]).returns(@coordinator)
|
SSHKit::Coordinator.expects(:new).with([]).returns(@coordinator)
|
||||||
dsl.on('my.server')
|
dsl.on("my.server")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "selects using the string when a hosts filter is present" do
|
it "selects using the string when a hosts filter is present" do
|
||||||
dsl.set :filter, { :hosts => 'server.local' }
|
dsl.set :filter, { :hosts => "server.local" }
|
||||||
SSHKit::Coordinator.expects(:new).with(['server.local']).returns(@coordinator)
|
SSHKit::Coordinator.expects(:new).with(["server.local"]).returns(@coordinator)
|
||||||
dsl.on('server.local')
|
dsl.on("server.local")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "doesn't select when a hosts filter is present that doesn't match" do
|
it "doesn't select when a hosts filter is present that doesn't match" do
|
||||||
dsl.set :filter, { :hosts => 'ruby.local' }
|
dsl.set :filter, { :hosts => "ruby.local" }
|
||||||
SSHKit::Coordinator.expects(:new).with([]).returns(@coordinator)
|
SSHKit::Coordinator.expects(:new).with([]).returns(@coordinator)
|
||||||
dsl.on('server.local')
|
dsl.on("server.local")
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'role_properties()' do
|
describe "role_properties()" do
|
||||||
|
|
||||||
before do
|
before do
|
||||||
dsl.role :redis, %w[example1.com example2.com], :redis => { :port => 6379, :type => :slave }
|
dsl.role :redis, %w[example1.com example2.com], :redis => { :port => 6379, :type => :slave }
|
||||||
dsl.server 'example1.com', :roles => %w{web}, :active => true, :web => { :port => 80 }
|
dsl.server "example1.com", :roles => %w{web}, :active => true, :web => { :port => 80 }
|
||||||
dsl.server 'example2.com', :roles => %w{web redis}, :web => { :port => 81 }, :redis => { :type => :master }
|
dsl.server "example2.com", :roles => %w{web redis}, :web => { :port => 81 }, :redis => { :type => :master }
|
||||||
dsl.server 'example3.com', :roles => %w{app}, :primary => true
|
dsl.server "example3.com", :roles => %w{app}, :primary => true
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'retrieves properties for a single role as a set' do
|
it "retrieves properties for a single role as a set" do
|
||||||
rps = dsl.role_properties(:app)
|
rps = dsl.role_properties(:app)
|
||||||
expect(rps).to eq(Set[{ :hostname => 'example3.com', :role => :app}])
|
expect(rps).to eq(Set[{ :hostname => "example3.com", :role => :app}])
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'retrieves properties for multiple roles as a set' do
|
it "retrieves properties for multiple roles as a set" do
|
||||||
rps = dsl.role_properties(:app, :web)
|
rps = dsl.role_properties(:app, :web)
|
||||||
expect(rps).to eq(Set[{ :hostname => 'example3.com', :role => :app},{ :hostname => 'example1.com', :role => :web, :port => 80},{ :hostname => 'example2.com', :role => :web, :port => 81}])
|
expect(rps).to eq(Set[{ :hostname => "example3.com", :role => :app},{ :hostname => "example1.com", :role => :web, :port => 80},{ :hostname => "example2.com", :role => :web, :port => 81}])
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'yields the properties for a single role' do
|
it "yields the properties for a single role" do
|
||||||
recipient = mock('recipient')
|
recipient = mock("recipient")
|
||||||
recipient.expects(:doit).with('example1.com', :redis, { :port => 6379, :type => :slave})
|
recipient.expects(:doit).with("example1.com", :redis, { :port => 6379, :type => :slave})
|
||||||
recipient.expects(:doit).with('example2.com', :redis, { :port => 6379, :type => :master})
|
recipient.expects(:doit).with("example2.com", :redis, { :port => 6379, :type => :master})
|
||||||
dsl.role_properties(:redis) do |host, role, props|
|
dsl.role_properties(:redis) do |host, role, props|
|
||||||
recipient.doit(host, role, props)
|
recipient.doit(host, role, props)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'yields the properties for multiple roles' do
|
it "yields the properties for multiple roles" do
|
||||||
recipient = mock('recipient')
|
recipient = mock("recipient")
|
||||||
recipient.expects(:doit).with('example1.com', :redis, { :port => 6379, :type => :slave})
|
recipient.expects(:doit).with("example1.com", :redis, { :port => 6379, :type => :slave})
|
||||||
recipient.expects(:doit).with('example2.com', :redis, { :port => 6379, :type => :master})
|
recipient.expects(:doit).with("example2.com", :redis, { :port => 6379, :type => :master})
|
||||||
recipient.expects(:doit).with('example3.com', :app, nil)
|
recipient.expects(:doit).with("example3.com", :app, nil)
|
||||||
dsl.role_properties(:redis, :app) do |host, role, props|
|
dsl.role_properties(:redis, :app) do |host, role, props|
|
||||||
recipient.doit(host, role, props)
|
recipient.doit(host, role, props)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'yields the merged properties for multiple roles' do
|
it "yields the merged properties for multiple roles" do
|
||||||
recipient = mock('recipient')
|
recipient = mock("recipient")
|
||||||
recipient.expects(:doit).with('example1.com', :redis, { :port => 6379, :type => :slave})
|
recipient.expects(:doit).with("example1.com", :redis, { :port => 6379, :type => :slave})
|
||||||
recipient.expects(:doit).with('example2.com', :redis, { :port => 6379, :type => :master})
|
recipient.expects(:doit).with("example2.com", :redis, { :port => 6379, :type => :master})
|
||||||
recipient.expects(:doit).with('example1.com', :web, { :port => 80 })
|
recipient.expects(:doit).with("example1.com", :web, { :port => 80 })
|
||||||
recipient.expects(:doit).with('example2.com', :web, { :port => 81 })
|
recipient.expects(:doit).with("example2.com", :web, { :port => 81 })
|
||||||
dsl.role_properties(:redis, :web) do |host, role, props|
|
dsl.role_properties(:redis, :web) do |host, role, props|
|
||||||
recipient.doit(host, role, props)
|
recipient.doit(host, role, props)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'honours a property filter before yielding' do
|
it "honours a property filter before yielding" do
|
||||||
recipient = mock('recipient')
|
recipient = mock("recipient")
|
||||||
recipient.expects(:doit).with('example1.com', :redis, { :port => 6379, :type => :slave})
|
recipient.expects(:doit).with("example1.com", :redis, { :port => 6379, :type => :slave})
|
||||||
recipient.expects(:doit).with('example1.com', :web, { :port => 80 })
|
recipient.expects(:doit).with("example1.com", :web, { :port => 80 })
|
||||||
dsl.role_properties(:redis, :web, :select => :active) do |host, role, props|
|
dsl.role_properties(:redis, :web, :select => :active) do |host, role, props|
|
||||||
recipient.doit(host, role, props)
|
recipient.doit(host, role, props)
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
require 'spec_helper'
|
require "spec_helper"
|
||||||
require 'support/test_app'
|
require "support/test_app"
|
||||||
require 'support/matchers'
|
require "support/matchers"
|
||||||
|
|
||||||
include TestApp
|
include TestApp
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
require 'spec_helper'
|
require "spec_helper"
|
||||||
|
|
||||||
describe Capistrano::Application do
|
describe Capistrano::Application do
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ describe Capistrano::Application do
|
||||||
|
|
||||||
let(:help_output) do
|
let(:help_output) do
|
||||||
out, _err = capture_io do
|
out, _err = capture_io do
|
||||||
flags '--help', '-h'
|
flags "--help", "-h"
|
||||||
end
|
end
|
||||||
out
|
out
|
||||||
end
|
end
|
||||||
|
@ -25,7 +25,7 @@ describe Capistrano::Application do
|
||||||
|
|
||||||
it "overrides the rake method, but still prints the rake version" do
|
it "overrides the rake method, but still prints the rake version" do
|
||||||
out, _err = capture_io do
|
out, _err = capture_io do
|
||||||
flags '--version', '-V'
|
flags "--version", "-V"
|
||||||
end
|
end
|
||||||
expect(out).to match(/\bCapistrano Version\b/)
|
expect(out).to match(/\bCapistrano Version\b/)
|
||||||
expect(out).to match(/\b#{Capistrano::VERSION}\b/)
|
expect(out).to match(/\b#{Capistrano::VERSION}\b/)
|
||||||
|
@ -35,15 +35,15 @@ describe Capistrano::Application do
|
||||||
|
|
||||||
it "overrides the rake method, and sets the sshkit_backend to SSHKit::Backend::Printer" do
|
it "overrides the rake method, and sets the sshkit_backend to SSHKit::Backend::Printer" do
|
||||||
capture_io do
|
capture_io do
|
||||||
flags '--dry-run', '-n'
|
flags "--dry-run", "-n"
|
||||||
end
|
end
|
||||||
sshkit_backend = Capistrano::Configuration.fetch(:sshkit_backend)
|
sshkit_backend = Capistrano::Configuration.fetch(:sshkit_backend)
|
||||||
expect(sshkit_backend).to eq(SSHKit::Backend::Printer)
|
expect(sshkit_backend).to eq(SSHKit::Backend::Printer)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'enables printing all config variables on command line parameter' do
|
it "enables printing all config variables on command line parameter" do
|
||||||
capture_io do
|
capture_io do
|
||||||
flags '--print-config-variables', '-p'
|
flags "--print-config-variables", "-p"
|
||||||
end
|
end
|
||||||
expect(Capistrano::Configuration.fetch(:print_config_variables)).to be true
|
expect(Capistrano::Configuration.fetch(:print_config_variables)).to be true
|
||||||
end
|
end
|
||||||
|
@ -66,7 +66,7 @@ describe Capistrano::Application do
|
||||||
end
|
end
|
||||||
|
|
||||||
def capture_io
|
def capture_io
|
||||||
require 'stringio'
|
require "stringio"
|
||||||
|
|
||||||
orig_stdout, orig_stderr = $stdout, $stderr
|
orig_stdout, orig_stderr = $stdout, $stderr
|
||||||
captured_stdout, captured_stderr = StringIO.new, StringIO.new
|
captured_stdout, captured_stderr = StringIO.new, StringIO.new
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
require 'spec_helper'
|
require "spec_helper"
|
||||||
|
|
||||||
module Capistrano
|
module Capistrano
|
||||||
class Configuration
|
class Configuration
|
||||||
|
@ -6,9 +6,9 @@ module Capistrano
|
||||||
subject(:empty_filter) { EmptyFilter.new }
|
subject(:empty_filter) { EmptyFilter.new }
|
||||||
|
|
||||||
describe '#filter' do
|
describe '#filter' do
|
||||||
let(:servers) { mock('servers') }
|
let(:servers) { mock("servers") }
|
||||||
|
|
||||||
it 'returns an empty array' do
|
it "returns an empty array" do
|
||||||
expect(empty_filter.filter(servers)).to eq([])
|
expect(empty_filter.filter(servers)).to eq([])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
require 'spec_helper'
|
require "spec_helper"
|
||||||
|
|
||||||
module Capistrano
|
module Capistrano
|
||||||
class Configuration
|
class Configuration
|
||||||
describe Filter do
|
describe Filter do
|
||||||
let(:available) { [ Server.new('server1').add_roles([:web,:db]),
|
let(:available) { [ Server.new("server1").add_roles([:web,:db]),
|
||||||
Server.new('server2').add_role(:web),
|
Server.new("server2").add_role(:web),
|
||||||
Server.new('server3').add_role(:redis),
|
Server.new("server3").add_role(:redis),
|
||||||
Server.new('server4').add_role(:db),
|
Server.new("server4").add_role(:db),
|
||||||
Server.new('server5').add_role(:stageweb) ] }
|
Server.new("server5").add_role(:stageweb) ] }
|
||||||
|
|
||||||
describe '#new' do
|
describe '#new' do
|
||||||
it "won't create an invalid type of filter" do
|
it "won't create an invalid type of filter" do
|
||||||
|
@ -16,54 +16,54 @@ module Capistrano
|
||||||
}.to raise_error RuntimeError
|
}.to raise_error RuntimeError
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with type :host' do
|
context "with type :host" do
|
||||||
context 'and no values' do
|
context "and no values" do
|
||||||
it 'creates an EmptyFilter strategy' do
|
it "creates an EmptyFilter strategy" do
|
||||||
expect(Filter.new(:host).instance_variable_get(:@strategy)).to be_a(EmptyFilter)
|
expect(Filter.new(:host).instance_variable_get(:@strategy)).to be_a(EmptyFilter)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'and :all' do
|
context "and :all" do
|
||||||
it 'creates an NullFilter strategy' do
|
it "creates an NullFilter strategy" do
|
||||||
expect(Filter.new(:host, :all).instance_variable_get(:@strategy)).to be_a(NullFilter)
|
expect(Filter.new(:host, :all).instance_variable_get(:@strategy)).to be_a(NullFilter)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'and [:all]' do
|
context "and [:all]" do
|
||||||
it 'creates an NullFilter strategy' do
|
it "creates an NullFilter strategy" do
|
||||||
expect(Filter.new(:host, [:all]).instance_variable_get(:@strategy)).to be_a(NullFilter)
|
expect(Filter.new(:host, [:all]).instance_variable_get(:@strategy)).to be_a(NullFilter)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'and [:all]' do
|
context "and [:all]" do
|
||||||
it 'creates an NullFilter strategy' do
|
it "creates an NullFilter strategy" do
|
||||||
expect(Filter.new(:host, 'all').instance_variable_get(:@strategy)).to be_a(NullFilter)
|
expect(Filter.new(:host, "all").instance_variable_get(:@strategy)).to be_a(NullFilter)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with type :role' do
|
context "with type :role" do
|
||||||
context 'and no values' do
|
context "and no values" do
|
||||||
it 'creates an EmptyFilter strategy' do
|
it "creates an EmptyFilter strategy" do
|
||||||
expect(Filter.new(:role).instance_variable_get(:@strategy)).to be_a(EmptyFilter)
|
expect(Filter.new(:role).instance_variable_get(:@strategy)).to be_a(EmptyFilter)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'and :all' do
|
context "and :all" do
|
||||||
it 'creates an NullFilter strategy' do
|
it "creates an NullFilter strategy" do
|
||||||
expect(Filter.new(:role, :all).instance_variable_get(:@strategy)).to be_a(NullFilter)
|
expect(Filter.new(:role, :all).instance_variable_get(:@strategy)).to be_a(NullFilter)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'and [:all]' do
|
context "and [:all]" do
|
||||||
it 'creates an NullFilter strategy' do
|
it "creates an NullFilter strategy" do
|
||||||
expect(Filter.new(:role, [:all]).instance_variable_get(:@strategy)).to be_a(NullFilter)
|
expect(Filter.new(:role, [:all]).instance_variable_get(:@strategy)).to be_a(NullFilter)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'and [:all]' do
|
context "and [:all]" do
|
||||||
it 'creates an NullFilter strategy' do
|
it "creates an NullFilter strategy" do
|
||||||
expect(Filter.new(:role, 'all').instance_variable_get(:@strategy)).to be_a(NullFilter)
|
expect(Filter.new(:role, "all").instance_variable_get(:@strategy)).to be_a(NullFilter)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -71,7 +71,7 @@ module Capistrano
|
||||||
|
|
||||||
describe '#filter' do
|
describe '#filter' do
|
||||||
let(:strategy) { filter.instance_variable_get(:@strategy) }
|
let(:strategy) { filter.instance_variable_get(:@strategy) }
|
||||||
let(:results) { mock('result') }
|
let(:results) { mock("result") }
|
||||||
|
|
||||||
shared_examples 'it calls #filter on its strategy' do
|
shared_examples 'it calls #filter on its strategy' do
|
||||||
it 'calls #filter on its strategy' do
|
it 'calls #filter on its strategy' do
|
||||||
|
@ -80,23 +80,23 @@ module Capistrano
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'for an empty filter' do
|
context "for an empty filter" do
|
||||||
let(:filter) { Filter.new(:role) }
|
let(:filter) { Filter.new(:role) }
|
||||||
it_behaves_like 'it calls #filter on its strategy'
|
it_behaves_like 'it calls #filter on its strategy'
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'for a null filter' do
|
context "for a null filter" do
|
||||||
let(:filter) { Filter.new(:role, :all) }
|
let(:filter) { Filter.new(:role, :all) }
|
||||||
it_behaves_like 'it calls #filter on its strategy'
|
it_behaves_like 'it calls #filter on its strategy'
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'for a role filter' do
|
context "for a role filter" do
|
||||||
let(:filter) { Filter.new(:role, 'web') }
|
let(:filter) { Filter.new(:role, "web") }
|
||||||
it_behaves_like 'it calls #filter on its strategy'
|
it_behaves_like 'it calls #filter on its strategy'
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'for a host filter' do
|
context "for a host filter" do
|
||||||
let(:filter) { Filter.new(:host, 'server1') }
|
let(:filter) { Filter.new(:host, "server1") }
|
||||||
it_behaves_like 'it calls #filter on its strategy'
|
it_behaves_like 'it calls #filter on its strategy'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,57 +1,57 @@
|
||||||
require 'spec_helper'
|
require "spec_helper"
|
||||||
|
|
||||||
module Capistrano
|
module Capistrano
|
||||||
class Configuration
|
class Configuration
|
||||||
describe HostFilter do
|
describe HostFilter do
|
||||||
subject(:host_filter) { HostFilter.new(values) }
|
subject(:host_filter) { HostFilter.new(values) }
|
||||||
|
|
||||||
let(:available) { [ Server.new('server1'),
|
let(:available) { [ Server.new("server1"),
|
||||||
Server.new('server2'),
|
Server.new("server2"),
|
||||||
Server.new('server3'),
|
Server.new("server3"),
|
||||||
Server.new('server4'),
|
Server.new("server4"),
|
||||||
Server.new('server5') ] }
|
Server.new("server5") ] }
|
||||||
|
|
||||||
shared_examples 'it filters hosts correctly' do |expected|
|
shared_examples "it filters hosts correctly" do |expected|
|
||||||
it 'filters correctly' do
|
it "filters correctly" do
|
||||||
set = host_filter.filter(available)
|
set = host_filter.filter(available)
|
||||||
expect(set.map(&:hostname)).to eq(expected)
|
expect(set.map(&:hostname)).to eq(expected)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#filter' do
|
describe '#filter' do
|
||||||
context 'with a string' do
|
context "with a string" do
|
||||||
let(:values) { 'server1' }
|
let(:values) { "server1" }
|
||||||
it_behaves_like 'it filters hosts correctly', %w{server1}
|
it_behaves_like "it filters hosts correctly", %w{server1}
|
||||||
|
|
||||||
context 'and a single server' do
|
context "and a single server" do
|
||||||
let(:available) { Server.new('server1') }
|
let(:available) { Server.new("server1") }
|
||||||
it_behaves_like 'it filters hosts correctly', %w{server1}
|
it_behaves_like "it filters hosts correctly", %w{server1}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with a comma separated string' do
|
context "with a comma separated string" do
|
||||||
let(:values) { 'server1,server3' }
|
let(:values) { "server1,server3" }
|
||||||
it_behaves_like 'it filters hosts correctly', %w{server1 server3}
|
it_behaves_like "it filters hosts correctly", %w{server1 server3}
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with an array of strings' do
|
context "with an array of strings" do
|
||||||
let(:values) { %w{server1 server3} }
|
let(:values) { %w{server1 server3} }
|
||||||
it_behaves_like 'it filters hosts correctly', %w{server1 server3}
|
it_behaves_like "it filters hosts correctly", %w{server1 server3}
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with a regexp' do
|
context "with a regexp" do
|
||||||
let(:values) { 'server[13]$' }
|
let(:values) { "server[13]$" }
|
||||||
it_behaves_like 'it filters hosts correctly', %w{server1 server3}
|
it_behaves_like "it filters hosts correctly", %w{server1 server3}
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with a regexp with line boundaries' do
|
context "with a regexp with line boundaries" do
|
||||||
let(:values) { '^server' }
|
let(:values) { "^server" }
|
||||||
it_behaves_like 'it filters hosts correctly', %w{server1 server2 server3 server4 server5}
|
it_behaves_like "it filters hosts correctly", %w{server1 server2 server3 server4 server5}
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with a regexp with a comma' do
|
context "with a regexp with a comma" do
|
||||||
let(:values) { 'server\d{1,3}$' }
|
let(:values) { 'server\d{1,3}$' }
|
||||||
it_behaves_like 'it filters hosts correctly', %w{server1 server2 server3 server4 server5}
|
it_behaves_like "it filters hosts correctly", %w{server1 server2 server3 server4 server5}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
require 'spec_helper'
|
require "spec_helper"
|
||||||
|
|
||||||
module Capistrano
|
module Capistrano
|
||||||
class Configuration
|
class Configuration
|
||||||
|
@ -6,9 +6,9 @@ module Capistrano
|
||||||
subject(:null_filter) { NullFilter.new }
|
subject(:null_filter) { NullFilter.new }
|
||||||
|
|
||||||
describe '#filter' do
|
describe '#filter' do
|
||||||
let(:servers) { mock('servers') }
|
let(:servers) { mock("servers") }
|
||||||
|
|
||||||
it 'returns the servers passed in as arguments' do
|
it "returns the servers passed in as arguments" do
|
||||||
expect(null_filter.filter(servers)).to eq(servers)
|
expect(null_filter.filter(servers)).to eq(servers)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
require 'spec_helper'
|
require "spec_helper"
|
||||||
|
|
||||||
module Capistrano
|
module Capistrano
|
||||||
class Configuration
|
class Configuration
|
||||||
|
@ -11,28 +11,28 @@ module Capistrano
|
||||||
let(:key) { :branch }
|
let(:key) { :branch }
|
||||||
let(:options) { nil }
|
let(:options) { nil }
|
||||||
|
|
||||||
describe '.new' do
|
describe ".new" do
|
||||||
it 'takes a key, default, options' do
|
it "takes a key, default, options" do
|
||||||
question
|
question
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#call' do
|
describe '#call' do
|
||||||
context 'value is entered' do
|
context "value is entered" do
|
||||||
let(:branch) { 'branch' }
|
let(:branch) { "branch" }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
$stdout.expects(:print).with('Please enter branch (default): ')
|
$stdout.expects(:print).with("Please enter branch (default): ")
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns the echoed value' do
|
it "returns the echoed value" do
|
||||||
$stdin.expects(:gets).returns(branch)
|
$stdin.expects(:gets).returns(branch)
|
||||||
$stdin.expects(:noecho).never
|
$stdin.expects(:noecho).never
|
||||||
|
|
||||||
expect(question.call).to eq(branch)
|
expect(question.call).to eq(branch)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns the value but does not echo it' do
|
it "returns the value but does not echo it" do
|
||||||
$stdin.expects(:noecho).returns(branch)
|
$stdin.expects(:noecho).returns(branch)
|
||||||
$stdout.expects(:print).with("\n")
|
$stdout.expects(:print).with("\n")
|
||||||
|
|
||||||
|
@ -40,16 +40,16 @@ module Capistrano
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'value is not entered' do
|
context "value is not entered" do
|
||||||
let(:branch) { default }
|
let(:branch) { default }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
$stdout.expects(:print).with('Please enter branch (default): ')
|
$stdout.expects(:print).with("Please enter branch (default): ")
|
||||||
$stdin.expects(:gets).returns('')
|
$stdin.expects(:gets).returns("")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
it 'returns the default as the value' do
|
it "returns the default as the value" do
|
||||||
expect(question.call).to eq(branch)
|
expect(question.call).to eq(branch)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
require 'spec_helper'
|
require "spec_helper"
|
||||||
|
|
||||||
module Capistrano
|
module Capistrano
|
||||||
class Configuration
|
class Configuration
|
||||||
describe RoleFilter do
|
describe RoleFilter do
|
||||||
subject(:role_filter) { RoleFilter.new(values) }
|
subject(:role_filter) { RoleFilter.new(values) }
|
||||||
|
|
||||||
let(:available) { [ Server.new('server1').add_roles([:web,:db]),
|
let(:available) { [ Server.new("server1").add_roles([:web,:db]),
|
||||||
Server.new('server2').add_role(:web),
|
Server.new("server2").add_role(:web),
|
||||||
Server.new('server3').add_role(:redis),
|
Server.new("server3").add_role(:redis),
|
||||||
Server.new('server4').add_role(:db),
|
Server.new("server4").add_role(:db),
|
||||||
Server.new('server5').add_role(:stageweb) ] }
|
Server.new("server5").add_role(:stageweb) ] }
|
||||||
|
|
||||||
shared_examples 'it filters roles correctly' do |expected_size, expected|
|
shared_examples "it filters roles correctly" do |expected_size, expected|
|
||||||
it 'filters correctly' do
|
it "filters correctly" do
|
||||||
set = role_filter.filter(available)
|
set = role_filter.filter(available)
|
||||||
expect(set.size).to eq(expected_size)
|
expect(set.size).to eq(expected_size)
|
||||||
expect(set.map(&:hostname)).to eq(expected)
|
expect(set.map(&:hostname)).to eq(expected)
|
||||||
|
@ -20,39 +20,39 @@ module Capistrano
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#filter' do
|
describe '#filter' do
|
||||||
context 'with a single role string' do
|
context "with a single role string" do
|
||||||
let(:values) { 'web' }
|
let(:values) { "web" }
|
||||||
it_behaves_like 'it filters roles correctly', 2, %w{server1 server2}
|
it_behaves_like "it filters roles correctly", 2, %w{server1 server2}
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with a single role' do
|
context "with a single role" do
|
||||||
let(:values) { [:web] }
|
let(:values) { [:web] }
|
||||||
it_behaves_like 'it filters roles correctly', 2, %w{server1 server2}
|
it_behaves_like "it filters roles correctly", 2, %w{server1 server2}
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with multiple roles in a string' do
|
context "with multiple roles in a string" do
|
||||||
let(:values) { 'web,db' }
|
let(:values) { "web,db" }
|
||||||
it_behaves_like 'it filters roles correctly', 3, %w{server1 server2 server4}
|
it_behaves_like "it filters roles correctly", 3, %w{server1 server2 server4}
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with multiple roles' do
|
context "with multiple roles" do
|
||||||
let(:values) { [:web, :db] }
|
let(:values) { [:web, :db] }
|
||||||
it_behaves_like 'it filters roles correctly', 3, %w{server1 server2 server4}
|
it_behaves_like "it filters roles correctly", 3, %w{server1 server2 server4}
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with a regex' do
|
context "with a regex" do
|
||||||
let(:values) { /red/ }
|
let(:values) { /red/ }
|
||||||
it_behaves_like 'it filters roles correctly', 1, %w{server3}
|
it_behaves_like "it filters roles correctly", 1, %w{server3}
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with a regex string' do
|
context "with a regex string" do
|
||||||
let(:values) { '/red|web/' }
|
let(:values) { "/red|web/" }
|
||||||
it_behaves_like 'it filters roles correctly', 4, %w{server1 server2 server3 server5}
|
it_behaves_like "it filters roles correctly", 4, %w{server1 server2 server3 server5}
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with both a string and regex' do
|
context "with both a string and regex" do
|
||||||
let(:values) { 'db,/red/' }
|
let(:values) { "db,/red/" }
|
||||||
it_behaves_like 'it filters roles correctly', 3, %w{server1 server3 server4}
|
it_behaves_like "it filters roles correctly", 3, %w{server1 server3 server4}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,141 +1,141 @@
|
||||||
require 'spec_helper'
|
require "spec_helper"
|
||||||
|
|
||||||
module Capistrano
|
module Capistrano
|
||||||
class Configuration
|
class Configuration
|
||||||
describe Server do
|
describe Server do
|
||||||
let(:server) { Server.new('root@hostname:1234') }
|
let(:server) { Server.new("root@hostname:1234") }
|
||||||
|
|
||||||
describe 'adding a role' do
|
describe "adding a role" do
|
||||||
subject { server.add_role(:test) }
|
subject { server.add_role(:test) }
|
||||||
it 'adds the role' do
|
it "adds the role" do
|
||||||
expect{subject}.to change{server.roles.size}.from(0).to(1)
|
expect{subject}.to change{server.roles.size}.from(0).to(1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'adding roles' do
|
describe "adding roles" do
|
||||||
subject { server.add_roles([:things, :stuff]) }
|
subject { server.add_roles([:things, :stuff]) }
|
||||||
it 'adds the roles' do
|
it "adds the roles" do
|
||||||
expect{subject}.to change{server.roles.size}.from(0).to(2)
|
expect{subject}.to change{server.roles.size}.from(0).to(2)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
describe 'checking roles' do
|
describe "checking roles" do
|
||||||
subject { server.has_role?(:test) }
|
subject { server.has_role?(:test) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
server.add_role(:test)
|
server.add_role(:test)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'adds the role' do
|
it "adds the role" do
|
||||||
expect(subject).to be_truthy
|
expect(subject).to be_truthy
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'comparing identity' do
|
describe "comparing identity" do
|
||||||
subject { server.hostname == Server[hostname].hostname }
|
subject { server.hostname == Server[hostname].hostname }
|
||||||
|
|
||||||
context 'with the same user, hostname and port' do
|
context "with the same user, hostname and port" do
|
||||||
let(:hostname) { 'root@hostname:1234' }
|
let(:hostname) { "root@hostname:1234" }
|
||||||
it { expect(subject).to be_truthy }
|
it { expect(subject).to be_truthy }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with a different user' do
|
context "with a different user" do
|
||||||
let(:hostname) { 'deployer@hostname:1234' }
|
let(:hostname) { "deployer@hostname:1234" }
|
||||||
it { expect(subject).to be_truthy }
|
it { expect(subject).to be_truthy }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with a different port' do
|
context "with a different port" do
|
||||||
let(:hostname) { 'root@hostname:5678' }
|
let(:hostname) { "root@hostname:5678" }
|
||||||
it { expect(subject).to be_truthy }
|
it { expect(subject).to be_truthy }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with a different hostname' do
|
context "with a different hostname" do
|
||||||
let(:hostname) { 'root@otherserver:1234' }
|
let(:hostname) { "root@otherserver:1234" }
|
||||||
it { expect(subject).to be_falsey }
|
it { expect(subject).to be_falsey }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'identifying as primary' do
|
describe "identifying as primary" do
|
||||||
subject { server.primary }
|
subject { server.primary }
|
||||||
context 'server is primary' do
|
context "server is primary" do
|
||||||
before do
|
before do
|
||||||
server.set(:primary, true)
|
server.set(:primary, true)
|
||||||
end
|
end
|
||||||
it 'returns self' do
|
it "returns self" do
|
||||||
expect(subject).to eq server
|
expect(subject).to eq server
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'server is not primary' do
|
context "server is not primary" do
|
||||||
it 'is falesy' do
|
it "is falesy" do
|
||||||
expect(subject).to be_falsey
|
expect(subject).to be_falsey
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'assigning properties' do
|
describe "assigning properties" do
|
||||||
|
|
||||||
before do
|
before do
|
||||||
server.with(properties)
|
server.with(properties)
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'properties contains roles' do
|
context "properties contains roles" do
|
||||||
let(:properties) { {:roles => [:clouds]} }
|
let(:properties) { {:roles => [:clouds]} }
|
||||||
|
|
||||||
it 'adds the roles' do
|
it "adds the roles" do
|
||||||
expect(server.roles.first).to eq :clouds
|
expect(server.roles.first).to eq :clouds
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'properties contains user' do
|
context "properties contains user" do
|
||||||
let(:properties) { {:user => 'tomc'} }
|
let(:properties) { {:user => "tomc"} }
|
||||||
|
|
||||||
it 'sets the user' do
|
it "sets the user" do
|
||||||
expect(server.user).to eq 'tomc'
|
expect(server.user).to eq "tomc"
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'sets the netssh_options user' do
|
it "sets the netssh_options user" do
|
||||||
expect(server.netssh_options[:user]).to eq 'tomc'
|
expect(server.netssh_options[:user]).to eq "tomc"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'properties contains port' do
|
context "properties contains port" do
|
||||||
let(:properties) { {:port => 2222} }
|
let(:properties) { {:port => 2222} }
|
||||||
|
|
||||||
it 'sets the port' do
|
it "sets the port" do
|
||||||
expect(server.port).to eq 2222
|
expect(server.port).to eq 2222
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'properties contains key' do
|
context "properties contains key" do
|
||||||
let(:properties) { {:key => '/key'} }
|
let(:properties) { {:key => "/key"} }
|
||||||
|
|
||||||
it 'adds the key' do
|
it "adds the key" do
|
||||||
expect(server.keys).to include '/key'
|
expect(server.keys).to include "/key"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'properties contains password' do
|
context "properties contains password" do
|
||||||
let(:properties) { {:password => 'supersecret'} }
|
let(:properties) { {:password => "supersecret"} }
|
||||||
|
|
||||||
it 'adds the key' do
|
it "adds the key" do
|
||||||
expect(server.password).to eq 'supersecret'
|
expect(server.password).to eq "supersecret"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'new properties' do
|
context "new properties" do
|
||||||
let(:properties) { { :webscales => 5 } }
|
let(:properties) { { :webscales => 5 } }
|
||||||
|
|
||||||
it 'adds the properties' do
|
it "adds the properties" do
|
||||||
expect(server.properties.webscales).to eq 5
|
expect(server.properties.webscales).to eq 5
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'existing properties' do
|
context "existing properties" do
|
||||||
let(:properties) { { :webscales => 6 } }
|
let(:properties) { { :webscales => 6 } }
|
||||||
|
|
||||||
it 'keeps the existing properties' do
|
it "keeps the existing properties" do
|
||||||
expect(server.properties.webscales).to eq 6
|
expect(server.properties.webscales).to eq 6
|
||||||
server.properties.webscales = 5
|
server.properties.webscales = 5
|
||||||
expect(server.properties.webscales).to eq 5
|
expect(server.properties.webscales).to eq 5
|
||||||
|
@ -152,103 +152,103 @@ module Capistrano
|
||||||
server.properties.active = true
|
server.properties.active = true
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'options are empty' do
|
context "options are empty" do
|
||||||
it { expect(subject).to be_truthy }
|
it { expect(subject).to be_truthy }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'value is a symbol' do
|
context "value is a symbol" do
|
||||||
context 'value matches server property' do
|
context "value matches server property" do
|
||||||
|
|
||||||
context 'with :filter' do
|
context "with :filter" do
|
||||||
let(:options) { { :filter => :active }}
|
let(:options) { { :filter => :active }}
|
||||||
it { expect(subject).to be_truthy }
|
it { expect(subject).to be_truthy }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with :select' do
|
context "with :select" do
|
||||||
let(:options) { { :select => :active }}
|
let(:options) { { :select => :active }}
|
||||||
it { expect(subject).to be_truthy }
|
it { expect(subject).to be_truthy }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with :exclude' do
|
context "with :exclude" do
|
||||||
let(:options) { { :exclude => :active }}
|
let(:options) { { :exclude => :active }}
|
||||||
it { expect(subject).to be_falsey }
|
it { expect(subject).to be_falsey }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'value does not match server properly' do
|
context "value does not match server properly" do
|
||||||
context 'with :active true' do
|
context "with :active true" do
|
||||||
let(:options) { { :active => true }}
|
let(:options) { { :active => true }}
|
||||||
it { expect(subject).to be_truthy }
|
it { expect(subject).to be_truthy }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with :active false' do
|
context "with :active false" do
|
||||||
let(:options) { { :active => false }}
|
let(:options) { { :active => false }}
|
||||||
it { expect(subject).to be_falsey }
|
it { expect(subject).to be_falsey }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'value does not match server properly' do
|
context "value does not match server properly" do
|
||||||
context 'with :filter' do
|
context "with :filter" do
|
||||||
let(:options) { { :filter => :inactive }}
|
let(:options) { { :filter => :inactive }}
|
||||||
it { expect(subject).to be_falsey }
|
it { expect(subject).to be_falsey }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with :select' do
|
context "with :select" do
|
||||||
let(:options) { { :select => :inactive }}
|
let(:options) { { :select => :inactive }}
|
||||||
it { expect(subject).to be_falsey }
|
it { expect(subject).to be_falsey }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with :exclude' do
|
context "with :exclude" do
|
||||||
let(:options) { { :exclude => :inactive }}
|
let(:options) { { :exclude => :inactive }}
|
||||||
it { expect(subject).to be_truthy }
|
it { expect(subject).to be_truthy }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'key is a property' do
|
context "key is a property" do
|
||||||
context 'with :active true' do
|
context "with :active true" do
|
||||||
let(:options) { { :active => true }}
|
let(:options) { { :active => true }}
|
||||||
it { expect(subject).to be_truthy }
|
it { expect(subject).to be_truthy }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with :active false' do
|
context "with :active false" do
|
||||||
let(:options) { { :active => false }}
|
let(:options) { { :active => false }}
|
||||||
it { expect(subject).to be_falsey }
|
it { expect(subject).to be_falsey }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'value is a proc' do
|
context "value is a proc" do
|
||||||
context 'value matches server property' do
|
context "value matches server property" do
|
||||||
|
|
||||||
context 'with :filter' do
|
context "with :filter" do
|
||||||
let(:options) { { :filter => ->(s) { s.properties.active } } }
|
let(:options) { { :filter => ->(s) { s.properties.active } } }
|
||||||
it { expect(subject).to be_truthy }
|
it { expect(subject).to be_truthy }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with :select' do
|
context "with :select" do
|
||||||
let(:options) { { :select => ->(s) { s.properties.active } } }
|
let(:options) { { :select => ->(s) { s.properties.active } } }
|
||||||
it { expect(subject).to be_truthy }
|
it { expect(subject).to be_truthy }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with :exclude' do
|
context "with :exclude" do
|
||||||
let(:options) { { :exclude => ->(s) { s.properties.active } } }
|
let(:options) { { :exclude => ->(s) { s.properties.active } } }
|
||||||
it { expect(subject).to be_falsey }
|
it { expect(subject).to be_falsey }
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'value does not match server properly' do
|
context "value does not match server properly" do
|
||||||
context 'with :filter' do
|
context "with :filter" do
|
||||||
let(:options) { { :filter => ->(s) { s.properties.inactive } } }
|
let(:options) { { :filter => ->(s) { s.properties.inactive } } }
|
||||||
it { expect(subject).to be_falsey }
|
it { expect(subject).to be_falsey }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with :select' do
|
context "with :select" do
|
||||||
let(:options) { { :select => ->(s) { s.properties.inactive } } }
|
let(:options) { { :select => ->(s) { s.properties.inactive } } }
|
||||||
it { expect(subject).to be_falsey }
|
it { expect(subject).to be_falsey }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with :exclude' do
|
context "with :exclude" do
|
||||||
let(:options) { { :exclude => ->(s) { s.properties.inactive } } }
|
let(:options) { { :exclude => ->(s) { s.properties.inactive } } }
|
||||||
it { expect(subject).to be_truthy }
|
it { expect(subject).to be_truthy }
|
||||||
end
|
end
|
||||||
|
@ -258,22 +258,22 @@ module Capistrano
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'assign ssh_options' do
|
describe "assign ssh_options" do
|
||||||
let(:server) { Server.new('user_name@hostname') }
|
let(:server) { Server.new("user_name@hostname") }
|
||||||
|
|
||||||
context 'defaults' do
|
context "defaults" do
|
||||||
it 'forward agent' do
|
it "forward agent" do
|
||||||
expect(server.netssh_options[:forward_agent]).to eq true
|
expect(server.netssh_options[:forward_agent]).to eq true
|
||||||
end
|
end
|
||||||
it 'contains user' do
|
it "contains user" do
|
||||||
expect(server.netssh_options[:user]).to eq 'user_name'
|
expect(server.netssh_options[:user]).to eq "user_name"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'custom' do
|
context "custom" do
|
||||||
let(:properties) do
|
let(:properties) do
|
||||||
{ :ssh_options => {
|
{ :ssh_options => {
|
||||||
:user => 'another_user',
|
:user => "another_user",
|
||||||
:keys => %w(/home/another_user/.ssh/id_rsa),
|
:keys => %w(/home/another_user/.ssh/id_rsa),
|
||||||
:forward_agent => false,
|
:forward_agent => false,
|
||||||
:auth_methods => %w(publickey password) } }
|
:auth_methods => %w(publickey password) } }
|
||||||
|
@ -283,19 +283,19 @@ module Capistrano
|
||||||
server.with(properties)
|
server.with(properties)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'not forward agent' do
|
it "not forward agent" do
|
||||||
expect(server.netssh_options[:forward_agent]).to eq false
|
expect(server.netssh_options[:forward_agent]).to eq false
|
||||||
end
|
end
|
||||||
it 'contains correct user' do
|
it "contains correct user" do
|
||||||
expect(server.netssh_options[:user]).to eq 'another_user'
|
expect(server.netssh_options[:user]).to eq "another_user"
|
||||||
end
|
end
|
||||||
it 'does not affect server user in host' do
|
it "does not affect server user in host" do
|
||||||
expect(server.user).to eq 'user_name'
|
expect(server.user).to eq "user_name"
|
||||||
end
|
end
|
||||||
it 'contains keys' do
|
it "contains keys" do
|
||||||
expect(server.netssh_options[:keys]).to eq %w(/home/another_user/.ssh/id_rsa)
|
expect(server.netssh_options[:keys]).to eq %w(/home/another_user/.ssh/id_rsa)
|
||||||
end
|
end
|
||||||
it 'contains auth_methods' do
|
it "contains auth_methods" do
|
||||||
expect(server.netssh_options[:auth_methods]).to eq %w(publickey password)
|
expect(server.netssh_options[:auth_methods]).to eq %w(publickey password)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -303,11 +303,11 @@ module Capistrano
|
||||||
end
|
end
|
||||||
|
|
||||||
describe ".[]" do
|
describe ".[]" do
|
||||||
it 'creates a server if its argument is not already a server' do
|
it "creates a server if its argument is not already a server" do
|
||||||
expect(Server['hostname:1234']).to be_a Server
|
expect(Server["hostname:1234"]).to be_a Server
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns its argument if it is already a server' do
|
it "returns its argument if it is already a server" do
|
||||||
expect(Server[server]).to be server
|
expect(Server[server]).to be server
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,63 +1,63 @@
|
||||||
require 'spec_helper'
|
require "spec_helper"
|
||||||
|
|
||||||
module Capistrano
|
module Capistrano
|
||||||
class Configuration
|
class Configuration
|
||||||
describe Servers do
|
describe Servers do
|
||||||
let(:servers) { Servers.new }
|
let(:servers) { Servers.new }
|
||||||
|
|
||||||
describe 'adding a role' do
|
describe "adding a role" do
|
||||||
|
|
||||||
it 'adds two new server instances' do
|
it "adds two new server instances" do
|
||||||
expect{servers.add_role(:app, %w{1 2})}.
|
expect{servers.add_role(:app, %w{1 2})}.
|
||||||
to change{servers.count}.from(0).to(2)
|
to change{servers.count}.from(0).to(2)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'handles de-duplification within roles' do
|
it "handles de-duplification within roles" do
|
||||||
servers.add_role(:app, %w{1})
|
servers.add_role(:app, %w{1})
|
||||||
servers.add_role(:app, %w{1})
|
servers.add_role(:app, %w{1})
|
||||||
expect(servers.count).to eq 1
|
expect(servers.count).to eq 1
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'handles de-duplification within roles with users' do
|
it "handles de-duplification within roles with users" do
|
||||||
servers.add_role(:app, %w{1}, :user => 'nick')
|
servers.add_role(:app, %w{1}, :user => "nick")
|
||||||
servers.add_role(:app, %w{1}, :user => 'fred')
|
servers.add_role(:app, %w{1}, :user => "fred")
|
||||||
expect(servers.count).to eq 1
|
expect(servers.count).to eq 1
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'accepts instances of server objects' do
|
it "accepts instances of server objects" do
|
||||||
servers.add_role(:app, [Capistrano::Configuration::Server.new('example.net'), 'example.com'])
|
servers.add_role(:app, [Capistrano::Configuration::Server.new("example.net"), "example.com"])
|
||||||
expect(servers.roles_for([:app]).length).to eq 2
|
expect(servers.roles_for([:app]).length).to eq 2
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'accepts non-enumerable types' do
|
it "accepts non-enumerable types" do
|
||||||
servers.add_role(:app, '1')
|
servers.add_role(:app, "1")
|
||||||
expect(servers.roles_for([:app]).count).to eq 1
|
expect(servers.roles_for([:app]).count).to eq 1
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'creates distinct server properties' do
|
it "creates distinct server properties" do
|
||||||
servers.add_role(:db, %w{1 2}, :db => { :port => 1234 } )
|
servers.add_role(:db, %w{1 2}, :db => { :port => 1234 } )
|
||||||
servers.add_host('1', :db => { :master => true })
|
servers.add_host("1", :db => { :master => true })
|
||||||
expect(servers.count).to eq(2)
|
expect(servers.count).to eq(2)
|
||||||
expect(servers.roles_for([:db]).count).to eq 2
|
expect(servers.roles_for([:db]).count).to eq 2
|
||||||
expect(servers.find(){|s| s.hostname == '1'}.properties.db).to eq({ :port => 1234, :master => true })
|
expect(servers.find(){|s| s.hostname == "1"}.properties.db).to eq({ :port => 1234, :master => true })
|
||||||
expect(servers.find(){|s| s.hostname == '2'}.properties.db).to eq({ :port => 1234 })
|
expect(servers.find(){|s| s.hostname == "2"}.properties.db).to eq({ :port => 1234 })
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'adding a role to an existing server' do
|
describe "adding a role to an existing server" do
|
||||||
before do
|
before do
|
||||||
servers.add_role(:web, %w{1 2})
|
servers.add_role(:web, %w{1 2})
|
||||||
servers.add_role(:app, %w{1 2})
|
servers.add_role(:app, %w{1 2})
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'adds new roles to existing servers' do
|
it "adds new roles to existing servers" do
|
||||||
expect(servers.count).to eq 2
|
expect(servers.count).to eq 2
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'collecting server roles' do
|
describe "collecting server roles" do
|
||||||
let(:app) { Set.new([:app]) }
|
let(:app) { Set.new([:app]) }
|
||||||
let(:web_app) { Set.new([:web, :app]) }
|
let(:web_app) { Set.new([:web, :app]) }
|
||||||
let(:web) { Set.new([:web]) }
|
let(:web) { Set.new([:web]) }
|
||||||
|
@ -67,274 +67,274 @@ module Capistrano
|
||||||
servers.add_role(:web, %w{2 3 4})
|
servers.add_role(:web, %w{2 3 4})
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns an array of the roles' do
|
it "returns an array of the roles" do
|
||||||
expect(servers.roles_for([:app]).collect(&:roles)).to eq [app, web_app, web_app]
|
expect(servers.roles_for([:app]).collect(&:roles)).to eq [app, web_app, web_app]
|
||||||
expect(servers.roles_for([:web]).collect(&:roles)).to eq [web_app, web_app, web]
|
expect(servers.roles_for([:web]).collect(&:roles)).to eq [web_app, web_app, web]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'finding the primary server' do
|
describe "finding the primary server" do
|
||||||
after do
|
after do
|
||||||
Configuration.reset!
|
Configuration.reset!
|
||||||
end
|
end
|
||||||
it 'takes the first server if none have the primary property' do
|
it "takes the first server if none have the primary property" do
|
||||||
servers.add_role(:app, %w{1 2})
|
servers.add_role(:app, %w{1 2})
|
||||||
expect(servers.fetch_primary(:app).hostname).to eq('1')
|
expect(servers.fetch_primary(:app).hostname).to eq("1")
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'takes the first server with the primary have the primary flag' do
|
it "takes the first server with the primary have the primary flag" do
|
||||||
servers.add_role(:app, %w{1 2})
|
servers.add_role(:app, %w{1 2})
|
||||||
servers.add_host('2', :primary => true)
|
servers.add_host("2", :primary => true)
|
||||||
expect(servers.fetch_primary(:app).hostname).to eq('2')
|
expect(servers.fetch_primary(:app).hostname).to eq("2")
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'ignores any on_filters' do
|
it "ignores any on_filters" do
|
||||||
Configuration.env.set :filter, { :host => '1'}
|
Configuration.env.set :filter, { :host => "1"}
|
||||||
servers.add_role(:app, %w{1 2})
|
servers.add_role(:app, %w{1 2})
|
||||||
servers.add_host('2', :primary => true)
|
servers.add_host("2", :primary => true)
|
||||||
expect(servers.fetch_primary(:app).hostname).to eq('2')
|
expect(servers.fetch_primary(:app).hostname).to eq("2")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'fetching servers' do
|
describe "fetching servers" do
|
||||||
before do
|
before do
|
||||||
servers.add_role(:app, %w{1 2})
|
servers.add_role(:app, %w{1 2})
|
||||||
servers.add_role(:web, %w{2 3})
|
servers.add_role(:web, %w{2 3})
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns the correct app servers' do
|
it "returns the correct app servers" do
|
||||||
expect(servers.roles_for([:app]).map(&:hostname)).to eq %w{1 2}
|
expect(servers.roles_for([:app]).map(&:hostname)).to eq %w{1 2}
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns the correct web servers' do
|
it "returns the correct web servers" do
|
||||||
expect(servers.roles_for([:web]).map(&:hostname)).to eq %w{2 3}
|
expect(servers.roles_for([:web]).map(&:hostname)).to eq %w{2 3}
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns the correct app and web servers' do
|
it "returns the correct app and web servers" do
|
||||||
expect(servers.roles_for([:app, :web]).map(&:hostname)).to eq %w{1 2 3}
|
expect(servers.roles_for([:app, :web]).map(&:hostname)).to eq %w{1 2 3}
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns all servers' do
|
it "returns all servers" do
|
||||||
expect(servers.roles_for([:all]).map(&:hostname)).to eq %w{1 2 3}
|
expect(servers.roles_for([:all]).map(&:hostname)).to eq %w{1 2 3}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'adding a server' do
|
describe "adding a server" do
|
||||||
|
|
||||||
before do
|
before do
|
||||||
servers.add_host('1', :roles => [:app, 'web'], :test => :value)
|
servers.add_host("1", :roles => [:app, "web"], :test => :value)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'can create a server with properties' do
|
it "can create a server with properties" do
|
||||||
expect(servers.roles_for([:app]).first.hostname).to eq '1'
|
expect(servers.roles_for([:app]).first.hostname).to eq "1"
|
||||||
expect(servers.roles_for([:web]).first.hostname).to eq '1'
|
expect(servers.roles_for([:web]).first.hostname).to eq "1"
|
||||||
expect(servers.roles_for([:all]).first.properties.test).to eq :value
|
expect(servers.roles_for([:all]).first.properties.test).to eq :value
|
||||||
expect(servers.roles_for([:all]).first.properties.keys).to eq [:test]
|
expect(servers.roles_for([:all]).first.properties.keys).to eq [:test]
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'can accept multiple servers with the same hostname but different ports or users' do
|
it "can accept multiple servers with the same hostname but different ports or users" do
|
||||||
servers.add_host('1', :roles => [:app, 'web'], :test => :value, :port => 12)
|
servers.add_host("1", :roles => [:app, "web"], :test => :value, :port => 12)
|
||||||
servers.add_host('1', :roles => [:app, 'web'], :test => :value, :port => 34)
|
servers.add_host("1", :roles => [:app, "web"], :test => :value, :port => 34)
|
||||||
servers.add_host('1', :roles => [:app, 'web'], :test => :value, :user => 'root')
|
servers.add_host("1", :roles => [:app, "web"], :test => :value, :user => "root")
|
||||||
servers.add_host('1', :roles => [:app, 'web'], :test => :value, :user => 'deployer')
|
servers.add_host("1", :roles => [:app, "web"], :test => :value, :user => "deployer")
|
||||||
servers.add_host('1', :roles => [:app, 'web'], :test => :value, :user => 'root', :port => 34)
|
servers.add_host("1", :roles => [:app, "web"], :test => :value, :user => "root", :port => 34)
|
||||||
servers.add_host('1', :roles => [:app, 'web'], :test => :value, :user => 'deployer', :port => 34)
|
servers.add_host("1", :roles => [:app, "web"], :test => :value, :user => "deployer", :port => 34)
|
||||||
servers.add_host('1', :roles => [:app, 'web'], :test => :value, :user => 'deployer', :port => 56)
|
servers.add_host("1", :roles => [:app, "web"], :test => :value, :user => "deployer", :port => 56)
|
||||||
expect(servers.count).to eq(5)
|
expect(servers.count).to eq(5)
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "with a :user property" do
|
describe "with a :user property" do
|
||||||
|
|
||||||
it 'sets the server ssh username' do
|
it "sets the server ssh username" do
|
||||||
servers.add_host('1', :roles => [:app, 'web'], :user => 'nick')
|
servers.add_host("1", :roles => [:app, "web"], :user => "nick")
|
||||||
expect(servers.count).to eq(1)
|
expect(servers.count).to eq(1)
|
||||||
expect(servers.roles_for([:all]).first.user).to eq 'nick'
|
expect(servers.roles_for([:all]).first.user).to eq "nick"
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'overwrites the value of a user specified in the hostname' do
|
it "overwrites the value of a user specified in the hostname" do
|
||||||
servers.add_host('brian@1', :roles => [:app, 'web'], :user => 'nick')
|
servers.add_host("brian@1", :roles => [:app, "web"], :user => "nick")
|
||||||
expect(servers.count).to eq(1)
|
expect(servers.count).to eq(1)
|
||||||
expect(servers.roles_for([:all]).first.user).to eq 'nick'
|
expect(servers.roles_for([:all]).first.user).to eq "nick"
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'overwrites the value of a previously defined scalar property' do
|
it "overwrites the value of a previously defined scalar property" do
|
||||||
servers.add_host('1', :roles => [:app, 'web'], :test => :volatile)
|
servers.add_host("1", :roles => [:app, "web"], :test => :volatile)
|
||||||
expect(servers.count).to eq(1)
|
expect(servers.count).to eq(1)
|
||||||
expect(servers.roles_for([:all]).first.properties.test).to eq :volatile
|
expect(servers.roles_for([:all]).first.properties.test).to eq :volatile
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'merges previously defined hash properties' do
|
it "merges previously defined hash properties" do
|
||||||
servers.add_host('1', :roles => [:b], :db => { :port => 1234 })
|
servers.add_host("1", :roles => [:b], :db => { :port => 1234 })
|
||||||
servers.add_host('1', :roles => [:b], :db => { :master => true })
|
servers.add_host("1", :roles => [:b], :db => { :master => true })
|
||||||
expect(servers.count).to eq(1)
|
expect(servers.count).to eq(1)
|
||||||
expect(servers.roles_for([:b]).first.properties.db).to eq({ :port => 1234, :master => true })
|
expect(servers.roles_for([:b]).first.properties.db).to eq({ :port => 1234, :master => true })
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'concatenates previously defined array properties' do
|
it "concatenates previously defined array properties" do
|
||||||
servers.add_host('1', :roles => [:b], :steps => [1,3,5])
|
servers.add_host("1", :roles => [:b], :steps => [1,3,5])
|
||||||
servers.add_host('1', :roles => [:b], :steps => [1,9])
|
servers.add_host("1", :roles => [:b], :steps => [1,9])
|
||||||
expect(servers.count).to eq(1)
|
expect(servers.count).to eq(1)
|
||||||
expect(servers.roles_for([:b]).first.properties.steps).to eq([1,3,5,1,9])
|
expect(servers.roles_for([:b]).first.properties.steps).to eq([1,3,5,1,9])
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'merges previously defined set properties' do
|
it "merges previously defined set properties" do
|
||||||
servers.add_host('1', :roles => [:b], :endpoints => Set[123,333])
|
servers.add_host("1", :roles => [:b], :endpoints => Set[123,333])
|
||||||
servers.add_host('1', :roles => [:b], :endpoints => Set[222,333])
|
servers.add_host("1", :roles => [:b], :endpoints => Set[222,333])
|
||||||
expect(servers.count).to eq(1)
|
expect(servers.count).to eq(1)
|
||||||
expect(servers.roles_for([:b]).first.properties.endpoints).to eq(Set[123,222,333])
|
expect(servers.roles_for([:b]).first.properties.endpoints).to eq(Set[123,222,333])
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'adds array property value only ones for a new host' do
|
it "adds array property value only ones for a new host" do
|
||||||
servers.add_host('2', :roles => [:array_test], :array_property => [1,2])
|
servers.add_host("2", :roles => [:array_test], :array_property => [1,2])
|
||||||
expect(servers.roles_for([:array_test]).first.properties.array_property).to eq [1,2]
|
expect(servers.roles_for([:array_test]).first.properties.array_property).to eq [1,2]
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'updates roles when custom user defined' do
|
it "updates roles when custom user defined" do
|
||||||
servers.add_host('1', :roles => ['foo'], :user => 'custom')
|
servers.add_host("1", :roles => ["foo"], :user => "custom")
|
||||||
servers.add_host('1', :roles => ['bar'], :user => 'custom')
|
servers.add_host("1", :roles => ["bar"], :user => "custom")
|
||||||
expect(servers.roles_for([:foo]).first.hostname).to eq '1'
|
expect(servers.roles_for([:foo]).first.hostname).to eq "1"
|
||||||
expect(servers.roles_for([:bar]).first.hostname).to eq '1'
|
expect(servers.roles_for([:bar]).first.hostname).to eq "1"
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'updates roles when custom port defined' do
|
it "updates roles when custom port defined" do
|
||||||
servers.add_host('1', :roles => ['foo'], :port => 1234)
|
servers.add_host("1", :roles => ["foo"], :port => 1234)
|
||||||
servers.add_host('1', :roles => ['bar'], :port => 1234)
|
servers.add_host("1", :roles => ["bar"], :port => 1234)
|
||||||
expect(servers.roles_for([:foo]).first.hostname).to eq '1'
|
expect(servers.roles_for([:foo]).first.hostname).to eq "1"
|
||||||
expect(servers.roles_for([:bar]).first.hostname).to eq '1'
|
expect(servers.roles_for([:bar]).first.hostname).to eq "1"
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'selecting roles' do
|
describe "selecting roles" do
|
||||||
|
|
||||||
before do
|
before do
|
||||||
servers.add_host('1', :roles => :app, :active => true)
|
servers.add_host("1", :roles => :app, :active => true)
|
||||||
servers.add_host('2', :roles => :app)
|
servers.add_host("2", :roles => :app)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'is empty if the filter would remove all matching hosts' do
|
it "is empty if the filter would remove all matching hosts" do
|
||||||
expect(servers.roles_for([:app, :select => :inactive])).to be_empty
|
expect(servers.roles_for([:app, :select => :inactive])).to be_empty
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'can filter hosts by properties on the host object using symbol as shorthand' do
|
it "can filter hosts by properties on the host object using symbol as shorthand" do
|
||||||
expect(servers.roles_for([:app, :filter => :active]).length).to eq 1
|
expect(servers.roles_for([:app, :filter => :active]).length).to eq 1
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'can select hosts by properties on the host object using symbol as shorthand' do
|
it "can select hosts by properties on the host object using symbol as shorthand" do
|
||||||
expect(servers.roles_for([:app, :select => :active]).length).to eq 1
|
expect(servers.roles_for([:app, :select => :active]).length).to eq 1
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'can filter hosts by properties on the host using a regular proc' do
|
it "can filter hosts by properties on the host using a regular proc" do
|
||||||
expect(servers.roles_for([:app, :filter => ->(h) { h.properties.active }]).length).to eq 1
|
expect(servers.roles_for([:app, :filter => ->(h) { h.properties.active }]).length).to eq 1
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'can select hosts by properties on the host using a regular proc' do
|
it "can select hosts by properties on the host using a regular proc" do
|
||||||
expect(servers.roles_for([:app, :select => ->(h) { h.properties.active }]).length).to eq 1
|
expect(servers.roles_for([:app, :select => ->(h) { h.properties.active }]).length).to eq 1
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'is empty if the regular proc filter would remove all matching hosts' do
|
it "is empty if the regular proc filter would remove all matching hosts" do
|
||||||
expect(servers.roles_for([:app, :select => ->(h) { h.properties.inactive }])).to be_empty
|
expect(servers.roles_for([:app, :select => ->(h) { h.properties.inactive }])).to be_empty
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'excluding by property' do
|
describe "excluding by property" do
|
||||||
|
|
||||||
before do
|
before do
|
||||||
servers.add_host('1', :roles => :app, :active => true)
|
servers.add_host("1", :roles => :app, :active => true)
|
||||||
servers.add_host('2', :roles => :app, :active => true, :no_release => true)
|
servers.add_host("2", :roles => :app, :active => true, :no_release => true)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'is empty if the filter would remove all matching hosts' do
|
it "is empty if the filter would remove all matching hosts" do
|
||||||
hosts = servers.roles_for([:app, :exclude => :active])
|
hosts = servers.roles_for([:app, :exclude => :active])
|
||||||
expect(hosts.map(&:hostname)).to be_empty
|
expect(hosts.map(&:hostname)).to be_empty
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns the servers without the attributes specified' do
|
it "returns the servers without the attributes specified" do
|
||||||
hosts = servers.roles_for([:app, :exclude => :no_release])
|
hosts = servers.roles_for([:app, :exclude => :no_release])
|
||||||
expect(hosts.map(&:hostname)).to eq %w{1}
|
expect(hosts.map(&:hostname)).to eq %w{1}
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'can exclude hosts by properties on the host using a regular proc' do
|
it "can exclude hosts by properties on the host using a regular proc" do
|
||||||
hosts = servers.roles_for([:app, :exclude => ->(h) { h.properties.no_release }])
|
hosts = servers.roles_for([:app, :exclude => ->(h) { h.properties.no_release }])
|
||||||
expect(hosts.map(&:hostname)).to eq %w{1}
|
expect(hosts.map(&:hostname)).to eq %w{1}
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'is empty if the regular proc filter would remove all matching hosts' do
|
it "is empty if the regular proc filter would remove all matching hosts" do
|
||||||
hosts = servers.roles_for([:app, :exclude => ->(h) { h.properties.active }])
|
hosts = servers.roles_for([:app, :exclude => ->(h) { h.properties.active }])
|
||||||
expect(hosts.map(&:hostname)).to be_empty
|
expect(hosts.map(&:hostname)).to be_empty
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'filtering roles internally' do
|
describe "filtering roles internally" do
|
||||||
|
|
||||||
before do
|
before do
|
||||||
servers.add_host('1', :roles => :app, :active => true)
|
servers.add_host("1", :roles => :app, :active => true)
|
||||||
servers.add_host('2', :roles => :app)
|
servers.add_host("2", :roles => :app)
|
||||||
servers.add_host('3', :roles => :web)
|
servers.add_host("3", :roles => :web)
|
||||||
servers.add_host('4', :roles => :web)
|
servers.add_host("4", :roles => :web)
|
||||||
servers.add_host('5', :roles => :db)
|
servers.add_host("5", :roles => :db)
|
||||||
end
|
end
|
||||||
|
|
||||||
subject { servers.roles_for(roles).map(&:hostname) }
|
subject { servers.roles_for(roles).map(&:hostname) }
|
||||||
|
|
||||||
context 'with the ROLES environment variable set' do
|
context "with the ROLES environment variable set" do
|
||||||
|
|
||||||
before do
|
before do
|
||||||
ENV.stubs(:[]).with('ROLES').returns('web,db')
|
ENV.stubs(:[]).with("ROLES").returns("web,db")
|
||||||
ENV.stubs(:[]).with('HOSTS').returns(nil)
|
ENV.stubs(:[]).with("HOSTS").returns(nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when selecting all roles' do
|
context "when selecting all roles" do
|
||||||
let(:roles) { [:all] }
|
let(:roles) { [:all] }
|
||||||
it 'ignores it' do
|
it "ignores it" do
|
||||||
expect(subject).to eq %w{1 2 3 4 5}
|
expect(subject).to eq %w{1 2 3 4 5}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when selecting specific roles' do
|
context "when selecting specific roles" do
|
||||||
let(:roles) { [:app, :web] }
|
let(:roles) { [:app, :web] }
|
||||||
it 'ignores it' do
|
it "ignores it" do
|
||||||
expect(subject).to eq %w{1 2 3 4}
|
expect(subject).to eq %w{1 2 3 4}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when selecting roles not included in ROLE' do
|
context "when selecting roles not included in ROLE" do
|
||||||
let(:roles) { [:app] }
|
let(:roles) { [:app] }
|
||||||
it 'ignores it' do
|
it "ignores it" do
|
||||||
expect(subject).to eq %w{1 2}
|
expect(subject).to eq %w{1 2}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with the HOSTS environment variable set' do
|
context "with the HOSTS environment variable set" do
|
||||||
|
|
||||||
before do
|
before do
|
||||||
ENV.stubs(:[]).with('ROLES').returns(nil)
|
ENV.stubs(:[]).with("ROLES").returns(nil)
|
||||||
ENV.stubs(:[]).with('HOSTS').returns('3,5')
|
ENV.stubs(:[]).with("HOSTS").returns("3,5")
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when selecting all roles' do
|
context "when selecting all roles" do
|
||||||
let(:roles) { [:all] }
|
let(:roles) { [:all] }
|
||||||
it 'ignores it' do
|
it "ignores it" do
|
||||||
expect(subject).to eq %w{1 2 3 4 5}
|
expect(subject).to eq %w{1 2 3 4 5}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when selecting specific roles' do
|
context "when selecting specific roles" do
|
||||||
let(:roles) { [:app, :web] }
|
let(:roles) { [:app, :web] }
|
||||||
it 'ignores it' do
|
it "ignores it" do
|
||||||
expect(subject).to eq %w{1 2 3 4}
|
expect(subject).to eq %w{1 2 3 4}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when selecting no roles' do
|
context "when selecting no roles" do
|
||||||
let(:roles) { [] }
|
let(:roles) { [] }
|
||||||
it 'ignores it' do
|
it "ignores it" do
|
||||||
expect(subject).to be_empty
|
expect(subject).to be_empty
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,34 +1,34 @@
|
||||||
require 'spec_helper'
|
require "spec_helper"
|
||||||
|
|
||||||
module Capistrano
|
module Capistrano
|
||||||
describe Configuration do
|
describe Configuration do
|
||||||
let(:config) { Configuration.new }
|
let(:config) { Configuration.new }
|
||||||
let(:servers) { stub }
|
let(:servers) { stub }
|
||||||
|
|
||||||
describe '.new' do
|
describe ".new" do
|
||||||
it 'accepts initial hash' do
|
it "accepts initial hash" do
|
||||||
configuration = described_class.new(:custom => 'value')
|
configuration = described_class.new(:custom => "value")
|
||||||
expect(configuration.fetch(:custom)).to eq('value')
|
expect(configuration.fetch(:custom)).to eq("value")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '.env' do
|
describe ".env" do
|
||||||
it 'is a global accessor to a single instance' do
|
it "is a global accessor to a single instance" do
|
||||||
Configuration.env.set(:test, true)
|
Configuration.env.set(:test, true)
|
||||||
expect(Configuration.env.fetch(:test)).to be_truthy
|
expect(Configuration.env.fetch(:test)).to be_truthy
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '.reset!' do
|
describe ".reset!" do
|
||||||
it 'blows away the existing `env` and creates a new one' do
|
it "blows away the existing `env` and creates a new one" do
|
||||||
old_env = Configuration.env
|
old_env = Configuration.env
|
||||||
Configuration.reset!
|
Configuration.reset!
|
||||||
expect(Configuration.env).not_to be old_env
|
expect(Configuration.env).not_to be old_env
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'roles' do
|
describe "roles" do
|
||||||
context 'adding a role' do
|
context "adding a role" do
|
||||||
subject { config.role(:app, %w{server1 server2}) }
|
subject { config.role(:app, %w{server1 server2}) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
|
@ -36,43 +36,43 @@ module Capistrano
|
||||||
servers.expects(:add_role).with(:app, %w{server1 server2}, {})
|
servers.expects(:add_role).with(:app, %w{server1 server2}, {})
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'adds the role' do
|
it "adds the role" do
|
||||||
expect(subject)
|
expect(subject)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'setting and fetching' do
|
describe "setting and fetching" do
|
||||||
subject { config.fetch(:key, :default) }
|
subject { config.fetch(:key, :default) }
|
||||||
|
|
||||||
context 'set' do
|
context "set" do
|
||||||
it 'sets by value' do
|
it "sets by value" do
|
||||||
config.set(:key, :value)
|
config.set(:key, :value)
|
||||||
expect(subject).to eq :value
|
expect(subject).to eq :value
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'sets by block' do
|
it "sets by block" do
|
||||||
config.set(:key) { :value }
|
config.set(:key) { :value }
|
||||||
expect(subject).to eq :value
|
expect(subject).to eq :value
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'raises an exception when given both a value and block' do
|
it "raises an exception when given both a value and block" do
|
||||||
expect{ config.set(:key, :value) { :value } }.to raise_error(Capistrano::ValidationError)
|
expect{ config.set(:key, :value) { :value } }.to raise_error(Capistrano::ValidationError)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'set_if_empty' do
|
context "set_if_empty" do
|
||||||
it 'sets by value when none is present' do
|
it "sets by value when none is present" do
|
||||||
config.set_if_empty(:key, :value)
|
config.set_if_empty(:key, :value)
|
||||||
expect(subject).to eq :value
|
expect(subject).to eq :value
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'sets by block when none is present' do
|
it "sets by block when none is present" do
|
||||||
config.set_if_empty(:key) { :value }
|
config.set_if_empty(:key) { :value }
|
||||||
expect(subject).to eq :value
|
expect(subject).to eq :value
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not overwrite existing values' do
|
it "does not overwrite existing values" do
|
||||||
config.set(:key, :value)
|
config.set(:key, :value)
|
||||||
config.set_if_empty(:key, :update)
|
config.set_if_empty(:key, :update)
|
||||||
config.set_if_empty(:key) { :update }
|
config.set_if_empty(:key) { :update }
|
||||||
|
@ -80,136 +80,136 @@ module Capistrano
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'value is not set' do
|
context "value is not set" do
|
||||||
it 'returns the default value' do
|
it "returns the default value" do
|
||||||
expect(subject).to eq :default
|
expect(subject).to eq :default
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'value is a proc' do
|
context "value is a proc" do
|
||||||
subject { config.fetch(:key, Proc.new { :proc } ) }
|
subject { config.fetch(:key, Proc.new { :proc } ) }
|
||||||
it 'calls the proc' do
|
it "calls the proc" do
|
||||||
expect(subject).to eq :proc
|
expect(subject).to eq :proc
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'value is a lambda' do
|
context "value is a lambda" do
|
||||||
subject { config.fetch(:key, lambda { :lambda } ) }
|
subject { config.fetch(:key, lambda { :lambda } ) }
|
||||||
it 'calls the lambda' do
|
it "calls the lambda" do
|
||||||
expect(subject).to eq :lambda
|
expect(subject).to eq :lambda
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'value inside proc inside a proc' do
|
context "value inside proc inside a proc" do
|
||||||
subject { config.fetch(:key, Proc.new { Proc.new { "some value" } } ) }
|
subject { config.fetch(:key, Proc.new { Proc.new { "some value" } } ) }
|
||||||
it 'calls all procs and lambdas' do
|
it "calls all procs and lambdas" do
|
||||||
expect(subject).to eq "some value"
|
expect(subject).to eq "some value"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'value inside lambda inside a lambda' do
|
context "value inside lambda inside a lambda" do
|
||||||
subject { config.fetch(:key, lambda { lambda { "some value" } } ) }
|
subject { config.fetch(:key, lambda { lambda { "some value" } } ) }
|
||||||
it 'calls all procs and lambdas' do
|
it "calls all procs and lambdas" do
|
||||||
expect(subject).to eq "some value"
|
expect(subject).to eq "some value"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'value inside lambda inside a proc' do
|
context "value inside lambda inside a proc" do
|
||||||
subject { config.fetch(:key, Proc.new { lambda { "some value" } } ) }
|
subject { config.fetch(:key, Proc.new { lambda { "some value" } } ) }
|
||||||
it 'calls all procs and lambdas' do
|
it "calls all procs and lambdas" do
|
||||||
expect(subject).to eq "some value"
|
expect(subject).to eq "some value"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'value inside proc inside a lambda' do
|
context "value inside proc inside a lambda" do
|
||||||
subject { config.fetch(:key, lambda { Proc.new { "some value" } } ) }
|
subject { config.fetch(:key, lambda { Proc.new { "some value" } } ) }
|
||||||
it 'calls all procs and lambdas' do
|
it "calls all procs and lambdas" do
|
||||||
expect(subject).to eq "some value"
|
expect(subject).to eq "some value"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'lambda with parameters' do
|
context "lambda with parameters" do
|
||||||
subject { config.fetch(:key, lambda { |c| c }).call(42) }
|
subject { config.fetch(:key, lambda { |c| c }).call(42) }
|
||||||
it 'is returned as a lambda' do
|
it "is returned as a lambda" do
|
||||||
expect(subject).to eq 42
|
expect(subject).to eq 42
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'block is passed to fetch' do
|
context "block is passed to fetch" do
|
||||||
subject { config.fetch(:key, :default) { fail 'we need this!' } }
|
subject { config.fetch(:key, :default) { fail "we need this!" } }
|
||||||
|
|
||||||
it 'returns the block value' do
|
it "returns the block value" do
|
||||||
expect { subject }.to raise_error(RuntimeError)
|
expect { subject }.to raise_error(RuntimeError)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'validations' do
|
context "validations" do
|
||||||
before do
|
before do
|
||||||
config.validate :key do |_, value|
|
config.validate :key do |_, value|
|
||||||
raise Capistrano::ValidationError unless value.length > 3
|
raise Capistrano::ValidationError unless value.length > 3
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'validates without error' do
|
it "validates without error" do
|
||||||
config.set(:key, 'longer_value')
|
config.set(:key, "longer_value")
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'raises an exception' do
|
it "raises an exception" do
|
||||||
expect{ config.set(:key, 'sho') }.to raise_error(Capistrano::ValidationError)
|
expect{ config.set(:key, "sho") }.to raise_error(Capistrano::ValidationError)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'appending' do
|
context "appending" do
|
||||||
subject { config.append(:linked_dirs, 'vendor/bundle', 'tmp') }
|
subject { config.append(:linked_dirs, "vendor/bundle", "tmp") }
|
||||||
|
|
||||||
it "returns appended value" do
|
it "returns appended value" do
|
||||||
expect(subject).to eq ['vendor/bundle', 'tmp']
|
expect(subject).to eq ["vendor/bundle", "tmp"]
|
||||||
end
|
end
|
||||||
|
|
||||||
context "on non-array variable" do
|
context "on non-array variable" do
|
||||||
before { config.set(:linked_dirs, "string") }
|
before { config.set(:linked_dirs, "string") }
|
||||||
subject { config.append(:linked_dirs, 'vendor/bundle') }
|
subject { config.append(:linked_dirs, "vendor/bundle") }
|
||||||
|
|
||||||
it "returns appended value" do
|
it "returns appended value" do
|
||||||
expect(subject).to eq ['string', 'vendor/bundle']
|
expect(subject).to eq ["string", "vendor/bundle"]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'removing' do
|
context "removing" do
|
||||||
before :each do
|
before :each do
|
||||||
config.set(:linked_dirs, ['vendor/bundle', 'tmp'])
|
config.set(:linked_dirs, ["vendor/bundle", "tmp"])
|
||||||
end
|
end
|
||||||
|
|
||||||
subject { config.remove(:linked_dirs, 'vendor/bundle') }
|
subject { config.remove(:linked_dirs, "vendor/bundle") }
|
||||||
|
|
||||||
it 'returns without removed value' do
|
it "returns without removed value" do
|
||||||
expect(subject).to eq ['tmp']
|
expect(subject).to eq ["tmp"]
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'on non-array variable' do
|
context "on non-array variable" do
|
||||||
before { config.set(:linked_dirs, 'string') }
|
before { config.set(:linked_dirs, "string") }
|
||||||
|
|
||||||
context 'when removing same value' do
|
context "when removing same value" do
|
||||||
subject { config.remove(:linked_dirs, 'string') }
|
subject { config.remove(:linked_dirs, "string") }
|
||||||
|
|
||||||
it 'returns without removed value' do
|
it "returns without removed value" do
|
||||||
expect(subject).to eq []
|
expect(subject).to eq []
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when removing different value' do
|
context "when removing different value" do
|
||||||
subject { config.remove(:linked_dirs, 'othervalue') }
|
subject { config.remove(:linked_dirs, "othervalue") }
|
||||||
|
|
||||||
it 'returns without removed value' do
|
it "returns without removed value" do
|
||||||
expect(subject).to eq ['string']
|
expect(subject).to eq ["string"]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'keys' do
|
describe "keys" do
|
||||||
subject { config.keys }
|
subject { config.keys }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
|
@ -217,23 +217,23 @@ module Capistrano
|
||||||
config.set(:key2, :value2)
|
config.set(:key2, :value2)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns all set keys' do
|
it "returns all set keys" do
|
||||||
expect(subject).to match_array [:key1, :key2]
|
expect(subject).to match_array [:key1, :key2]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'deleting' do
|
describe "deleting" do
|
||||||
before do
|
before do
|
||||||
config.set(:key, :value)
|
config.set(:key, :value)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'deletes the value' do
|
it "deletes the value" do
|
||||||
config.delete(:key)
|
config.delete(:key)
|
||||||
expect(config.fetch(:key)).to be_nil
|
expect(config.fetch(:key)).to be_nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'asking' do
|
describe "asking" do
|
||||||
let(:question) { stub }
|
let(:question) { stub }
|
||||||
let(:options) { Hash.new }
|
let(:options) { Hash.new }
|
||||||
|
|
||||||
|
@ -242,30 +242,30 @@ module Capistrano
|
||||||
returns(question)
|
returns(question)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'prompts for the value when fetching' do
|
it "prompts for the value when fetching" do
|
||||||
config.ask(:branch, :default, options)
|
config.ask(:branch, :default, options)
|
||||||
expect(config.fetch(:branch)).to eq question
|
expect(config.fetch(:branch)).to eq question
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'setting the backend' do
|
describe "setting the backend" do
|
||||||
it 'by default, is SSHKit' do
|
it "by default, is SSHKit" do
|
||||||
expect(config.backend).to eq SSHKit
|
expect(config.backend).to eq SSHKit
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'can be set to another class' do
|
it "can be set to another class" do
|
||||||
config.backend = :test
|
config.backend = :test
|
||||||
expect(config.backend).to eq :test
|
expect(config.backend).to eq :test
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "ssh_options for Netssh" do
|
describe "ssh_options for Netssh" do
|
||||||
it 'merges them with the :ssh_options variable' do
|
it "merges them with the :ssh_options variable" do
|
||||||
config.set :format, :pretty
|
config.set :format, :pretty
|
||||||
config.set :log_level, :debug
|
config.set :log_level, :debug
|
||||||
config.set :ssh_options, { :user => 'albert' }
|
config.set :ssh_options, { :user => "albert" }
|
||||||
SSHKit::Backend::Netssh.configure do |ssh| ssh.ssh_options = { :password => 'einstein' } end
|
SSHKit::Backend::Netssh.configure do |ssh| ssh.ssh_options = { :password => "einstein" } end
|
||||||
config.configure_backend
|
config.configure_backend
|
||||||
expect(config.backend.config.backend.config.ssh_options).to eq({ :user => 'albert', :password => 'einstein' })
|
expect(config.backend.config.backend.config.ssh_options).to eq({ :user => "albert", :password => "einstein" })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
require 'spec_helper'
|
require "spec_helper"
|
||||||
|
|
||||||
describe Capistrano::DSL::Paths do
|
describe Capistrano::DSL::Paths do
|
||||||
|
|
||||||
let(:dsl) { Class.new.extend Capistrano::DSL }
|
let(:dsl) { Class.new.extend Capistrano::DSL }
|
||||||
let(:parent) { Pathname.new('/var/shared') }
|
let(:parent) { Pathname.new("/var/shared") }
|
||||||
let(:paths) { Class.new.extend Capistrano::DSL::Paths }
|
let(:paths) { Class.new.extend Capistrano::DSL::Paths }
|
||||||
|
|
||||||
let(:linked_dirs) { %w{log public/system} }
|
let(:linked_dirs) { %w{log public/system} }
|
||||||
let(:linked_files) { %w{config/database.yml log/my.log log/access.log} }
|
let(:linked_files) { %w{config/database.yml log/my.log log/access.log} }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
dsl.set(:deploy_to, '/var/www')
|
dsl.set(:deploy_to, "/var/www")
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#linked_dirs' do
|
describe '#linked_dirs' do
|
||||||
|
@ -20,10 +20,10 @@ describe Capistrano::DSL::Paths do
|
||||||
paths.expects(:fetch).with(:linked_dirs).returns(linked_dirs)
|
paths.expects(:fetch).with(:linked_dirs).returns(linked_dirs)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns the full pathnames' do
|
it "returns the full pathnames" do
|
||||||
expect(subject).to eq [
|
expect(subject).to eq [
|
||||||
Pathname.new('/var/shared/log'),
|
Pathname.new("/var/shared/log"),
|
||||||
Pathname.new('/var/shared/public/system'),
|
Pathname.new("/var/shared/public/system"),
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -36,11 +36,11 @@ describe Capistrano::DSL::Paths do
|
||||||
paths.expects(:fetch).with(:linked_files).returns(linked_files)
|
paths.expects(:fetch).with(:linked_files).returns(linked_files)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns the full pathnames' do
|
it "returns the full pathnames" do
|
||||||
expect(subject).to eq [
|
expect(subject).to eq [
|
||||||
Pathname.new('/var/shared/config/database.yml'),
|
Pathname.new("/var/shared/config/database.yml"),
|
||||||
Pathname.new('/var/shared/log/my.log'),
|
Pathname.new("/var/shared/log/my.log"),
|
||||||
Pathname.new('/var/shared/log/access.log'),
|
Pathname.new("/var/shared/log/access.log"),
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -52,10 +52,10 @@ describe Capistrano::DSL::Paths do
|
||||||
paths.expects(:fetch).with(:linked_files).returns(linked_files)
|
paths.expects(:fetch).with(:linked_files).returns(linked_files)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns the full paths names of the parent dirs' do
|
it "returns the full paths names of the parent dirs" do
|
||||||
expect(subject).to eq [
|
expect(subject).to eq [
|
||||||
Pathname.new('/var/shared/config'),
|
Pathname.new("/var/shared/config"),
|
||||||
Pathname.new('/var/shared/log'),
|
Pathname.new("/var/shared/log"),
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -67,10 +67,10 @@ describe Capistrano::DSL::Paths do
|
||||||
paths.expects(:fetch).with(:linked_dirs).returns(linked_dirs)
|
paths.expects(:fetch).with(:linked_dirs).returns(linked_dirs)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns the full paths names of the parent dirs' do
|
it "returns the full paths names of the parent dirs" do
|
||||||
expect(subject).to eq [
|
expect(subject).to eq [
|
||||||
Pathname.new('/var/shared'),
|
Pathname.new("/var/shared"),
|
||||||
Pathname.new('/var/shared/public'),
|
Pathname.new("/var/shared/public"),
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -79,23 +79,23 @@ describe Capistrano::DSL::Paths do
|
||||||
|
|
||||||
subject { dsl.release_path }
|
subject { dsl.release_path }
|
||||||
|
|
||||||
context 'where no release path has been set' do
|
context "where no release path has been set" do
|
||||||
before do
|
before do
|
||||||
dsl.delete(:release_path)
|
dsl.delete(:release_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns the `current_path` value' do
|
it "returns the `current_path` value" do
|
||||||
expect(subject.to_s).to eq '/var/www/current'
|
expect(subject.to_s).to eq "/var/www/current"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'where the release path has been set' do
|
context "where the release path has been set" do
|
||||||
before do
|
before do
|
||||||
dsl.set(:release_path,'/var/www/release_path')
|
dsl.set(:release_path,"/var/www/release_path")
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns the set `release_path` value' do
|
it "returns the set `release_path` value" do
|
||||||
expect(subject.to_s).to eq '/var/www/release_path'
|
expect(subject.to_s).to eq "/var/www/release_path"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -104,24 +104,24 @@ describe Capistrano::DSL::Paths do
|
||||||
let(:now) { Time.parse("Oct 21 16:29:00 2015") }
|
let(:now) { Time.parse("Oct 21 16:29:00 2015") }
|
||||||
subject { dsl.release_path }
|
subject { dsl.release_path }
|
||||||
|
|
||||||
context 'without a timestamp' do
|
context "without a timestamp" do
|
||||||
before do
|
before do
|
||||||
dsl.env.expects(:timestamp).returns(now)
|
dsl.env.expects(:timestamp).returns(now)
|
||||||
dsl.set_release_path
|
dsl.set_release_path
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns the release path with the current env timestamp' do
|
it "returns the release path with the current env timestamp" do
|
||||||
expect(subject.to_s).to eq '/var/www/releases/20151021162900'
|
expect(subject.to_s).to eq "/var/www/releases/20151021162900"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with a timestamp' do
|
context "with a timestamp" do
|
||||||
before do
|
before do
|
||||||
dsl.set_release_path('timestamp')
|
dsl.set_release_path("timestamp")
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns the release path with the timestamp' do
|
it "returns the release path with the timestamp" do
|
||||||
expect(subject.to_s).to eq '/var/www/releases/timestamp'
|
expect(subject.to_s).to eq "/var/www/releases/timestamp"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -129,23 +129,23 @@ describe Capistrano::DSL::Paths do
|
||||||
describe '#deploy_config_path' do
|
describe '#deploy_config_path' do
|
||||||
subject { dsl.deploy_config_path.to_s }
|
subject { dsl.deploy_config_path.to_s }
|
||||||
|
|
||||||
context 'when not specified' do
|
context "when not specified" do
|
||||||
before do
|
before do
|
||||||
dsl.delete(:deploy_config_path)
|
dsl.delete(:deploy_config_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns "config/deploy.rb"' do
|
it 'returns "config/deploy.rb"' do
|
||||||
expect(subject).to eq 'config/deploy.rb'
|
expect(subject).to eq "config/deploy.rb"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when the variable :deploy_config_path is set' do
|
context "when the variable :deploy_config_path is set" do
|
||||||
before do
|
before do
|
||||||
dsl.set(:deploy_config_path, 'my/custom/path.rb')
|
dsl.set(:deploy_config_path, "my/custom/path.rb")
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns the custom path' do
|
it "returns the custom path" do
|
||||||
expect(subject).to eq 'my/custom/path.rb'
|
expect(subject).to eq "my/custom/path.rb"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -153,24 +153,24 @@ describe Capistrano::DSL::Paths do
|
||||||
describe '#stage_config_path' do
|
describe '#stage_config_path' do
|
||||||
subject { dsl.stage_config_path.to_s }
|
subject { dsl.stage_config_path.to_s }
|
||||||
|
|
||||||
context 'when not specified' do
|
context "when not specified" do
|
||||||
|
|
||||||
before do
|
before do
|
||||||
dsl.delete(:stage_config_path)
|
dsl.delete(:stage_config_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns "config/deploy"' do
|
it 'returns "config/deploy"' do
|
||||||
expect(subject).to eq 'config/deploy'
|
expect(subject).to eq "config/deploy"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when the variable :stage_config_path is set' do
|
context "when the variable :stage_config_path is set" do
|
||||||
before do
|
before do
|
||||||
dsl.set(:stage_config_path, 'my/custom/path')
|
dsl.set(:stage_config_path, "my/custom/path")
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns the custom path' do
|
it "returns the custom path" do
|
||||||
expect(subject).to eq 'my/custom/path'
|
expect(subject).to eq "my/custom/path"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -178,25 +178,25 @@ describe Capistrano::DSL::Paths do
|
||||||
describe '#repo_path' do
|
describe '#repo_path' do
|
||||||
subject { dsl.repo_path.to_s }
|
subject { dsl.repo_path.to_s }
|
||||||
|
|
||||||
context 'when not specified' do
|
context "when not specified" do
|
||||||
|
|
||||||
before do
|
before do
|
||||||
dsl.delete(:repo_path)
|
dsl.delete(:repo_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns the default #{deploy_to}/repo' do
|
it 'returns the default #{deploy_to}/repo' do
|
||||||
dsl.set(:deploy_to, '/var/www')
|
dsl.set(:deploy_to, "/var/www")
|
||||||
expect(subject).to eq '/var/www/repo'
|
expect(subject).to eq "/var/www/repo"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when the variable :repo_path is set' do
|
context "when the variable :repo_path is set" do
|
||||||
before do
|
before do
|
||||||
dsl.set(:repo_path, 'my/custom/path')
|
dsl.set(:repo_path, "my/custom/path")
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns the custom path' do
|
it "returns the custom path" do
|
||||||
expect(subject).to eq 'my/custom/path'
|
expect(subject).to eq "my/custom/path"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
require 'spec_helper'
|
require "spec_helper"
|
||||||
|
|
||||||
module Capistrano
|
module Capistrano
|
||||||
class DummyTaskEnhancements
|
class DummyTaskEnhancements
|
||||||
|
@ -8,7 +8,7 @@ module Capistrano
|
||||||
describe TaskEnhancements do
|
describe TaskEnhancements do
|
||||||
let(:task_enhancements) { DummyTaskEnhancements.new }
|
let(:task_enhancements) { DummyTaskEnhancements.new }
|
||||||
|
|
||||||
describe 'ordering' do
|
describe "ordering" do
|
||||||
|
|
||||||
after do
|
after do
|
||||||
task.clear
|
task.clear
|
||||||
|
@ -19,100 +19,100 @@ module Capistrano
|
||||||
|
|
||||||
let(:order) { [] }
|
let(:order) { [] }
|
||||||
let!(:task) do
|
let!(:task) do
|
||||||
Rake::Task.define_task('task', [:order]) do |_t, args|
|
Rake::Task.define_task("task", [:order]) do |_t, args|
|
||||||
args['order'].push 'task'
|
args["order"].push "task"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
let!(:before_task) do
|
let!(:before_task) do
|
||||||
Rake::Task.define_task('before_task') do
|
Rake::Task.define_task("before_task") do
|
||||||
order.push 'before_task'
|
order.push "before_task"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
let!(:after_task) do
|
let!(:after_task) do
|
||||||
Rake::Task.define_task('after_task') do
|
Rake::Task.define_task("after_task") do
|
||||||
order.push 'after_task'
|
order.push "after_task"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'invokes in proper order if define after than before' do
|
it "invokes in proper order if define after than before" do
|
||||||
task_enhancements.after('task', 'after_task')
|
task_enhancements.after("task", "after_task")
|
||||||
task_enhancements.before('task', 'before_task')
|
task_enhancements.before("task", "before_task")
|
||||||
|
|
||||||
Rake::Task['task'].invoke order
|
Rake::Task["task"].invoke order
|
||||||
|
|
||||||
expect(order).to eq(['before_task', 'task', 'after_task'])
|
expect(order).to eq(["before_task", "task", "after_task"])
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'invokes in proper order if define before than after' do
|
it "invokes in proper order if define before than after" do
|
||||||
task_enhancements.before('task', 'before_task')
|
task_enhancements.before("task", "before_task")
|
||||||
task_enhancements.after('task', 'after_task')
|
task_enhancements.after("task", "after_task")
|
||||||
|
|
||||||
Rake::Task['task'].invoke order
|
Rake::Task["task"].invoke order
|
||||||
|
|
||||||
expect(order).to eq(['before_task', 'task', 'after_task'])
|
expect(order).to eq(["before_task", "task", "after_task"])
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'invokes in proper order when referring to as-yet undefined tasks' do
|
it "invokes in proper order when referring to as-yet undefined tasks" do
|
||||||
task_enhancements.after('task', 'not_loaded_task')
|
task_enhancements.after("task", "not_loaded_task")
|
||||||
|
|
||||||
Rake::Task.define_task('not_loaded_task') do
|
Rake::Task.define_task("not_loaded_task") do
|
||||||
order.push 'not_loaded_task'
|
order.push "not_loaded_task"
|
||||||
end
|
end
|
||||||
|
|
||||||
Rake::Task['task'].invoke order
|
Rake::Task["task"].invoke order
|
||||||
|
|
||||||
expect(order).to eq(['task', 'not_loaded_task'])
|
expect(order).to eq(["task", "not_loaded_task"])
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'invokes in proper order and with arguments and block' do
|
it "invokes in proper order and with arguments and block" do
|
||||||
task_enhancements.after('task', 'after_task_custom', :order) do |_t, _args|
|
task_enhancements.after("task", "after_task_custom", :order) do |_t, _args|
|
||||||
order.push 'after_task'
|
order.push "after_task"
|
||||||
end
|
end
|
||||||
|
|
||||||
task_enhancements.before('task', 'before_task_custom', :order) do |_t, _args|
|
task_enhancements.before("task", "before_task_custom", :order) do |_t, _args|
|
||||||
order.push 'before_task'
|
order.push "before_task"
|
||||||
end
|
end
|
||||||
|
|
||||||
Rake::Task['task'].invoke(order)
|
Rake::Task["task"].invoke(order)
|
||||||
|
|
||||||
expect(order).to eq(['before_task', 'task', 'after_task'])
|
expect(order).to eq(["before_task", "task", "after_task"])
|
||||||
end
|
end
|
||||||
|
|
||||||
it "invokes using the correct namespace when defined within a namespace" do
|
it "invokes using the correct namespace when defined within a namespace" do
|
||||||
Rake.application.in_namespace('namespace') {
|
Rake.application.in_namespace("namespace") {
|
||||||
Rake::Task.define_task('task') do |t|
|
Rake::Task.define_task("task") do |t|
|
||||||
order.push(t.name)
|
order.push(t.name)
|
||||||
end
|
end
|
||||||
task_enhancements.before('task', 'before_task', :order) do |t|
|
task_enhancements.before("task", "before_task", :order) do |t|
|
||||||
order.push(t.name)
|
order.push(t.name)
|
||||||
end
|
end
|
||||||
task_enhancements.after('task', 'after_task', :order) do |t|
|
task_enhancements.after("task", "after_task", :order) do |t|
|
||||||
order.push(t.name)
|
order.push(t.name)
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
Rake::Task['namespace:task'].invoke
|
Rake::Task["namespace:task"].invoke
|
||||||
|
|
||||||
expect(order).to eq(
|
expect(order).to eq(
|
||||||
['namespace:before_task', 'namespace:task', 'namespace:after_task']
|
["namespace:before_task", "namespace:task", "namespace:after_task"]
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'remote_file' do
|
describe "remote_file" do
|
||||||
subject(:remote_file) { task_enhancements.remote_file('source' => 'destination') }
|
subject(:remote_file) { task_enhancements.remote_file("source" => "destination") }
|
||||||
|
|
||||||
it { expect(remote_file.name).to eq('source') }
|
it { expect(remote_file.name).to eq("source") }
|
||||||
it { is_expected.to be_a(Capistrano::UploadTask) }
|
it { is_expected.to be_a(Capistrano::UploadTask) }
|
||||||
|
|
||||||
describe 'namespaced' do
|
describe "namespaced" do
|
||||||
let(:app) { Rake.application }
|
let(:app) { Rake.application }
|
||||||
around { |ex| app.in_namespace('namespace', &ex) }
|
around { |ex| app.in_namespace("namespace", &ex) }
|
||||||
|
|
||||||
it { expect(remote_file.name).to eq('source') }
|
it { expect(remote_file.name).to eq("source") }
|
||||||
it { is_expected.to be_a(Capistrano::UploadTask) }
|
it { is_expected.to be_a(Capistrano::UploadTask) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
require 'spec_helper'
|
require "spec_helper"
|
||||||
|
|
||||||
module Capistrano
|
module Capistrano
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ module Capistrano
|
||||||
I18n.expects(:t).with(:phrase, {:count => 2, :scope => :capistrano})
|
I18n.expects(:t).with(:phrase, {:count => 2, :scope => :capistrano})
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'delegates to I18n' do
|
it "delegates to I18n" do
|
||||||
dsl.t(:phrase, :count => 2)
|
dsl.t(:phrase, :count => 2)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -23,14 +23,14 @@ module Capistrano
|
||||||
describe '#stage_set?' do
|
describe '#stage_set?' do
|
||||||
subject { dsl.stage_set? }
|
subject { dsl.stage_set? }
|
||||||
|
|
||||||
context 'stage is set' do
|
context "stage is set" do
|
||||||
before do
|
before do
|
||||||
dsl.set(:stage, :sandbox)
|
dsl.set(:stage, :sandbox)
|
||||||
end
|
end
|
||||||
it { expect(subject).to be_truthy }
|
it { expect(subject).to be_truthy }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'stage is not set' do
|
context "stage is not set" do
|
||||||
before do
|
before do
|
||||||
dsl.set(:stage, nil)
|
dsl.set(:stage, nil)
|
||||||
end
|
end
|
||||||
|
@ -44,7 +44,7 @@ module Capistrano
|
||||||
dsl.expects(:execute).with(:sudo, :my, :command)
|
dsl.expects(:execute).with(:sudo, :my, :command)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'prepends sudo, delegates to execute' do
|
it "prepends sudo, delegates to execute" do
|
||||||
dsl.sudo(:my, :command)
|
dsl.sudo(:my, :command)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
require 'spec_helper'
|
require "spec_helper"
|
||||||
|
|
||||||
require 'capistrano/git'
|
require "capistrano/git"
|
||||||
|
|
||||||
module Capistrano
|
module Capistrano
|
||||||
describe Git do
|
describe Git do
|
||||||
|
@ -42,17 +42,17 @@ module Capistrano
|
||||||
context.expects(:fetch).with(:git_shallow_clone).returns(nil)
|
context.expects(:fetch).with(:git_shallow_clone).returns(nil)
|
||||||
context.expects(:repo_url).returns(:url)
|
context.expects(:repo_url).returns(:url)
|
||||||
context.expects(:repo_path).returns(:path)
|
context.expects(:repo_path).returns(:path)
|
||||||
context.expects(:execute).with(:git, :clone, '--mirror', :url, :path)
|
context.expects(:execute).with(:git, :clone, "--mirror", :url, :path)
|
||||||
|
|
||||||
subject.clone
|
subject.clone
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should run git clone in shallow mode" do
|
it "should run git clone in shallow mode" do
|
||||||
context.expects(:fetch).with(:git_shallow_clone).returns('1')
|
context.expects(:fetch).with(:git_shallow_clone).returns("1")
|
||||||
context.expects(:repo_url).returns(:url)
|
context.expects(:repo_url).returns(:url)
|
||||||
context.expects(:repo_path).returns(:path)
|
context.expects(:repo_path).returns(:path)
|
||||||
|
|
||||||
context.expects(:execute).with(:git, :clone, '--mirror', "--depth", '1', '--no-single-branch', :url, :path)
|
context.expects(:execute).with(:git, :clone, "--mirror", "--depth", "1", "--no-single-branch", :url, :path)
|
||||||
|
|
||||||
subject.clone
|
subject.clone
|
||||||
end
|
end
|
||||||
|
@ -61,15 +61,15 @@ module Capistrano
|
||||||
describe "#update" do
|
describe "#update" do
|
||||||
it "should run git update" do
|
it "should run git update" do
|
||||||
context.expects(:fetch).with(:git_shallow_clone).returns(nil)
|
context.expects(:fetch).with(:git_shallow_clone).returns(nil)
|
||||||
context.expects(:execute).with(:git, :remote, :update, '--prune')
|
context.expects(:execute).with(:git, :remote, :update, "--prune")
|
||||||
|
|
||||||
subject.update
|
subject.update
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should run git update in shallow mode" do
|
it "should run git update in shallow mode" do
|
||||||
context.expects(:fetch).with(:git_shallow_clone).returns('1')
|
context.expects(:fetch).with(:git_shallow_clone).returns("1")
|
||||||
context.expects(:fetch).with(:branch).returns(:branch)
|
context.expects(:fetch).with(:branch).returns(:branch)
|
||||||
context.expects(:execute).with(:git, :fetch, "--depth", '1', "origin", :branch)
|
context.expects(:execute).with(:git, :fetch, "--depth", "1", "origin", :branch)
|
||||||
|
|
||||||
subject.update
|
subject.update
|
||||||
end
|
end
|
||||||
|
@ -81,17 +81,17 @@ module Capistrano
|
||||||
context.expects(:fetch).with(:branch).returns(:branch)
|
context.expects(:fetch).with(:branch).returns(:branch)
|
||||||
context.expects(:release_path).returns(:path)
|
context.expects(:release_path).returns(:path)
|
||||||
|
|
||||||
context.expects(:execute).with(:git, :archive, :branch, '| tar -x -f - -C', :path)
|
context.expects(:execute).with(:git, :archive, :branch, "| tar -x -f - -C", :path)
|
||||||
|
|
||||||
subject.release
|
subject.release
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should run git archive with a subtree" do
|
it "should run git archive with a subtree" do
|
||||||
context.expects(:fetch).with(:repo_tree).returns('tree')
|
context.expects(:fetch).with(:repo_tree).returns("tree")
|
||||||
context.expects(:fetch).with(:branch).returns(:branch)
|
context.expects(:fetch).with(:branch).returns(:branch)
|
||||||
context.expects(:release_path).returns(:path)
|
context.expects(:release_path).returns(:path)
|
||||||
|
|
||||||
context.expects(:execute).with(:git, :archive, :branch, 'tree', '| tar -x --strip-components 1 -f - -C', :path)
|
context.expects(:execute).with(:git, :archive, :branch, "tree", "| tar -x --strip-components 1 -f - -C", :path)
|
||||||
|
|
||||||
subject.release
|
subject.release
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
require 'spec_helper'
|
require "spec_helper"
|
||||||
|
|
||||||
require 'capistrano/hg'
|
require "capistrano/hg"
|
||||||
|
|
||||||
module Capistrano
|
module Capistrano
|
||||||
describe Hg do
|
describe Hg do
|
||||||
|
@ -42,7 +42,7 @@ module Capistrano
|
||||||
context.expects(:repo_url).returns(:url)
|
context.expects(:repo_url).returns(:url)
|
||||||
context.expects(:repo_path).returns(:path)
|
context.expects(:repo_path).returns(:path)
|
||||||
|
|
||||||
context.expects(:execute).with(:hg, "clone", '--noupdate', :url, :path)
|
context.expects(:execute).with(:hg, "clone", "--noupdate", :url, :path)
|
||||||
|
|
||||||
subject.clone
|
subject.clone
|
||||||
end
|
end
|
||||||
|
@ -68,11 +68,11 @@ module Capistrano
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should run hg archive with a subtree" do
|
it "should run hg archive with a subtree" do
|
||||||
context.expects(:fetch).with(:repo_tree).returns('tree')
|
context.expects(:fetch).with(:repo_tree).returns("tree")
|
||||||
context.expects(:fetch).with(:branch).returns(:branch)
|
context.expects(:fetch).with(:branch).returns(:branch)
|
||||||
context.expects(:release_path).returns(:path)
|
context.expects(:release_path).returns(:path)
|
||||||
|
|
||||||
context.expects(:execute).with(:hg, "archive --type tgz -p . -I", 'tree', "--rev", :branch, '| tar -x --strip-components 1 -f - -C', :path)
|
context.expects(:execute).with(:hg, "archive --type tgz -p . -I", "tree", "--rev", :branch, "| tar -x --strip-components 1 -f - -C", :path)
|
||||||
|
|
||||||
subject.release
|
subject.release
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
require 'spec_helper'
|
require "spec_helper"
|
||||||
require 'rake'
|
require "rake"
|
||||||
require 'capistrano/immutable_task'
|
require "capistrano/immutable_task"
|
||||||
|
|
||||||
module Capistrano
|
module Capistrano
|
||||||
describe ImmutableTask do
|
describe ImmutableTask do
|
||||||
|
@ -9,10 +9,10 @@ module Capistrano
|
||||||
Rake::Task.clear
|
Rake::Task.clear
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'prints warning and raises when task is enhanced' do
|
it "prints warning and raises when task is enhanced" do
|
||||||
extend(Rake::DSL)
|
extend(Rake::DSL)
|
||||||
|
|
||||||
load_defaults = Rake::Task.define_task('load:defaults')
|
load_defaults = Rake::Task.define_task("load:defaults")
|
||||||
load_defaults.extend(Capistrano::ImmutableTask)
|
load_defaults.extend(Capistrano::ImmutableTask)
|
||||||
|
|
||||||
$stderr.expects(:puts).with do |message|
|
$stderr.expects(:puts).with do |message|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
require 'spec_helper'
|
require "spec_helper"
|
||||||
|
|
||||||
require 'capistrano/scm'
|
require "capistrano/scm"
|
||||||
|
|
||||||
module RaiseNotImplementedMacro
|
module RaiseNotImplementedMacro
|
||||||
def raise_not_implemented_on(method)
|
def raise_not_implemented_on(method)
|
||||||
|
@ -63,8 +63,8 @@ module Capistrano
|
||||||
|
|
||||||
describe "#release_path" do
|
describe "#release_path" do
|
||||||
it "should return the release path according to the context" do
|
it "should return the release path according to the context" do
|
||||||
context.expects(:release_path).returns('/path/to/nowhere')
|
context.expects(:release_path).returns("/path/to/nowhere")
|
||||||
expect(subject.release_path).to eq('/path/to/nowhere')
|
expect(subject.release_path).to eq("/path/to/nowhere")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
require 'spec_helper'
|
require "spec_helper"
|
||||||
|
|
||||||
require 'capistrano/svn'
|
require "capistrano/svn"
|
||||||
|
|
||||||
module Capistrano
|
module Capistrano
|
||||||
describe Svn do
|
describe Svn do
|
||||||
|
@ -9,9 +9,9 @@ module Capistrano
|
||||||
|
|
||||||
describe "#svn" do
|
describe "#svn" do
|
||||||
it "should call execute svn in the context, with arguments" do
|
it "should call execute svn in the context, with arguments" do
|
||||||
context.expects(:execute).with(:svn, :init, '--username someuser', '--password somepassword')
|
context.expects(:execute).with(:svn, :init, "--username someuser", "--password somepassword")
|
||||||
context.expects(:fetch).twice.with(:svn_username).returns('someuser')
|
context.expects(:fetch).twice.with(:svn_username).returns("someuser")
|
||||||
context.expects(:fetch).twice.with(:svn_password).returns('somepassword')
|
context.expects(:fetch).twice.with(:svn_password).returns("somepassword")
|
||||||
context.expects(:fetch).once.with(:svn_revision).returns(nil)
|
context.expects(:fetch).once.with(:svn_revision).returns(nil)
|
||||||
subject.svn(:init)
|
subject.svn(:init)
|
||||||
end
|
end
|
||||||
|
@ -34,9 +34,9 @@ module Capistrano
|
||||||
describe "#check" do
|
describe "#check" do
|
||||||
it "should test the repo url" do
|
it "should test the repo url" do
|
||||||
context.expects(:repo_url).returns(:url)
|
context.expects(:repo_url).returns(:url)
|
||||||
context.expects(:test).with(:svn, :info, :url, '--username someuser', '--password somepassword').returns(true)
|
context.expects(:test).with(:svn, :info, :url, "--username someuser", "--password somepassword").returns(true)
|
||||||
context.expects(:fetch).twice.with(:svn_username).returns('someuser')
|
context.expects(:fetch).twice.with(:svn_username).returns("someuser")
|
||||||
context.expects(:fetch).twice.with(:svn_password).returns('somepassword')
|
context.expects(:fetch).twice.with(:svn_password).returns("somepassword")
|
||||||
|
|
||||||
subject.check
|
subject.check
|
||||||
end
|
end
|
||||||
|
@ -46,11 +46,11 @@ module Capistrano
|
||||||
it "should run svn checkout" do
|
it "should run svn checkout" do
|
||||||
context.expects(:repo_url).returns(:url)
|
context.expects(:repo_url).returns(:url)
|
||||||
context.expects(:repo_path).returns(:path)
|
context.expects(:repo_path).returns(:path)
|
||||||
context.expects(:fetch).twice.with(:svn_username).returns('someuser')
|
context.expects(:fetch).twice.with(:svn_username).returns("someuser")
|
||||||
context.expects(:fetch).twice.with(:svn_password).returns('somepassword')
|
context.expects(:fetch).twice.with(:svn_password).returns("somepassword")
|
||||||
context.expects(:fetch).once.with(:svn_revision).returns(nil)
|
context.expects(:fetch).once.with(:svn_revision).returns(nil)
|
||||||
|
|
||||||
context.expects(:execute).with(:svn, :checkout, :url, :path, '--username someuser', '--password somepassword')
|
context.expects(:execute).with(:svn, :checkout, :url, :path, "--username someuser", "--password somepassword")
|
||||||
|
|
||||||
subject.clone
|
subject.clone
|
||||||
end
|
end
|
||||||
|
@ -58,9 +58,9 @@ module Capistrano
|
||||||
|
|
||||||
describe "#update" do
|
describe "#update" do
|
||||||
it "should run svn update" do
|
it "should run svn update" do
|
||||||
context.expects(:execute).with(:svn, :update, '--username someuser', '--password somepassword')
|
context.expects(:execute).with(:svn, :update, "--username someuser", "--password somepassword")
|
||||||
context.expects(:fetch).twice.with(:svn_username).returns('someuser')
|
context.expects(:fetch).twice.with(:svn_username).returns("someuser")
|
||||||
context.expects(:fetch).twice.with(:svn_password).returns('somepassword')
|
context.expects(:fetch).twice.with(:svn_password).returns("somepassword")
|
||||||
context.expects(:fetch).once.with(:svn_revision).returns(nil)
|
context.expects(:fetch).once.with(:svn_revision).returns(nil)
|
||||||
|
|
||||||
subject.update
|
subject.update
|
||||||
|
@ -69,10 +69,10 @@ module Capistrano
|
||||||
|
|
||||||
describe "#update_specific_revision" do
|
describe "#update_specific_revision" do
|
||||||
it "should run svn update and update to a specific revision" do
|
it "should run svn update and update to a specific revision" do
|
||||||
context.expects(:execute).with(:svn, :update, '--username someuser', '--password somepassword', '--revision 12345')
|
context.expects(:execute).with(:svn, :update, "--username someuser", "--password somepassword", "--revision 12345")
|
||||||
context.expects(:fetch).twice.with(:svn_username).returns('someuser')
|
context.expects(:fetch).twice.with(:svn_username).returns("someuser")
|
||||||
context.expects(:fetch).twice.with(:svn_password).returns('somepassword')
|
context.expects(:fetch).twice.with(:svn_password).returns("somepassword")
|
||||||
context.expects(:fetch).twice.with(:svn_revision).returns('12345')
|
context.expects(:fetch).twice.with(:svn_revision).returns("12345")
|
||||||
|
|
||||||
subject.update
|
subject.update
|
||||||
end
|
end
|
||||||
|
@ -81,11 +81,11 @@ module Capistrano
|
||||||
describe "#release" do
|
describe "#release" do
|
||||||
it "should run svn export" do
|
it "should run svn export" do
|
||||||
context.expects(:release_path).returns(:path)
|
context.expects(:release_path).returns(:path)
|
||||||
context.expects(:fetch).twice.with(:svn_username).returns('someuser')
|
context.expects(:fetch).twice.with(:svn_username).returns("someuser")
|
||||||
context.expects(:fetch).twice.with(:svn_password).returns('somepassword')
|
context.expects(:fetch).twice.with(:svn_password).returns("somepassword")
|
||||||
context.expects(:fetch).once.with(:svn_revision).returns(nil)
|
context.expects(:fetch).once.with(:svn_revision).returns(nil)
|
||||||
|
|
||||||
context.expects(:execute).with(:svn, :export, '--force', '.', :path, '--username someuser', '--password somepassword')
|
context.expects(:execute).with(:svn, :export, "--force", ".", :path, "--username someuser", "--password somepassword")
|
||||||
|
|
||||||
subject.release
|
subject.release
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,19 +1,19 @@
|
||||||
require 'spec_helper'
|
require "spec_helper"
|
||||||
|
|
||||||
describe Capistrano::UploadTask do
|
describe Capistrano::UploadTask do
|
||||||
let(:app) { Rake.application = Rake::Application.new }
|
let(:app) { Rake.application = Rake::Application.new }
|
||||||
|
|
||||||
subject(:upload_task) { described_class.define_task('path/file.yml') }
|
subject(:upload_task) { described_class.define_task("path/file.yml") }
|
||||||
|
|
||||||
it { is_expected.to be_a(Rake::FileCreationTask) }
|
it { is_expected.to be_a(Rake::FileCreationTask) }
|
||||||
it { is_expected.to be_needed }
|
it { is_expected.to be_needed }
|
||||||
|
|
||||||
context 'inside namespace' do
|
context "inside namespace" do
|
||||||
let(:normal_task) { Rake::Task.define_task('path/other_file.yml') }
|
let(:normal_task) { Rake::Task.define_task("path/other_file.yml") }
|
||||||
|
|
||||||
around { |ex| app.in_namespace('namespace', &ex) }
|
around { |ex| app.in_namespace("namespace", &ex) }
|
||||||
|
|
||||||
it { expect(upload_task.name).to eq('path/file.yml') }
|
it { expect(upload_task.name).to eq("path/file.yml") }
|
||||||
it { expect(upload_task.scope.path).to eq('namespace') }
|
it { expect(upload_task.scope.path).to eq("namespace") }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
require 'spec_helper'
|
require "spec_helper"
|
||||||
|
|
||||||
module Capistrano
|
module Capistrano
|
||||||
|
|
||||||
|
@ -7,13 +7,13 @@ module Capistrano
|
||||||
let(:version) { stub }
|
let(:version) { stub }
|
||||||
|
|
||||||
describe '#new' do
|
describe '#new' do
|
||||||
it 'takes a version' do
|
it "takes a version" do
|
||||||
expect(validator)
|
expect(validator)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#verify' do
|
describe '#verify' do
|
||||||
let(:current_version) { '3.0.1' }
|
let(:current_version) { "3.0.1" }
|
||||||
|
|
||||||
subject { validator.verify }
|
subject { validator.verify }
|
||||||
|
|
||||||
|
@ -21,40 +21,40 @@ module Capistrano
|
||||||
validator.stubs(:current_version).returns(current_version)
|
validator.stubs(:current_version).returns(current_version)
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with exact version' do
|
context "with exact version" do
|
||||||
context 'valid' do
|
context "valid" do
|
||||||
let(:version) { '3.0.1' }
|
let(:version) { "3.0.1" }
|
||||||
it { expect(subject).to be_truthy }
|
it { expect(subject).to be_truthy }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'invalid - lower' do
|
context "invalid - lower" do
|
||||||
let(:version) { '3.0.0' }
|
let(:version) { "3.0.0" }
|
||||||
|
|
||||||
it 'fails' do
|
it "fails" do
|
||||||
expect { subject }.to raise_error(RuntimeError)
|
expect { subject }.to raise_error(RuntimeError)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'invalid - higher' do
|
context "invalid - higher" do
|
||||||
let(:version) { '3.0.2' }
|
let(:version) { "3.0.2" }
|
||||||
|
|
||||||
it 'fails' do
|
it "fails" do
|
||||||
expect { subject }.to raise_error(RuntimeError)
|
expect { subject }.to raise_error(RuntimeError)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with optimistic versioning' do
|
context "with optimistic versioning" do
|
||||||
context 'valid' do
|
context "valid" do
|
||||||
let(:version) { '>= 3.0.0' }
|
let(:version) { ">= 3.0.0" }
|
||||||
it { expect(subject).to be_truthy }
|
it { expect(subject).to be_truthy }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'invalid - lower' do
|
context "invalid - lower" do
|
||||||
let(:version) { '<= 2.0.0' }
|
let(:version) { "<= 2.0.0" }
|
||||||
|
|
||||||
it 'fails' do
|
it "fails" do
|
||||||
expect { subject }.to raise_error(RuntimeError)
|
expect { subject }.to raise_error(RuntimeError)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -62,33 +62,33 @@ module Capistrano
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
context 'with pessimistic versioning' do
|
context "with pessimistic versioning" do
|
||||||
context '2 decimal places' do
|
context "2 decimal places" do
|
||||||
context 'valid' do
|
context "valid" do
|
||||||
let(:version) { '~> 3.0.0' }
|
let(:version) { "~> 3.0.0" }
|
||||||
it { expect(subject).to be_truthy }
|
it { expect(subject).to be_truthy }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'invalid' do
|
context "invalid" do
|
||||||
let(:version) { '~> 3.1.0' }
|
let(:version) { "~> 3.1.0" }
|
||||||
|
|
||||||
it 'fails' do
|
it "fails" do
|
||||||
expect { subject }.to raise_error(RuntimeError)
|
expect { subject }.to raise_error(RuntimeError)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context '1 decimal place' do
|
context "1 decimal place" do
|
||||||
let(:current_version) { '3.5.0' }
|
let(:current_version) { "3.5.0" }
|
||||||
|
|
||||||
context 'valid' do
|
context "valid" do
|
||||||
let(:version) { '~> 3.1' }
|
let(:version) { "~> 3.1" }
|
||||||
it { expect(subject).to be_truthy }
|
it { expect(subject).to be_truthy }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'invalid' do
|
context "invalid" do
|
||||||
let(:version) { '~> 3.6' }
|
let(:version) { "~> 3.6" }
|
||||||
it 'fails' do
|
it "fails" do
|
||||||
expect { subject }.to raise_error(RuntimeError)
|
expect { subject }.to raise_error(RuntimeError)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
require 'spec_helper'
|
require "spec_helper"
|
||||||
|
|
||||||
module Capistrano
|
module Capistrano
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
|
||||||
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
||||||
require 'capistrano/all'
|
require "capistrano/all"
|
||||||
require 'rspec'
|
require "rspec"
|
||||||
require 'mocha/api'
|
require "mocha/api"
|
||||||
require 'time'
|
require "time"
|
||||||
|
|
||||||
# Requires supporting files with custom matchers and macros, etc,
|
# Requires supporting files with custom matchers and macros, etc,
|
||||||
# in ./support/ and its subdirectories.
|
# in ./support/ and its subdirectories.
|
||||||
|
@ -12,5 +12,5 @@ Dir['#{File.dirname(__FILE__)}/support/**/*.rb'].each {|f| require f}
|
||||||
RSpec.configure do |config|
|
RSpec.configure do |config|
|
||||||
config.raise_errors_for_deprecations!
|
config.raise_errors_for_deprecations!
|
||||||
config.mock_framework = :mocha
|
config.mock_framework = :mocha
|
||||||
config.order = 'random'
|
config.order = "random"
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
require 'open-uri'
|
require "open-uri"
|
||||||
|
|
||||||
Vagrant.configure("2") do |config|
|
Vagrant.configure("2") do |config|
|
||||||
|
|
||||||
|
@ -7,9 +7,9 @@ Vagrant.configure("2") do |config|
|
||||||
[:app].each_with_index do |role, i|
|
[:app].each_with_index do |role, i|
|
||||||
config.vm.define(role, :primary => true) do |primary|
|
config.vm.define(role, :primary => true) do |primary|
|
||||||
primary.vm.define role
|
primary.vm.define role
|
||||||
primary.vm.box = 'hashicorp/precise64'
|
primary.vm.box = "hashicorp/precise64"
|
||||||
primary.vm.network "forwarded_port", :guest => 22, :host => "222#{i}".to_i
|
primary.vm.network "forwarded_port", :guest => 22, :host => "222#{i}".to_i
|
||||||
primary.vm.provision :shell, :inline => 'sudo apt-get -y install git-core'
|
primary.vm.provision :shell, :inline => "sudo apt-get -y install git-core"
|
||||||
|
|
||||||
vagrantkey = open("https://raw.githubusercontent.com/mitchellh/vagrant/master/keys/vagrant.pub", "r",&:read)
|
vagrantkey = open("https://raw.githubusercontent.com/mitchellh/vagrant/master/keys/vagrant.pub", "r",&:read)
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
namespace :deploy do
|
namespace :deploy do
|
||||||
namespace :check do
|
namespace :check do
|
||||||
task :linked_files => 'config/database.yml'
|
task :linked_files => "config/database.yml"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
remote_file 'config/database.yml' => '/tmp/database.yml', :roles => :all
|
remote_file "config/database.yml" => "/tmp/database.yml", :roles => :all
|
||||||
|
|
||||||
file '/tmp/database.yml' do |t|
|
file "/tmp/database.yml" do |t|
|
||||||
sh "touch #{t.name}"
|
sh "touch #{t.name}"
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
set :fail, proc { fail }
|
set :fail, proc { fail }
|
||||||
before 'deploy:starting', :fail do
|
before "deploy:starting", :fail do
|
||||||
on roles :all do
|
on roles :all do
|
||||||
execute :mkdir, '-p', shared_path
|
execute :mkdir, "-p", shared_path
|
||||||
execute :touch, shared_path.join('fail')
|
execute :touch, shared_path.join("fail")
|
||||||
end
|
end
|
||||||
fetch(:fail)
|
fetch(:fail)
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
after 'deploy:failed', :custom_failed do
|
after "deploy:failed", :custom_failed do
|
||||||
on roles :all do
|
on roles :all do
|
||||||
execute :touch, shared_path.join('failed')
|
execute :touch, shared_path.join("failed")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
task :am_i_root do
|
task :am_i_root do
|
||||||
on roles(:all) do |host|
|
on roles(:all) do |host|
|
||||||
host.user = 'root'
|
host.user = "root"
|
||||||
ident = capture :id, '-a'
|
ident = capture :id, "-a"
|
||||||
info "I am #{ident}"
|
info "I am #{ident}"
|
||||||
end
|
end
|
||||||
on roles(:all) do |_host|
|
on roles(:all) do |_host|
|
||||||
ident = capture :id, '-a'
|
ident = capture :id, "-a"
|
||||||
info "I am #{ident}"
|
info "I am #{ident}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
require 'fileutils'
|
require "fileutils"
|
||||||
require 'pathname'
|
require "pathname"
|
||||||
|
|
||||||
module TestApp
|
module TestApp
|
||||||
extend self
|
extend self
|
||||||
|
@ -37,7 +37,7 @@ module TestApp
|
||||||
FileUtils.rm_rf(test_app_path)
|
FileUtils.rm_rf(test_app_path)
|
||||||
FileUtils.mkdir(test_app_path)
|
FileUtils.mkdir(test_app_path)
|
||||||
|
|
||||||
File.open(gemfile, 'w+') do |file|
|
File.open(gemfile, "w+") do |file|
|
||||||
file.write "gem 'capistrano', path: '#{path_to_cap}'"
|
file.write "gem 'capistrano', path: '#{path_to_cap}'"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -55,20 +55,20 @@ module TestApp
|
||||||
end
|
end
|
||||||
|
|
||||||
def write_local_deploy_file(config)
|
def write_local_deploy_file(config)
|
||||||
File.open(test_stage_path, 'w') do |file|
|
File.open(test_stage_path, "w") do |file|
|
||||||
file.write config
|
file.write config
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def append_to_deploy_file(config)
|
def append_to_deploy_file(config)
|
||||||
File.open(test_stage_path, 'a') do |file|
|
File.open(test_stage_path, "a") do |file|
|
||||||
file.write config + "\n"
|
file.write config + "\n"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def prepend_to_capfile(config)
|
def prepend_to_capfile(config)
|
||||||
current_capfile = File.read(capfile)
|
current_capfile = File.read(capfile)
|
||||||
File.open(capfile, 'w') do |file|
|
File.open(capfile, "w") do |file|
|
||||||
file.write config
|
file.write config
|
||||||
file.write current_capfile
|
file.write current_capfile
|
||||||
end
|
end
|
||||||
|
@ -79,7 +79,7 @@ module TestApp
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_shared_file(path)
|
def create_shared_file(path)
|
||||||
File.open(shared_path.join(path), 'w')
|
File.open(shared_path.join(path), "w")
|
||||||
end
|
end
|
||||||
|
|
||||||
def cap(task)
|
def cap(task)
|
||||||
|
@ -95,31 +95,31 @@ module TestApp
|
||||||
end
|
end
|
||||||
|
|
||||||
def stage
|
def stage
|
||||||
'test'
|
"test"
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_stage_path
|
def test_stage_path
|
||||||
test_app_path.join('config/deploy/test.rb')
|
test_app_path.join("config/deploy/test.rb")
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_app_path
|
def test_app_path
|
||||||
Pathname.new('/tmp/test_app')
|
Pathname.new("/tmp/test_app")
|
||||||
end
|
end
|
||||||
|
|
||||||
def deploy_to
|
def deploy_to
|
||||||
Pathname.new('/home/vagrant/var/www/deploy')
|
Pathname.new("/home/vagrant/var/www/deploy")
|
||||||
end
|
end
|
||||||
|
|
||||||
def shared_path
|
def shared_path
|
||||||
deploy_to.join('shared')
|
deploy_to.join("shared")
|
||||||
end
|
end
|
||||||
|
|
||||||
def current_path
|
def current_path
|
||||||
deploy_to.join('current')
|
deploy_to.join("current")
|
||||||
end
|
end
|
||||||
|
|
||||||
def releases_path
|
def releases_path
|
||||||
deploy_to.join('releases')
|
deploy_to.join("releases")
|
||||||
end
|
end
|
||||||
|
|
||||||
def release_path
|
def release_path
|
||||||
|
@ -131,19 +131,19 @@ module TestApp
|
||||||
end
|
end
|
||||||
|
|
||||||
def repo_path
|
def repo_path
|
||||||
deploy_to.join('repo')
|
deploy_to.join("repo")
|
||||||
end
|
end
|
||||||
|
|
||||||
def path_to_cap
|
def path_to_cap
|
||||||
File.expand_path('.')
|
File.expand_path(".")
|
||||||
end
|
end
|
||||||
|
|
||||||
def gemfile
|
def gemfile
|
||||||
test_app_path.join('Gemfile')
|
test_app_path.join("Gemfile")
|
||||||
end
|
end
|
||||||
|
|
||||||
def capfile
|
def capfile
|
||||||
test_app_path.join('Capfile')
|
test_app_path.join("Capfile")
|
||||||
end
|
end
|
||||||
|
|
||||||
def current_user
|
def current_user
|
||||||
|
@ -151,7 +151,7 @@ module TestApp
|
||||||
end
|
end
|
||||||
|
|
||||||
def task_dir
|
def task_dir
|
||||||
test_app_path.join('lib/capistrano/tasks')
|
test_app_path.join("lib/capistrano/tasks")
|
||||||
end
|
end
|
||||||
|
|
||||||
def copy_task_to_test_app(source)
|
def copy_task_to_test_app(source)
|
||||||
|
@ -159,7 +159,7 @@ module TestApp
|
||||||
end
|
end
|
||||||
|
|
||||||
def config_path
|
def config_path
|
||||||
test_app_path.join('config')
|
test_app_path.join("config")
|
||||||
end
|
end
|
||||||
|
|
||||||
def move_configuration_to_custom_location(location)
|
def move_configuration_to_custom_location(location)
|
||||||
|
|
Loading…
Reference in New Issue