Skip to content

Commit

Permalink
Merge pull request #785 from rodjek/pdk-1519
Browse files Browse the repository at this point in the history
(PDK-1519) Print deprecation notice on Ruby < 2.4
  • Loading branch information
rodjek authored Oct 22, 2019
2 parents a60f378 + 079e0c4 commit 73149c5
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/pdk/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,23 @@ def self.anonymised_args
end
end

def self.deprecated_runtime?
Gem::Version.new(RbConfig::CONFIG['ruby_version']) < Gem::Version.new('2.4.0')
end

def self.run(args)
if deprecated_runtime?
PDK.logger.info(
text: _(
'Support for Ruby versions older than 2.4 will be dropped in the ' \
'future PDK 2.0.0 release. We recommend updating your Ruby ' \
'installation to ensure that you can continue using the latest ' \
'version of PDK.',
),
wrap: true,
)
end

@args = args
PDK::Config.analytics_config_interview! unless ENV['PDK_DISABLE_ANALYTICS'] || PDK::Config.analytics_config_exist?
@base_cmd.run(args)
Expand Down
34 changes: 34 additions & 0 deletions spec/unit/pdk/cli_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
require 'spec_helper'
require 'pdk/cli'

def deprecated_runtime?
Gem::Version.new(RbConfig::CONFIG['ruby_version']) < Gem::Version.new('2.4.0')
end

describe PDK::CLI do
context 'when invoking help' do
it 'outputs basic help' do
Expand All @@ -10,6 +14,36 @@
end
end

context 'when invoked by Ruby < 2.4.0', if: deprecated_runtime? do
before(:each) do
allow($stdout).to receive(:puts)
end

it 'informs the user of the upcoming Ruby deprecation' do
expect(logger).to receive(:info).with(
text: a_string_matching(%r{ruby versions older than}i),
wrap: true,
)

described_class.run([])
end
end

context 'when invoked by Ruby >= 2.4.0', unless: deprecated_runtime? do
before(:each) do
allow($stdout).to receive(:puts)
end

it 'does not inform the user of an upcoming Ruby deprecation' do
expect(logger).not_to receive(:info).with(
text: a_string_matching(%r{ruby versions older than}i),
wrap: true,
)

described_class.run([])
end
end

context 'analytics opt-out prompt' do
before(:each) do
# Temporarily bypass suite-wide analytics disable
Expand Down

0 comments on commit 73149c5

Please sign in to comment.