2013-06-16 08:08:15 -04:00
|
|
|
require 'fileutils'
|
2013-06-14 12:09:32 -04:00
|
|
|
module TestApp
|
|
|
|
def create_test_app
|
2013-06-16 08:08:15 -04:00
|
|
|
[test_app_path, deploy_to].each do |path|
|
|
|
|
FileUtils.rm_rf(path)
|
|
|
|
FileUtils.mkdir(path)
|
|
|
|
end
|
2013-06-14 12:09:32 -04:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2013-06-16 08:08:15 -04:00
|
|
|
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
|
2013-06-14 12:09:32 -04:00
|
|
|
|
|
|
|
def test_app_path
|
|
|
|
Pathname.new('/tmp/test_app')
|
|
|
|
end
|
|
|
|
|
2013-06-16 08:08:15 -04:00
|
|
|
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
|
|
|
|
|
2013-06-14 12:09:32 -04:00
|
|
|
def path_to_cap
|
|
|
|
File.expand_path('.')
|
|
|
|
end
|
|
|
|
|
|
|
|
def gemfile
|
|
|
|
test_app_path.join('Gemfile')
|
|
|
|
end
|
2013-06-16 08:08:15 -04:00
|
|
|
|
|
|
|
def current_user
|
|
|
|
`whoami`.chomp
|
|
|
|
end
|
2013-06-14 12:09:32 -04:00
|
|
|
end
|