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 class Deprecator
attr_reader :config, :groups 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 = {}) def initialize(opts = {})
@@test_cfg_io ||= nil # rubocop: disable Style/ClassVars @config = Inspec::Deprecation::ConfigFile.new(opts[:config_io])
@config = Inspec::Deprecation::ConfigFile.new(opts[:config_io] || @@test_cfg_io)
@groups = @config.groups @groups = @config.groups
end end

View file

@ -2,7 +2,8 @@ require 'utils/deprecation/deprecator'
module Inspec module Inspec
def self.deprecate(group, msg, opts = {}) 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) deprecator.handle_deprecation(group, msg, opts)
end end
end end

View file

@ -18,41 +18,31 @@ class DeprecationTester < Inspec.resource(1)
EOC EOC
def fail_me def fail_me
Inspec::Deprecation::Deprecator.class_test_cfg_io(StringIO.new(DEPRECATION_CFG)) Inspec.deprecate(:a_group_that_will_fail, 'This should fail', config_io: StringIO.new(DEPRECATION_CFG))
Inspec.deprecate(:a_group_that_will_fail, 'This should fail')
'fail_me_return_value' 'fail_me_return_value'
end end
def exit_me_default_code 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', config_io: StringIO.new(DEPRECATION_CFG))
Inspec.deprecate(:a_group_that_will_exit, 'This should exit')
'exit_me_return_value' 'exit_me_return_value'
end end
def exit_me_explicit_code 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', config_io: StringIO.new(DEPRECATION_CFG))
Inspec.deprecate(:a_group_that_will_exit_with_a_code, 'This should exit')
'exit_me_return_value' 'exit_me_return_value'
end end
def ignore_me def ignore_me
Inspec::Deprecation::Deprecator.class_test_cfg_io(StringIO.new(DEPRECATION_CFG)) Inspec.deprecate(:an_ignored_group, 'This should be ignored', config_io: StringIO.new(DEPRECATION_CFG))
Inspec.deprecate(:an_ignored_group, 'This should be ignored')
'ignore_me_return_value' 'ignore_me_return_value'
end end
def warn_me def warn_me
Inspec::Deprecation::Deprecator.class_test_cfg_io(StringIO.new(DEPRECATION_CFG)) Inspec.deprecate(:a_group_that_will_warn, 'This should warn', config_io: StringIO.new(DEPRECATION_CFG))
Inspec.deprecate(:a_group_that_will_warn, 'This should warn')
'warn_me_return_value' 'warn_me_return_value'
end end