mirror of
https://github.com/inspec/inspec
synced 2024-11-10 07:04:15 +00:00
Merge pull request #4768 from inspec/zenspider/bug628
Wire up backend to rspec metadata, allowing for example groups to use resources
This commit is contained in:
commit
5d8a0af8ce
4 changed files with 28 additions and 20 deletions
|
@ -23,11 +23,11 @@ Gem::Specification.new do |spec|
|
|||
|
||||
spec.required_ruby_version = ">= 2.4"
|
||||
|
||||
spec.add_dependency "train", "~> 3.0" # Inspec 4 must have train 2+; 3+ if we include train-winrm
|
||||
spec.add_dependency "train", "~> 3.0"
|
||||
# Train plugins we ship with InSpec
|
||||
spec.add_dependency "train-habitat", "~> 0.1"
|
||||
spec.add_dependency "train-aws", "~> 0.1"
|
||||
spec.add_dependency "train-winrm", "~> 0.2" # Requires train 3+
|
||||
spec.add_dependency "train-winrm", "~> 0.2"
|
||||
|
||||
# Implementation dependencies
|
||||
spec.add_dependency "chef-telemetry", "~> 1.0"
|
||||
|
|
|
@ -11,14 +11,13 @@ module Inspec
|
|||
module DescribeDslLazyLoader
|
||||
# Support for Describe DSL plugins
|
||||
def method_missing(method_name, *arguments, &block)
|
||||
# TODO: need a backend available at the describe level... class method somewhere?
|
||||
# # see if it is a resource first
|
||||
# begin
|
||||
# resource = Inspec::DSL.method_missing_resource(:where_is_backend?, method_name, *arguments)
|
||||
# return resource if resource
|
||||
# rescue LoadError
|
||||
# # pass through
|
||||
# end
|
||||
begin
|
||||
backend = metadata[:backend] # populated via Inspec::Runner#add_resource
|
||||
resource = Inspec::DSL.method_missing_resource(backend, method_name, *arguments)
|
||||
return resource if resource
|
||||
rescue LoadError
|
||||
# pass through
|
||||
end
|
||||
|
||||
# Check to see if there is a describe_dsl plugin activator hook with the method name
|
||||
registry = Inspec::Plugin::V2::Registry.instance
|
||||
|
|
|
@ -307,6 +307,8 @@ module Inspec
|
|||
def add_resource(method_name, arg, opts, block)
|
||||
case method_name
|
||||
when "describe"
|
||||
opts = { backend: @test_collector.backend }.merge opts
|
||||
|
||||
@test_collector.example_group(*arg, opts, &block)
|
||||
when "expect"
|
||||
block.example_group
|
||||
|
|
|
@ -10,6 +10,8 @@ require "inspec/rspec_extensions"
|
|||
|
||||
module Inspec
|
||||
class RunnerRspec
|
||||
attr_accessor :formatter
|
||||
|
||||
def initialize(conf)
|
||||
@conf = conf
|
||||
@formatter = nil
|
||||
|
@ -22,29 +24,34 @@ module Inspec
|
|||
# @param [Type] &block the block associated with this example group
|
||||
# @return [RSpecExampleGroup]
|
||||
def example_group(*args, &block)
|
||||
# NOTE: this RUNS immediately
|
||||
RSpec::Core::ExampleGroup.describe(*args, &block)
|
||||
end
|
||||
|
||||
def formatters
|
||||
RSpec.configuration.formatters.grep(Inspec::Formatters::Base)
|
||||
end
|
||||
|
||||
# Add a full profile to the runner. Only pulls in metadata
|
||||
#
|
||||
# @param [Inspec::Profile] profile
|
||||
# @return [nil]
|
||||
def add_profile(profile)
|
||||
RSpec.configuration.formatters
|
||||
.find_all { |c| c.is_a?(Inspec::Formatters::Base) }
|
||||
.each do |fmt|
|
||||
formatters.each do |fmt|
|
||||
fmt.add_profile(profile)
|
||||
end
|
||||
end
|
||||
|
||||
def backend
|
||||
formatters.first.backend
|
||||
end
|
||||
|
||||
# Configure the backend of the runner.
|
||||
#
|
||||
# @param [Inspec::Backend] backend
|
||||
# @return [nil]
|
||||
def backend=(backend)
|
||||
RSpec.configuration.formatters
|
||||
.find_all { |c| c.is_a?(Inspec::Formatters::Base) }
|
||||
.each do |fmt|
|
||||
formatters.each do |fmt|
|
||||
fmt.backend = backend
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue