Skip to content

Commit

Permalink
fix: add guard to ensure CAPISTRANO::VERSION is defined (#984)
Browse files Browse the repository at this point in the history
  • Loading branch information
waltjones committed Jul 21, 2020
1 parent 34b0a63 commit 2e6980d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/rollbar/capistrano_tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ def deploy_update(capistrano, logger, dry_run, opts = {})
end

def capistrano_300_warning(logger)
logger.warn("You need to upgrade capistrano to '>= 3.1' version in order to correctly report deploys to Rollbar. (On 3.0, the reported revision will be incorrect.)") if ::Capistrano::VERSION =~ /^3\.0/
return unless ::Capistrano.const_defined?('VERSION') && ::Capistrano::VERSION =~ /^3\.0/

logger.warn('You need to upgrade capistrano to >= 3.1 version in order'\
'to correctly report deploys to Rollbar. (On 3.0, the reported revision'\
'will be incorrect.)')
end

def report_deploy_started(capistrano, dry_run)
Expand Down
40 changes: 40 additions & 0 deletions spec/rollbar/capistrano_tasks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -326,4 +326,44 @@
end
end
end

describe '.capistrano_300_warning' do
context 'when ::Capistrano::VERSION is defined' do
it 'does nothing' do
expect(logger).not_to receive(:warn)

subject.send(:capistrano_300_warning, logger)
end
end

context 'when ::Capistrano::VERSION is 3.0' do
it 'logs a warning' do
# The class is not reloaded between tests, so prepare to restore the constant.
original_version = ::Capistrano::VERSION
::Capistrano.send(:remove_const, 'VERSION')
::Capistrano.const_set('VERSION', '3.0.0')

expect(logger).to receive(:warn)

subject.send(:capistrano_300_warning, logger)

::Capistrano.send(:remove_const, 'VERSION')
::Capistrano.const_set('VERSION', original_version)
end
end

context 'when ::Capistrano::VERSION is undefined' do
it 'does nothing' do
# The class is not reloaded between tests, so prepare to restore the constant.
original_version = ::Capistrano::VERSION
::Capistrano.send(:remove_const, 'VERSION')

expect(logger).not_to receive(:warn)

subject.send(:capistrano_300_warning, logger)

::Capistrano.const_set('VERSION', original_version)
end
end
end
end

0 comments on commit 2e6980d

Please sign in to comment.