1
0
Fork 0
mirror of https://github.com/capistrano/capistrano synced 2023-03-27 23:21:18 -04:00
capistrano/spec/support/test_app.rb
seenmyfate f5a585b3a4 Add integration tests for deploy task
This commit adds the outlines of a testing framework for Cap tasks.
Currently just the `cap install` and `cap deploy` tasks are covered. For
now, these tests can only be run if it is `ssh localhost` will work for
you and are currently excluded from the suite. It is my intention to
eventually replace the `sshkit` backend with a test backend, but for now
this is good enough to prevent simple regressions.
2013-06-16 13:08:15 +01:00

89 lines
1.5 KiB
Ruby

require 'fileutils'
module TestApp
def create_test_app
[test_app_path, deploy_to].each do |path|
FileUtils.rm_rf(path)
FileUtils.mkdir(path)
end
File.open(gemfile, 'w+') do |file|
file.write "gem 'capistrano', path: '#{path_to_cap}'"
end
Dir.chdir(test_app_path) do
%x[bundle]
end
end
def install_test_app_with(config)
create_test_app
Dir.chdir(test_app_path) do
%x[bundle exec cap install STAGES=#{stage}]
end
write_local_deploy_file(config)
end
def write_local_deploy_file(config)
File.open(test_stage_path, 'w') do |file|
file.write config
end
end
def create_shared_directory(path)
FileUtils.mkdir_p(shared_path.join(path))
end
def create_shared_file(path)
File.open(shared_path.join(path), 'w')
end
def cap(task)
Dir.chdir(test_app_path) do
%x[bundle exec cap #{stage} #{task}]
end
end
def stage
'test'
end
def test_stage_path
test_app_path.join('config/deploy/test.rb')
end
def test_app_path
Pathname.new('/tmp/test_app')
end
def deploy_to
Pathname.new('/tmp/test_app/deploy_to')
end
def shared_path
deploy_to.join('shared')
end
def current_path
deploy_to.join('current')
end
def releases_path
deploy_to.join('releases')
end
def release_path
releases_path.join(Dir.entries(releases_path).last)
end
def path_to_cap
File.expand_path('.')
end
def gemfile
test_app_path.join('Gemfile')
end
def current_user
`whoami`.chomp
end
end