capistrano-deploy 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --backtrace
2
+ --color
data/Gemfile CHANGED
@@ -2,3 +2,6 @@ source "http://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in capistrano-deploy.gemspec
4
4
  gemspec
5
+
6
+ gem 'rake'
7
+ gem 'rspec'
@@ -1,19 +1,20 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- capistrano-deploy (0.2.1)
5
- capistrano (~> 2.8.0)
4
+ capistrano-deploy (0.2.2)
5
+ capistrano (~> 2.9.0)
6
6
 
7
7
  GEM
8
8
  remote: http://rubygems.org/
9
9
  specs:
10
- capistrano (2.8.0)
10
+ capistrano (2.9.0)
11
11
  highline
12
12
  net-scp (>= 1.0.0)
13
13
  net-sftp (>= 2.0.0)
14
14
  net-ssh (>= 2.0.14)
15
15
  net-ssh-gateway (>= 1.1.0)
16
- highline (1.6.2)
16
+ diff-lcs (1.1.3)
17
+ highline (1.6.5)
17
18
  net-scp (1.0.4)
18
19
  net-ssh (>= 1.99.1)
19
20
  net-sftp (2.0.5)
@@ -21,7 +22,15 @@ GEM
21
22
  net-ssh (2.2.1)
22
23
  net-ssh-gateway (1.1.0)
23
24
  net-ssh (>= 1.99.1)
24
- rake (0.8.7)
25
+ rake (0.9.2.2)
26
+ rspec (2.6.0)
27
+ rspec-core (~> 2.6.0)
28
+ rspec-expectations (~> 2.6.0)
29
+ rspec-mocks (~> 2.6.0)
30
+ rspec-core (2.6.4)
31
+ rspec-expectations (2.6.0)
32
+ diff-lcs (~> 1.1.2)
33
+ rspec-mocks (2.6.0)
25
34
 
26
35
  PLATFORMS
27
36
  ruby
@@ -29,3 +38,4 @@ PLATFORMS
29
38
  DEPENDENCIES
30
39
  capistrano-deploy!
31
40
  rake
41
+ rspec
data/Rakefile CHANGED
@@ -1,2 +1,9 @@
1
1
  require 'bundler'
2
2
  Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core/rake_task'
5
+
6
+ desc 'Run all specs in spec directory'
7
+ RSpec::Core::RakeTask.new
8
+
9
+ task :default => :spec
@@ -1,9 +1,9 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  Gem::Specification.new do |s|
3
3
  s.name = 'capistrano-deploy'
4
- s.version = '0.2.1'
4
+ s.version = '0.2.2'
5
5
  s.platform = Gem::Platform::RUBY
6
- s.authors = ['Just Lest']
6
+ s.authors = ['Sergey Nartimov']
7
7
  s.email = ['just.lest@gmail.com']
8
8
  s.homepage = 'https://github.com/lest/capistrano-deploy'
9
9
  s.summary = 'Capistrano deploy recipes'
@@ -12,6 +12,5 @@ Gem::Specification.new do |s|
12
12
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
13
13
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
14
14
 
15
- s.add_dependency('capistrano', '~> 2.8.0')
16
- s.add_development_dependency('rake')
15
+ s.add_dependency('capistrano', '~> 2.9.0')
17
16
  end
@@ -1,27 +1,49 @@
1
- Capistrano::Configuration.instance(:must_exist).load do
2
- def use_recipe(recipe)
3
- require "capistrano-deploy/#{recipe}"
4
- end
1
+ module CapistranoDeploy
2
+ def self.load_into(configuration)
3
+ configuration.load do
4
+ @used_recipes = []
5
5
 
6
- def use_recipes(*recipes)
7
- recipes.each do |recipe|
8
- use_recipe(recipe)
9
- end
10
- end
6
+ (class << self; self; end).class_eval do
7
+ attr_reader :used_recipes
11
8
 
12
- namespace :deploy do
13
- desc 'Run deploy'
14
- task :default do
15
- update
16
- restart
17
- end
9
+ define_method :use_recipe do |recipe_name|
10
+ @used_recipes << recipe_name.to_sym
18
11
 
19
- task :update do
20
- # nothing
21
- end
12
+ require "capistrano-deploy/#{recipe_name}"
13
+ recipe = CapistranoDeploy.const_get(recipe_name.to_s.capitalize.gsub(/_(\w)/) { $1.upcase })
14
+ recipe.load_into(configuration)
15
+ end
16
+ end
17
+
18
+ def use_recipes(*recipes)
19
+ recipes.each do |recipe|
20
+ use_recipe(recipe)
21
+ end
22
+ end
22
23
 
23
- task :restart do
24
- # nothing
24
+ def using_recipe?(recipe)
25
+ used_recipes.include?(recipe.to_sym)
26
+ end
27
+
28
+ namespace :deploy do
29
+ desc 'Run deploy'
30
+ task :default do
31
+ update
32
+ restart
33
+ end
34
+
35
+ task :update do
36
+ # nothing
37
+ end
38
+
39
+ task :restart do
40
+ # nothing
41
+ end
42
+ end
25
43
  end
26
44
  end
27
45
  end
46
+
47
+ if Capistrano::Configuration.instance
48
+ CapistranoDeploy.load_into(Capistrano::Configuration.instance)
49
+ end
@@ -1,19 +1,21 @@
1
- Capistrano::Configuration.instance(:must_exist).load do
2
- set(:rake) { 'bundle exec rake' }
1
+ module CapistranoDeploy
2
+ module Bundle
3
+ def self.load_into(configuration)
4
+ configuration.load do
5
+ namespace :bundle do
6
+ desc 'Install gems'
7
+ task :install, :except => {:no_release => true} do
8
+ bundle_cmd = fetch(:bundle_cmd, 'bundle')
9
+ bundle_flags = fetch(:bundle_flags, '--deployment --quiet')
10
+ bundle_without = [*fetch(:bundle_without, [:development, :test])].compact
3
11
 
4
- set(:whenever_cmd) { 'bundle exec whenever' }
12
+ args = [bundle_flags.to_s]
13
+ args << "--without #{bundle_without.join(' ')}" unless bundle_without.empty?
5
14
 
6
- namespace :bundle do
7
- desc 'Install gems'
8
- task :install, :except => {:no_release => true} do
9
- bundle_cmd = fetch(:bundle_cmd, 'bundle')
10
- bundle_flags = fetch(:bundle_flags, '--deployment --quiet')
11
- bundle_without = [*fetch(:bundle_without, [:development, :test])].compact
12
-
13
- args = [bundle_flags.to_s]
14
- args << "--without #{bundle_without.join(' ')}" unless bundle_without.empty?
15
-
16
- run "cd #{deploy_to} && #{bundle_cmd} install #{args.join(' ')}"
15
+ run "cd #{deploy_to} && #{bundle_cmd} install #{args.join(' ')}"
16
+ end
17
+ end
18
+ end
17
19
  end
18
20
  end
19
21
  end
@@ -1,30 +1,36 @@
1
- Capistrano::Configuration.instance(:must_exist).load do
2
- ssh_options[:forward_agent] = true
1
+ module CapistranoDeploy
2
+ module Git
3
+ def self.load_into(configuration)
4
+ configuration.load do
5
+ ssh_options[:forward_agent] = true
3
6
 
4
- set(:application) { repository.slice(/[^\/:]+?(?=\.git$)/) }
5
- set(:repository) { abort "Please specify repository, set :repository, 'foo'" }
6
- set :branch, 'master'
7
- set :enable_submodules, false
7
+ set(:application) { repository.slice(/[^\/:]+?(?=\.git$)/) }
8
+ set(:repository) { abort "Please specify repository, set :repository, 'foo'" }
9
+ set :branch, 'master'
10
+ set :enable_submodules, false
8
11
 
9
- set(:current_revision) { capture("cd #{deploy_to} && git rev-parse HEAD").chomp }
12
+ set(:current_revision) { capture("cd #{deploy_to} && git rev-parse HEAD").chomp }
10
13
 
11
- namespace :deploy do
12
- desc 'Setup'
13
- task :setup, :except => {:no_release => true} do
14
- run "mkdir -p `dirname #{deploy_to}` && git clone --no-checkout #{repository} #{deploy_to}"
15
- update
16
- end
14
+ namespace :deploy do
15
+ desc 'Setup'
16
+ task :setup, :except => {:no_release => true} do
17
+ run "mkdir -p `dirname #{deploy_to}` && git clone --no-checkout #{repository} #{deploy_to}"
18
+ update
19
+ end
17
20
 
18
- desc 'Update the deployed code'
19
- task :update, :except => {:no_release => true} do
20
- command = ["cd #{deploy_to}", 'git fetch origin', "git reset --hard origin/#{branch}"]
21
- command += ['git submodule init', 'git submodule -q sync', 'git submodule -q update'] if enable_submodules
22
- run command.join(' && ')
23
- end
21
+ desc 'Update the deployed code'
22
+ task :update, :except => {:no_release => true} do
23
+ command = ["cd #{deploy_to}", 'git fetch origin', "git reset --hard origin/#{branch}"]
24
+ command += ['git submodule init', 'git submodule -q sync', 'git submodule -q update'] if enable_submodules
25
+ run command.join(' && ')
26
+ end
24
27
 
25
- desc 'Show pending commits'
26
- task :pending do
27
- system("git log --pretty=medium --stat #{current_revision}..origin/#{branch}")
28
+ desc 'Show pending commits'
29
+ task :pending do
30
+ system("git log --pretty=medium --stat #{current_revision}..origin/#{branch}")
31
+ end
32
+ end
33
+ end
28
34
  end
29
35
  end
30
36
  end
@@ -1,26 +1,32 @@
1
- Capistrano::Configuration.instance(:must_exist).load do
2
- set :multistage_stages, []
1
+ module CapistranoDeploy
2
+ module Multistage
3
+ def self.load_into(configuration)
4
+ configuration.load do
5
+ set :multistage_stages, []
3
6
 
4
- def define_stage(name, &block)
5
- multistage_stages << name
6
- callbacks[:start].detect { |c| c.source == 'multistage:ensure' }.except << name.to_s
7
- task(name) do
8
- set :stage, name
9
- block.call
10
- end
11
- end
7
+ def define_stage(name, &block)
8
+ multistage_stages << name
9
+ callbacks[:start].detect { |c| c.source == 'multistage:ensure' }.except << name.to_s
10
+ task(name) do
11
+ set :stage, name.to_s
12
+ block.call
13
+ end
14
+ end
12
15
 
13
- namespace :multistage do
14
- task :ensure do
15
- unless exists?(:stage)
16
- if exists?(:default_stage)
17
- find_and_execute_task(default_stage)
18
- else
19
- abort "No stage specified. Please specify one of: #{multistage_stages.join(', ')} (e.g. `cap #{multistage_stages.first} #{ARGV.last}')"
16
+ namespace :multistage do
17
+ task :ensure do
18
+ unless exists?(:stage)
19
+ if exists?(:default_stage)
20
+ find_and_execute_task(default_stage)
21
+ else
22
+ abort "No stage specified. Please specify one of: #{multistage_stages.join(', ')} (e.g. `cap #{multistage_stages.first} #{ARGV.last}')"
23
+ end
24
+ end
25
+ end
20
26
  end
27
+
28
+ on :start, 'multistage:ensure'
21
29
  end
22
30
  end
23
31
  end
24
-
25
- on :start, 'multistage:ensure'
26
32
  end
@@ -1,8 +1,16 @@
1
- Capistrano::Configuration.instance(:must_exist).load do
2
- namespace :deploy do
3
- desc 'Restart passenger'
4
- task :restart, :roles => :app, :except => {:no_release => true} do
5
- run "touch #{deploy_to}/tmp/restart.txt"
1
+ module CapistranoDeploy
2
+ module Passenger
3
+ def self.load_into(configuration)
4
+ configuration.load do
5
+ namespace :passenger do
6
+ desc 'Restart passenger'
7
+ task :restart, :roles => :app, :except => {:no_release => true} do
8
+ run "touch #{deploy_to}/tmp/restart.txt"
9
+ end
10
+ end
11
+
12
+ after 'deploy:restart', 'passenger:restart'
13
+ end
6
14
  end
7
15
  end
8
16
  end
@@ -1,17 +1,31 @@
1
- Capistrano::Configuration.instance(:must_exist).load do
2
- namespace :deploy do
3
- desc 'Deploy & migrate'
4
- task :migrations do
5
- update
6
- migrate
7
- restart
8
- end
1
+ module CapistranoDeploy
2
+ module Rails
3
+ def self.load_into(configuration)
4
+ configuration.load do
5
+ set :rake do
6
+ if using_recipe?(:bundle)
7
+ 'bundle exec rake'
8
+ else
9
+ 'rake'
10
+ end
11
+ end
12
+
13
+ set(:rails_env) { 'production' }
14
+
15
+ namespace :deploy do
16
+ desc 'Deploy & migrate'
17
+ task :migrations do
18
+ update
19
+ migrate
20
+ restart
21
+ end
9
22
 
10
- desc 'Run migrations'
11
- task :migrate, :roles => :db, :only => {:primary => true} do
12
- rake = fetch(:rake, 'rake')
13
- rails_env = fetch(:rails_env, 'production')
14
- run "cd #{deploy_to} && RAILS_ENV=#{rails_env} #{rake} db:migrate"
23
+ desc 'Run migrations'
24
+ task :migrate, :roles => :db, :only => {:primary => true} do
25
+ run "cd #{deploy_to} && RAILS_ENV=#{rails_env} #{rake} db:migrate"
26
+ end
27
+ end
28
+ end
15
29
  end
16
30
  end
17
31
  end
@@ -1,11 +1,17 @@
1
- Capistrano::Configuration.instance(:must_exist).load do
2
- $:.unshift(File.expand_path('./lib', ENV['rvm_path']))
3
- require 'rvm/capistrano'
1
+ module CapistranoDeploy
2
+ module Rvm
3
+ def self.load_into(configuration)
4
+ configuration.load do
5
+ $:.unshift(File.expand_path('./lib', ENV['rvm_path']))
6
+ require 'rvm/capistrano'
4
7
 
5
- if File.exists?('.rvmrc')
6
- matches = File.read('.rvmrc').scan(/^rvm\s+use\s+.*?([\w\-\.]+@[\w\-]+).*$/)
7
- if matches.any?
8
- set :rvm_ruby_string, matches.last.first
8
+ if File.exists?('.rvmrc')
9
+ matches = File.read('.rvmrc').scan(/^rvm\s+use\s+.*?([\w\-\.]+@[\w\-]+).*$/)
10
+ if matches.any?
11
+ set :rvm_ruby_string, matches.last.first
12
+ end
13
+ end
14
+ end
9
15
  end
10
16
  end
11
17
  end
@@ -1,20 +1,26 @@
1
- Capistrano::Configuration.instance(:must_exist).load do
2
- set(:unicorn_pid) { "`cat #{deploy_to}/tmp/pids/unicorn.pid`" }
1
+ module CapistranoDeploy
2
+ module Unicorn
3
+ def self.load_into(configuration)
4
+ configuration.load do
5
+ set(:unicorn_pid) { "`cat #{deploy_to}/tmp/pids/unicorn.pid`" }
3
6
 
4
- namespace :unicorn do
5
- desc 'Reload unicorn'
6
- task :reload, :roles => :app, :except => {:no_release => true} do
7
- run "kill -HUP #{unicorn_pid}"
8
- end
7
+ namespace :unicorn do
8
+ desc 'Reload unicorn'
9
+ task :reload, :roles => :app, :except => {:no_release => true} do
10
+ run "kill -HUP #{unicorn_pid}"
11
+ end
9
12
 
10
- desc 'Stop unicorn'
11
- task :stop, :roles => :app, :except => {:no_release => true} do
12
- run "kill -QUIT #{unicorn_pid}"
13
- end
13
+ desc 'Stop unicorn'
14
+ task :stop, :roles => :app, :except => {:no_release => true} do
15
+ run "kill -QUIT #{unicorn_pid}"
16
+ end
14
17
 
15
- desc 'Reexecute unicorn'
16
- task :reexec, :roles => :app, :except => {:no_release => true} do
17
- run "kill -USR2 #{unicorn_pid}"
18
+ desc 'Reexecute unicorn'
19
+ task :reexec, :roles => :app, :except => {:no_release => true} do
20
+ run "kill -USR2 #{unicorn_pid}"
21
+ end
22
+ end
23
+ end
18
24
  end
19
25
  end
20
26
  end
@@ -1,16 +1,35 @@
1
- Capistrano::Configuration.instance(:must_exist).load do
2
- set(:whenever_cmd) { 'whenever' }
3
- set(:whenever_identifier) { application }
1
+ module CapistranoDeploy
2
+ module Whenever
3
+ def self.load_into(configuration)
4
+ configuration.load do
5
+ set :whenever_cmd do
6
+ if using_recipe?(:bundle)
7
+ 'bundle exec whenever'
8
+ else
9
+ 'whenever'
10
+ end
11
+ end
4
12
 
5
- namespace :whenever do
6
- desc 'Update crontab file'
7
- task :update_crontab, :roles => :db, :only => {:primary => true} do
8
- run "cd #{deploy_to} && #{whenever_cmd} --update-crontab #{whenever_identifier}"
9
- end
13
+ set :whenever_identifier do
14
+ if using_recipe?(:multistage)
15
+ "#{application}_#{stage}"
16
+ else
17
+ application
18
+ end
19
+ end
20
+
21
+ namespace :whenever do
22
+ desc 'Update crontab file'
23
+ task :update_crontab, :roles => :db, :only => {:primary => true} do
24
+ run "cd #{deploy_to} && #{whenever_cmd} --update-crontab #{whenever_identifier}"
25
+ end
10
26
 
11
- desc 'Clear crontab file'
12
- task :clear_crontab, :roles => :db, :only => {:primary => true} do
13
- run "cd #{deploy_to} && #{whenever_cmd} --clear-crontab #{whenever_identifier}"
27
+ desc 'Clear crontab file'
28
+ task :clear_crontab, :roles => :db, :only => {:primary => true} do
29
+ run "cd #{deploy_to} && #{whenever_cmd} --clear-crontab #{whenever_identifier}"
30
+ end
31
+ end
32
+ end
14
33
  end
15
34
  end
16
35
  end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'deploy' do
4
+ before do
5
+ mock_config { use_recipes :git, :rails }
6
+ end
7
+
8
+ it 'returns used recipes' do
9
+ config.used_recipes.should == [:git, :rails]
10
+ end
11
+
12
+ it 'checks if recipe is used' do
13
+ config.should be_using_recipe(:git)
14
+ config.should_not be_using_recipe(:bundle)
15
+ end
16
+
17
+ describe 'deploy' do
18
+ it 'runs update and restart' do
19
+ config.namespaces[:deploy].should_receive(:update)
20
+ config.namespaces[:deploy].should_receive(:restart)
21
+ cli_execute 'deploy'
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,61 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'git' do
4
+ before do
5
+ mock_config { use_recipe :git; set :deploy_to, '/foo/bar' }
6
+ end
7
+
8
+ it 'has branch' do
9
+ config.branch.should == 'master'
10
+ end
11
+
12
+ context 'with repository' do
13
+ before do
14
+ mock_config { set :repository, 'git@example.com/test-app.git' }
15
+ end
16
+
17
+ it 'sets application from repo' do
18
+ config.application.should == 'test-app'
19
+ end
20
+
21
+ describe 'deploy:setup' do
22
+ it 'clones repository' do
23
+ cli_execute 'deploy:setup'
24
+ config.should have_run('mkdir -p `dirname /foo/bar` && git clone --no-checkout git@example.com/test-app.git /foo/bar')
25
+ end
26
+
27
+ it 'invokes update during setup' do
28
+ config.namespaces[:deploy].should_receive(:update)
29
+ cli_execute 'deploy:setup'
30
+ end
31
+ end
32
+
33
+ describe 'deploy:update' do
34
+ it 'updates' do
35
+ cli_execute 'deploy:update'
36
+ config.should have_run('cd /foo/bar && git fetch origin && git reset --hard origin/master')
37
+ end
38
+
39
+ it 'updates submodules' do
40
+ mock_config { set :enable_submodules, true }
41
+ cli_execute 'deploy:update'
42
+ config.should have_run('cd /foo/bar && git fetch origin && git reset --hard origin/master && git submodule init && git submodule -q sync && git submodule -q update')
43
+ end
44
+ end
45
+ end
46
+
47
+ it 'has current revision' do
48
+ config.should_receive(:capture).with('cd /foo/bar && git rev-parse HEAD') { "baz\n" }
49
+ config.current_revision.should == 'baz'
50
+ end
51
+
52
+ it 'shows pending' do
53
+ config.should_receive(:current_revision) { 'baz' }
54
+ config.namespaces[:deploy].should_receive(:system).with('git log --pretty=medium --stat baz..origin/master')
55
+ cli_execute 'deploy:pending'
56
+ end
57
+
58
+ it 'sets forward agent' do
59
+ config.ssh_options[:forward_agent].should == true
60
+ end
61
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'multistage' do
4
+ before do
5
+ mock_config do
6
+ use_recipes :multistage
7
+
8
+ set :default_stage, :development
9
+
10
+ define_stage :development do
11
+ set :foo, 'bar'
12
+ end
13
+
14
+ define_stage :production do
15
+ set :foo, 'baz'
16
+ end
17
+
18
+ task(:example) {}
19
+ end
20
+ end
21
+
22
+ it 'uses default stage' do
23
+ cli_execute 'example'
24
+ config.stage.should == 'development'
25
+ config.foo.should == 'bar'
26
+ end
27
+
28
+ it 'uses specified stage' do
29
+ cli_execute %w[production example]
30
+ config.stage.should == 'production'
31
+ config.foo.should == 'baz'
32
+ end
33
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'passenger' do
4
+ before do
5
+ mock_config do
6
+ use_recipe :passenger
7
+ set :deploy_to, '/foo/bar'
8
+ end
9
+ end
10
+
11
+ describe 'passenger:restart' do
12
+ it 'touches tmp/restart.txt' do
13
+ cli_execute 'passenger:restart'
14
+ config.should have_run('touch /foo/bar/tmp/restart.txt')
15
+ end
16
+ end
17
+
18
+ describe 'deploy:restart' do
19
+ it 'touches tmp/restart.txt' do
20
+ cli_execute 'deploy:restart'
21
+ config.should have_run('touch /foo/bar/tmp/restart.txt')
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'rails' do
4
+ before do
5
+ mock_config { use_recipe :rails }
6
+ end
7
+
8
+ describe 'deploy:migrate' do
9
+ before do
10
+ mock_config { set :deploy_to, '/foo/bar' }
11
+ end
12
+
13
+ it 'runs rake db:migrate' do
14
+ cli_execute 'deploy:migrate'
15
+ config.should have_run('cd /foo/bar && RAILS_ENV=production rake db:migrate')
16
+ end
17
+
18
+ it 'runs bundle exec db:migrate when using with bundle' do
19
+ mock_config { use_recipe :bundle }
20
+ cli_execute 'deploy:migrate'
21
+ config.should have_run('cd /foo/bar && RAILS_ENV=production bundle exec rake db:migrate')
22
+ end
23
+ end
24
+
25
+ describe 'deploy:migrations' do
26
+ it 'runs update, migrate and restart' do
27
+ config.namespaces[:deploy].should_receive(:update)
28
+ config.namespaces[:deploy].should_receive(:migrate)
29
+ config.namespaces[:deploy].should_receive(:restart)
30
+ cli_execute 'deploy:migrations'
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,65 @@
1
+ require 'capistrano'
2
+ require 'capistrano/cli'
3
+ require 'capistrano-deploy'
4
+
5
+ module CapistranoDeploy
6
+ module Spec
7
+ module ConfigurationExtension
8
+ def run(cmd, options={}, &block)
9
+ runs[cmd] = {:options => options, :block => block}
10
+ end
11
+
12
+ def runs
13
+ @runs ||= {}
14
+ end
15
+ end
16
+
17
+ module Helper
18
+ def mock_config(new_instance = false, &block)
19
+ if !@config || new_instance
20
+ @config = Capistrano::Configuration.new(:output => StringIO.new)
21
+ @config.extend(CapistranoDeploy::Spec::ConfigurationExtension)
22
+ CapistranoDeploy.load_into(@config)
23
+ end
24
+
25
+ @config.instance_eval(&block)
26
+ end
27
+
28
+ def config
29
+ @config
30
+ end
31
+
32
+ def cli_execute(*args)
33
+ config = @config
34
+ cli = Capistrano::CLI.parse(args.flatten).tap do |cli|
35
+ cli.instance_eval do
36
+ (class << self; self; end).send(:define_method, :instantiate_configuration) do |options|
37
+ config
38
+ end
39
+ end
40
+ end
41
+
42
+ cli.execute!
43
+ end
44
+ end
45
+
46
+ module Matchers
47
+ extend RSpec::Matchers::DSL
48
+
49
+ define :have_run do |cmd|
50
+ match do |configuration|
51
+ configuration.runs[cmd]
52
+ end
53
+
54
+ failure_message_for_should do |configuration|
55
+ "expected configuration to run #{cmd}, but it wasn't found in #{configuration.runs.keys}"
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+
62
+ RSpec.configure do |config|
63
+ config.include CapistranoDeploy::Spec::Helper
64
+ config.include CapistranoDeploy::Spec::Matchers
65
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'unicorn' do
4
+ before do
5
+ mock_config { use_recipes :unicorn }
6
+ end
7
+
8
+ it 'has default unicorn pid' do
9
+ mock_config { set :deploy_to, '/foo/bar' }
10
+ config.unicorn_pid.should == '`cat /foo/bar/tmp/pids/unicorn.pid`'
11
+ end
12
+
13
+ context 'signals' do
14
+ before do
15
+ mock_config { set :unicorn_pid, '/foo.pid' }
16
+ end
17
+
18
+ it 'reload' do
19
+ cli_execute 'unicorn:reload'
20
+ config.should have_run('kill -HUP /foo.pid')
21
+ end
22
+
23
+ it 'stop' do
24
+ cli_execute 'unicorn:stop'
25
+ config.should have_run('kill -QUIT /foo.pid')
26
+ end
27
+
28
+ it 'reexec' do
29
+ cli_execute 'unicorn:reexec'
30
+ config.should have_run('kill -USR2 /foo.pid')
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'whenever' do
4
+ before do
5
+ mock_config { use_recipe :whenever}
6
+ end
7
+
8
+ describe 'whenever_identifier' do
9
+ before do
10
+ mock_config { set :application, 'foo' }
11
+ end
12
+
13
+ it 'defaults to application' do
14
+ config.whenever_identifier.should == 'foo'
15
+ end
16
+
17
+ it 'default to application with stage when using multistage' do
18
+ mock_config do
19
+ use_recipe :multistage
20
+ set :stage, 'bar'
21
+ end
22
+ config.whenever_identifier.should == 'foo_bar'
23
+ end
24
+ end
25
+ end
metadata CHANGED
@@ -1,38 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-deploy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
- - Just Lest
8
+ - Sergey Nartimov
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-04 00:00:00.000000000Z
12
+ date: 2011-12-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: capistrano
16
- requirement: &9253740 !ruby/object:Gem::Requirement
16
+ requirement: &2157534600 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 2.8.0
21
+ version: 2.9.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *9253740
25
- - !ruby/object:Gem::Dependency
26
- name: rake
27
- requirement: &9251220 !ruby/object:Gem::Requirement
28
- none: false
29
- requirements:
30
- - - ! '>='
31
- - !ruby/object:Gem::Version
32
- version: '0'
33
- type: :development
34
- prerelease: false
35
- version_requirements: *9251220
24
+ version_requirements: *2157534600
36
25
  description:
37
26
  email:
38
27
  - just.lest@gmail.com
@@ -41,6 +30,7 @@ extensions: []
41
30
  extra_rdoc_files: []
42
31
  files:
43
32
  - .gitignore
33
+ - .rspec
44
34
  - Gemfile
45
35
  - Gemfile.lock
46
36
  - README.md
@@ -56,6 +46,14 @@ files:
56
46
  - lib/capistrano-deploy/rvm.rb
57
47
  - lib/capistrano-deploy/unicorn.rb
58
48
  - lib/capistrano-deploy/whenever.rb
49
+ - spec/deploy_spec.rb
50
+ - spec/git_spec.rb
51
+ - spec/multistage_spec.rb
52
+ - spec/passenger_spec.rb
53
+ - spec/rails_spec.rb
54
+ - spec/spec_helper.rb
55
+ - spec/unicorn_spec.rb
56
+ - spec/whenever_spec.rb
59
57
  homepage: https://github.com/lest/capistrano-deploy
60
58
  licenses: []
61
59
  post_install_message:
@@ -70,7 +68,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
70
68
  version: '0'
71
69
  segments:
72
70
  - 0
73
- hash: -700247554343477175
71
+ hash: 1789516116924546670
74
72
  required_rubygems_version: !ruby/object:Gem::Requirement
75
73
  none: false
76
74
  requirements:
@@ -79,11 +77,19 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
77
  version: '0'
80
78
  segments:
81
79
  - 0
82
- hash: -700247554343477175
80
+ hash: 1789516116924546670
83
81
  requirements: []
84
82
  rubyforge_project:
85
- rubygems_version: 1.8.6
83
+ rubygems_version: 1.8.10
86
84
  signing_key:
87
85
  specification_version: 3
88
86
  summary: Capistrano deploy recipes
89
- test_files: []
87
+ test_files:
88
+ - spec/deploy_spec.rb
89
+ - spec/git_spec.rb
90
+ - spec/multistage_spec.rb
91
+ - spec/passenger_spec.rb
92
+ - spec/rails_spec.rb
93
+ - spec/spec_helper.rb
94
+ - spec/unicorn_spec.rb
95
+ - spec/whenever_spec.rb