Remove class var for testing, replace with tramp data

Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
This commit is contained in:
Clinton Wolfe 2019-01-16 00:24:19 -05:00
parent 212fe36b76
commit 48e2188047
3 changed files with 8 additions and 23 deletions

View file

@ -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

View file

@ -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

View file

@ -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