diff --git a/lib/pdk/cli.rb b/lib/pdk/cli.rb index 4329903f3..d70f91e8a 100644 --- a/lib/pdk/cli.rb +++ b/lib/pdk/cli.rb @@ -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) diff --git a/spec/unit/pdk/cli_spec.rb b/spec/unit/pdk/cli_spec.rb index e82f7a6c9..275a69c40 100644 --- a/spec/unit/pdk/cli_spec.rb +++ b/spec/unit/pdk/cli_spec.rb @@ -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 @@ -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