Class: Inspec::Runner
- Inherits:
-
Object
- Object
- Inspec::Runner
- Extended by:
- Forwardable
- Defined in:
- lib/inspec/runner.rb
Overview
rubocop:disable Metrics/ClassLength
Instance Attribute Summary collapse
-
#backend ⇒ Object
readonly
Returns the value of attribute backend.
-
#rules ⇒ Object
readonly
Returns the value of attribute rules.
Instance Method Summary collapse
- #add_content(test, libs) ⇒ Object
- #add_test_profile(test, ignore_supports = false) ⇒ Object
- #add_tests(tests, options = {}) ⇒ Object
- #configure_transport ⇒ Object
- #create_context ⇒ Object
-
#initialize(conf = {}) ⇒ Runner
constructor
A new instance of Runner.
- #normalize_map(hm) ⇒ Object
- #tests ⇒ Object
Constructor Details
#initialize(conf = {}) ⇒ Runner
Returns a new instance of Runner.
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/inspec/runner.rb', line 19 def initialize(conf = {}) @rules = {} @profile_id = conf[:id] @conf = conf.dup @conf[:logger] ||= Logger.new(nil) @test_collector = @conf.delete(:test_collector) || begin require 'inspec/runner_rspec' RunnerRspec.new(@conf) end configure_transport end |
Instance Attribute Details
#backend ⇒ Object (readonly)
Returns the value of attribute backend.
18 19 20 |
# File 'lib/inspec/runner.rb', line 18 def backend @backend end |
#rules ⇒ Object (readonly)
Returns the value of attribute rules.
18 19 20 |
# File 'lib/inspec/runner.rb', line 18 def rules @rules end |
Instance Method Details
#add_content(test, libs) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/inspec/runner.rb', line 94 def add_content(test, libs) content = test[:content] return if content.nil? || content.empty? # load all libraries ctx = create_context libs.each do |lib| ctx.load(lib[:content].to_s, lib[:ref], lib[:line] || 1) ctx.reload_dsl end # evaluate the test content ctx.load(content, test[:ref], test[:line] || 1) # process the resulting rules ctx.rules.each do |rule_id, rule| register_rule(rule_id, rule) end end |
#add_test_profile(test, ignore_supports = false) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/inspec/runner.rb', line 49 def add_test_profile(test, ignore_supports = false) assets = Inspec::Targets.resolve(test, @conf) = assets.find_all { |a| a[:type] == :metadata } = .map do |x| Inspec::Metadata.from_ref(x[:ref], x[:content], @profile_id, @conf[:logger]) end .each do || return [] unless ignore_supports || .supports_transport?(@backend) end assets end |
#add_tests(tests, options = {}) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/inspec/runner.rb', line 61 def add_tests(tests, = {}) # retrieve the raw ruby code of all tests items = tests.map do |test| add_test_profile(test, [:ignore_supports]) end.flatten tests = items.find_all { |i| i[:type] == :test } libs = items.find_all { |i| i[:type] == :library } = items.find_all { |i| i[:type] == :metadata } # Ensure each test directory exists on the $LOAD_PATH. This # will ensure traditional RSpec-isms like `require 'spec_helper'` # continue to work. tests.flatten.each do |test| # do not load path for virtual files, eg. from zip if !test[:ref].nil? test_directory = File.dirname(test[:ref]) $LOAD_PATH.unshift test_directory unless $LOAD_PATH.include?(test_directory) end end # add all tests (raw) to the runtime tests.flatten.each do |test| add_content(test, libs) end [tests, libs, ] end |
#configure_transport ⇒ Object
45 46 47 |
# File 'lib/inspec/runner.rb', line 45 def configure_transport @backend = Inspec::Backend.create(@conf) end |
#create_context ⇒ Object
90 91 92 |
# File 'lib/inspec/runner.rb', line 90 def create_context Inspec::ProfileContext.new(@profile_id, @backend) end |
#normalize_map(hm) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/inspec/runner.rb', line 37 def normalize_map(hm) res = {} hm.each {|k, v| res[k.to_s] = v } res end |
#tests ⇒ Object
33 34 35 |
# File 'lib/inspec/runner.rb', line 33 def tests @test_collector.tests end |