From 48e21880471db787b991551359ffd4b3d1da3495 Mon Sep 17 00:00:00 2001 From: Clinton Wolfe Date: Wed, 16 Jan 2019 00:24:19 -0500 Subject: [PATCH] Remove class var for testing, replace with tramp data Signed-off-by: Clinton Wolfe --- lib/utils/deprecation/deprecator.rb | 8 +------- lib/utils/deprecation/global_method.rb | 3 ++- .../libraries/deprecation_tester.rb | 20 +++++-------------- 3 files changed, 8 insertions(+), 23 deletions(-) diff --git a/lib/utils/deprecation/deprecator.rb b/lib/utils/deprecation/deprecator.rb index c53a1eeed..abd95b0d1 100644 --- a/lib/utils/deprecation/deprecator.rb +++ b/lib/utils/deprecation/deprecator.rb @@ -6,14 +6,8 @@ module Inspec class Deprecator attr_reader :config, :groups - # This is used only in functional testing - def self.class_test_cfg_io(io) - @@test_cfg_io = io # rubocop: disable Style/ClassVars - end - def initialize(opts = {}) - @@test_cfg_io ||= nil # rubocop: disable Style/ClassVars - @config = Inspec::Deprecation::ConfigFile.new(opts[:config_io] || @@test_cfg_io) + @config = Inspec::Deprecation::ConfigFile.new(opts[:config_io]) @groups = @config.groups end diff --git a/lib/utils/deprecation/global_method.rb b/lib/utils/deprecation/global_method.rb index ac2d3ade7..aba4fcab8 100644 --- a/lib/utils/deprecation/global_method.rb +++ b/lib/utils/deprecation/global_method.rb @@ -2,7 +2,8 @@ require 'utils/deprecation/deprecator' module Inspec def self.deprecate(group, msg, opts = {}) - deprecator = opts.delete(:deprecator) || Inspec::Deprecation::Deprecator.new + config_io = opts.delete(:config_io) + deprecator = Inspec::Deprecation::Deprecator.new(config_io: config_io) deprecator.handle_deprecation(group, msg, opts) end end diff --git a/test/unit/mock/profiles/deprecation/resource_pack/libraries/deprecation_tester.rb b/test/unit/mock/profiles/deprecation/resource_pack/libraries/deprecation_tester.rb index 26b7addae..3a7e52a11 100644 --- a/test/unit/mock/profiles/deprecation/resource_pack/libraries/deprecation_tester.rb +++ b/test/unit/mock/profiles/deprecation/resource_pack/libraries/deprecation_tester.rb @@ -18,41 +18,31 @@ class DeprecationTester < Inspec.resource(1) EOC def fail_me - Inspec::Deprecation::Deprecator.class_test_cfg_io(StringIO.new(DEPRECATION_CFG)) - - Inspec.deprecate(:a_group_that_will_fail, 'This should fail') + Inspec.deprecate(:a_group_that_will_fail, 'This should fail', config_io: StringIO.new(DEPRECATION_CFG)) 'fail_me_return_value' end def exit_me_default_code - Inspec::Deprecation::Deprecator.class_test_cfg_io(StringIO.new(DEPRECATION_CFG)) - - Inspec.deprecate(:a_group_that_will_exit, 'This should exit') + Inspec.deprecate(:a_group_that_will_exit, 'This should exit', config_io: StringIO.new(DEPRECATION_CFG)) 'exit_me_return_value' end def exit_me_explicit_code - Inspec::Deprecation::Deprecator.class_test_cfg_io(StringIO.new(DEPRECATION_CFG)) - - Inspec.deprecate(:a_group_that_will_exit_with_a_code, 'This should exit') + Inspec.deprecate(:a_group_that_will_exit_with_a_code, 'This should exit', config_io: StringIO.new(DEPRECATION_CFG)) 'exit_me_return_value' end def ignore_me - Inspec::Deprecation::Deprecator.class_test_cfg_io(StringIO.new(DEPRECATION_CFG)) - - Inspec.deprecate(:an_ignored_group, 'This should be ignored') + Inspec.deprecate(:an_ignored_group, 'This should be ignored', config_io: StringIO.new(DEPRECATION_CFG)) 'ignore_me_return_value' end def warn_me - Inspec::Deprecation::Deprecator.class_test_cfg_io(StringIO.new(DEPRECATION_CFG)) - - Inspec.deprecate(:a_group_that_will_warn, 'This should warn') + Inspec.deprecate(:a_group_that_will_warn, 'This should warn', config_io: StringIO.new(DEPRECATION_CFG)) 'warn_me_return_value' end