mirror of
https://github.com/inspec/inspec
synced 2024-12-18 17:14:33 +00:00
isolate rspec-dsl in profile context
This commit is contained in:
parent
b991dd03bb
commit
21a92a0c4e
2 changed files with 17 additions and 11 deletions
lib/inspec
|
@ -4,7 +4,6 @@
|
||||||
|
|
||||||
require 'inspec/rule'
|
require 'inspec/rule'
|
||||||
require 'inspec/dsl'
|
require 'inspec/dsl'
|
||||||
require 'rspec/core/dsl'
|
|
||||||
require 'securerandom'
|
require 'securerandom'
|
||||||
|
|
||||||
module Inspec
|
module Inspec
|
||||||
|
@ -25,7 +24,8 @@ module Inspec
|
||||||
end
|
end
|
||||||
|
|
||||||
def reload_dsl
|
def reload_dsl
|
||||||
ctx = create_context
|
resources_dsl = Inspec::Resource.create_dsl(@backend)
|
||||||
|
ctx = create_context(resources_dsl, rule_context(resources_dsl))
|
||||||
@profile_context = ctx.new
|
@profile_context = ctx.new
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -64,6 +64,19 @@ module Inspec
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
# Create the context for controls. This includes all components of the DSL,
|
||||||
|
# including matchers and resources.
|
||||||
|
#
|
||||||
|
# @param [ResourcesDSL] resources_dsl which has all resources to attach
|
||||||
|
# @return [RuleContext] the inner context of rules
|
||||||
|
def rule_context(resources_dsl)
|
||||||
|
require 'rspec/core/dsl'
|
||||||
|
Class.new(Inspec::Rule) do
|
||||||
|
include RSpec::Core::DSL
|
||||||
|
include resources_dsl
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Creates the heart of the profile context:
|
# Creates the heart of the profile context:
|
||||||
# An instantiated object which has all resources registered to it
|
# An instantiated object which has all resources registered to it
|
||||||
# and exposes them to the a test file. The profile context serves as a
|
# and exposes them to the a test file. The profile context serves as a
|
||||||
|
@ -72,15 +85,8 @@ module Inspec
|
||||||
#
|
#
|
||||||
# @param outer_dsl [OuterDSLClass]
|
# @param outer_dsl [OuterDSLClass]
|
||||||
# @return [ProfileContextClass]
|
# @return [ProfileContextClass]
|
||||||
def create_context
|
def create_context(resources_dsl, rule_class)
|
||||||
profile_context_owner = self
|
profile_context_owner = self
|
||||||
resources_dsl = Inspec::Resource.create_dsl(@backend)
|
|
||||||
|
|
||||||
# the inner working of a rule
|
|
||||||
rule_class = Class.new(Inspec::Rule) do
|
|
||||||
include RSpec::Core::DSL
|
|
||||||
include resources_dsl
|
|
||||||
end
|
|
||||||
|
|
||||||
# rubocop:disable Lint/NestedMethodDefinition
|
# rubocop:disable Lint/NestedMethodDefinition
|
||||||
Class.new do
|
Class.new do
|
||||||
|
|
|
@ -17,7 +17,7 @@ module Inspec
|
||||||
# which is specified via the backend argument.
|
# which is specified via the backend argument.
|
||||||
#
|
#
|
||||||
# @param backend [BackendRunner] exposing the target to resources
|
# @param backend [BackendRunner] exposing the target to resources
|
||||||
# @return [ResourceDSLModule]
|
# @return [ResourcesDSL]
|
||||||
def self.create_dsl(backend)
|
def self.create_dsl(backend)
|
||||||
# need the local name, to use it in the module creation further down
|
# need the local name, to use it in the module creation further down
|
||||||
my_registry = registry
|
my_registry = registry
|
||||||
|
|
Loading…
Reference in a new issue