From 079e0c48cec2cf76316a96531e7754756870f631 Mon Sep 17 00:00:00 2001 From: Tim Sharpe Date: Tue, 22 Oct 2019 13:40:49 +1100 Subject: [PATCH] (PDK-1519) Print deprecation notice on Ruby < 2.4 Happens at the start of the global CLI runner block so that it applies to all PDK commands. This doesn't inform users who are purely using PDK as a library though, but I think that they're better served by documenting the upcoming deprecation as well as following semver and performing a major version bump when dropping support for older Rubies. --- lib/pdk/cli.rb | 16 ++++++++++++++++ spec/unit/pdk/cli_spec.rb | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/lib/pdk/cli.rb b/lib/pdk/cli.rb index 327d0aad8..ee738fcee 100644 --- a/lib/pdk/cli.rb +++ b/lib/pdk/cli.rb @@ -41,7 +41,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