Fix a bad interaction involving clearing the plugin registry in unit testing

Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
This commit is contained in:
Clinton Wolfe 2020-05-24 23:13:27 -04:00 committed by Mary Jinglewski
parent 83c7f84290
commit aa824d1b49
4 changed files with 27 additions and 34 deletions

View file

@ -1,14 +1,18 @@
# This file is known as the "entry point."
# This is the file InSpec will try to load if it
# thinks your plugin is installed.
# The *only* thing this file should do is setup the
# load path, then load the plugin definition file.
# Next two lines simply add the path of the gem to the load path.
# This is not needed when being loaded as a gem; but when doing
# plugin development, you may need it. Either way, it's harmless.
libdir = File.dirname(__FILE__)
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
require "inspec-reporter-html2/plugin"
require "inspec-reporter-html2/version"
module InspecPlugins
module Html2Reporter
class Plugin < ::Inspec.plugin(2)
# Internal machine name of the plugin. InSpec will use this in errors, etc.
plugin_name :'inspec-reporter-html2'
# Define a new Reporter.
reporter :html2 do
require "inspec-reporter-html2/reporter"
InspecPlugins::Html2Reporter::Reporter
end
end
end
end

View file

@ -1,22 +0,0 @@
require "inspec-reporter-html2/version"
# The InspecPlugins namespace is where all plugins should declare themselves.
# The 'Inspec' capitalization is used throughout the InSpec source code; yes, it's
# strange.
module InspecPlugins
# Pick a reasonable namespace here for your plugin. A reasonable choice
# would be the CamelCase version of your plugin gem name.
# inspec-reporter-html => HtmlReporter
module Html2Reporter
class Plugin < ::Inspec.plugin(2)
# Internal machine name of the plugin. InSpec will use this in errors, etc.
plugin_name :'inspec-reporter-html2'
# Define a new Reporter.
reporter :html2 do
require "inspec-reporter-html2/reporter"
InspecPlugins::Html2Reporter::Reporter
end
end
end
end

View file

@ -1,13 +1,23 @@
require_relative "../../../shared/core_plugin_test_helper.rb"
require_relative "../../lib/inspec-reporter-html2"
require "inspec/plugin/v2"
describe InspecPlugins::Html2Reporter::Plugin do
let(:plugin_name) { :'inspec-reporter-html2' }
let(:registry) { Inspec::Plugin::V2::Registry.instance }
let(:status) { registry[plugin_name] }
# During full unit testing, the registry is purged by test/unit/plugins/v2/loader_test.rb
def setup
Inspec::Plugin::V2::Loader.new.load_all
end
def teardown
registry.__reset
end
it "should be registered" do
registry.known_plugin?(plugin_name)
_(registry.known_plugin?(plugin_name)).must_equal true
end
it "should be an api-v2 plugin" do

View file

@ -36,6 +36,7 @@ class PluginLoaderTests < Minitest::Test
inspec-compliance
inspec-habitat
inspec-init
inspec-reporter-html2
}
@system_plugins = [
"train-habitat",