Skip to content
Browse files

Re-organized capistrano task to allow for testing

  • Loading branch information...
1 parent ca0ee34 commit ee3ea1b7c020b3877523b20b32f88e3d419dd90b @czarneckid czarneckid committed
Showing with 60 additions and 15 deletions.
  1. +1 −0 airbrake.gemspec
  2. +26 −15 lib/airbrake/capistrano.rb
  3. +33 −0 test/capistrano_test.rb
View
1 airbrake.gemspec
@@ -24,6 +24,7 @@ Gem::Specification.new do |s|
s.add_development_dependency("rspec", "~> 2.6.0")
s.add_development_dependency("sham_rack", "~> 1.3.0")
s.add_development_dependency("shoulda", "~> 2.11.3")
+ s.add_development_dependency("capistrano", "~> 2.8.0")
s.authors = ["thoughtbot, inc"]
s.email = %q{support@airbrakeapp.com}
View
41 lib/airbrake/capistrano.rb
@@ -1,21 +1,32 @@
# Defines deploy:notify_airbrake which will send information about the deploy to Airbrake.
+require 'capistrano'
-Capistrano::Configuration.instance(:must_exist).load do
- after "deploy", "deploy:notify_airbrake"
- after "deploy:migrations", "deploy:notify_airbrake"
+module Airbrake
+ module Capistrano
+ def self.load_into(configuration)
+ configuration.load do
+ after "deploy", "airbrake:notify"
+ after "deploy:migrations", "airbrake:notify"
- namespace :deploy do
- desc "Notify Airbrake of the deployment"
- task :notify_airbrake, :except => { :no_release => true } do
- rails_env = fetch(:airbrake_env, fetch(:rails_env, "production"))
- local_user = ENV['USER'] || ENV['USERNAME']
- executable = RUBY_PLATFORM.downcase.include?('mswin') ? fetch(:rake, 'rake.bat') : fetch(:rake, 'rake')
- notify_command = "#{executable} airbrake:deploy TO=#{rails_env} REVISION=#{current_revision} REPO=#{repository} USER=#{local_user}"
- notify_command << " DRY_RUN=true" if dry_run
- notify_command << " API_KEY=#{ENV['API_KEY']}" if ENV['API_KEY']
- logger.info "Notifying Airbrake of Deploy (#{notify_command})"
- `#{notify_command}`
- logger.info "Airbrake Notification Complete."
+ namespace :airbrake do
+ desc "Notify Airbrake of the deployment"
+ task :notify, :except => { :no_release => true } do
+ rails_env = fetch(:airbrake_env, fetch(:rails_env, "production"))
+ local_user = ENV['USER'] || ENV['USERNAME']
+ executable = RUBY_PLATFORM.downcase.include?('mswin') ? fetch(:rake, 'rake.bat') : fetch(:rake, 'rake')
+ notify_command = "#{executable} airbrake:deploy TO=#{rails_env} REVISION=#{current_revision} REPO=#{repository} USER=#{local_user}"
+ notify_command << " DRY_RUN=true" if dry_run
+ notify_command << " API_KEY=#{ENV['API_KEY']}" if ENV['API_KEY']
+ logger.info "Notifying Airbrake of Deploy (#{notify_command})"
+ `#{notify_command}` if !configuration.dry_run
+ logger.info "Airbrake Notification Complete."
+ end
+ end
+ end
end
end
end
+
+if Capistrano::Configuration.instance
+ Airbrake::Capistrano.load_into(Capistrano::Configuration.instance)
+end
View
33 test/capistrano_test.rb
@@ -0,0 +1,33 @@
+require File.dirname(__FILE__) + '/helper'
+
+require 'capistrano/configuration'
+require 'airbrake/capistrano'
+
+class CapistranoTest < Test::Unit::TestCase
+ def setup
+ super
+ reset_config
+
+ @configuration = Capistrano::Configuration.new
+ Airbrake::Capistrano.load_into(@configuration)
+ @configuration.dry_run = true
+ end
+
+ should "define deploy:notify_airbrake task" do
+ assert_not_nil @configuration.find_task('airbrake:notify')
+ end
+
+ should "log when calling deploy:notify_airbrake task" do
+ @configuration.set(:current_revision, '084505b1c0e0bcf1526e673bb6ac99fbcb18aecc')
+ @configuration.set(:repository, 'repository')
+ io = StringIO.new
+ logger = Capistrano::Logger.new(:output => io)
+ logger.level = Capistrano::Logger::MAX_LEVEL
+
+ @configuration.logger = logger
+ @configuration.find_and_execute_task('airbrake:notify')
+
+ assert io.string.include?('** Notifying Airbrake of Deploy')
+ assert io.string.include?('** Airbrake Notification Complete')
+ end
+end

0 comments on commit ee3ea1b

Please sign in to comment.
Something went wrong with that request. Please try again.