Class: Inspec::RunnerRspec
- Inherits:
-
Object
- Object
- Inspec::RunnerRspec
- Defined in:
- lib/inspec/runner_rspec.rb
Instance Attribute Summary collapse
-
#formatter ⇒ Object
Returns the value of attribute formatter.
Instance Method Summary collapse
-
#add_profile(profile) ⇒ nil
Add a full profile to the runner.
-
#add_test(example, rule) ⇒ nil
Add an example group to the list of registered tests.
-
#backend ⇒ Object
end of control count related methods.
-
#backend=(backend) ⇒ nil
Configure the backend of the runner.
-
#example_group(*args, &block) ⇒ RSpecExampleGroup
Create a new RSpec example group from arguments and block.
-
#exit_code ⇒ int
Return a proper exit code to the runner.
- #formatters ⇒ Object
-
#initialize(conf) ⇒ RunnerRspec
constructor
A new instance of RunnerRspec.
-
#reset ⇒ nil
Empty the list of registered tests.
-
#run(with = nil) ⇒ int
Run all registered tests with an optional test runner.
- #set_control_checks_count_map(mapping) ⇒ Object
-
#set_controls_count(controls_count) ⇒ Object
These control count related methods are called from load logic of runner library of inspec Start of control count related methods.
-
#tests ⇒ Array
Retrieve the list of tests that have been added.
Constructor Details
#initialize(conf) ⇒ RunnerRspec
Returns a new instance of RunnerRspec.
15 16 17 18 19 |
# File 'lib/inspec/runner_rspec.rb', line 15 def initialize(conf) @conf = conf @formatter = nil reset end |
Instance Attribute Details
#formatter ⇒ Object
Returns the value of attribute formatter.
13 14 15 |
# File 'lib/inspec/runner_rspec.rb', line 13 def formatter @formatter end |
Instance Method Details
#add_profile(profile) ⇒ nil
Add a full profile to the runner. Only pulls in metadata
39 40 41 42 43 |
# File 'lib/inspec/runner_rspec.rb', line 39 def add_profile(profile) formatters.each do |fmt| fmt.add_profile(profile) end end |
#add_test(example, rule) ⇒ nil
Add an example group to the list of registered tests.
79 80 81 82 |
# File 'lib/inspec/runner_rspec.rb', line 79 def add_test(example, rule) set_rspec_ids(example, rule) @tests.example_groups.push(example) end |
#backend ⇒ Object
end of control count related methods
60 61 62 |
# File 'lib/inspec/runner_rspec.rb', line 60 def backend formatters.first.backend end |
#backend=(backend) ⇒ nil
Configure the backend of the runner.
68 69 70 71 72 |
# File 'lib/inspec/runner_rspec.rb', line 68 def backend=(backend) formatters.each do |fmt| fmt.backend = backend end end |
#example_group(*args, &block) ⇒ RSpecExampleGroup
Create a new RSpec example group from arguments and block.
26 27 28 29 |
# File 'lib/inspec/runner_rspec.rb', line 26 def example_group(*args, &block) # NOTE: this RUNS immediately RSpec::Core::ExampleGroup.describe(*args, &block) end |
#exit_code ⇒ int
Return a proper exit code to the runner
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/inspec/runner_rspec.rb', line 104 def exit_code return @rspec_exit_code if @formatter.results.empty? stats = @formatter.results[:statistics][:controls] load_failures = @formatter.results[:profiles]&.select { |p| p[:status] == "failed" }&.any? skipped = @formatter.results.dig(:profiles, 0, :status) == "skipped" if stats[:failed][:total] == 0 && stats[:skipped][:total] == 0 && !skipped && !load_failures && (stats[:error] && stats[:error][:total] == 0) # placed error count condition because of enhanced outcomes 0 elsif load_failures @conf["distinct_exit"] ? 102 : 1 elsif stats[:failed][:total] > 0 || (stats[:error] && stats[:error][:total] > 0) @conf["distinct_exit"] ? 100 : 1 elsif stats[:skipped][:total] > 0 || skipped @conf["distinct_exit"] ? 101 : 0 else @rspec_exit_code end end |
#formatters ⇒ Object
31 32 33 |
# File 'lib/inspec/runner_rspec.rb', line 31 def formatters RSpec.configuration.formatters.grep(Inspec::Formatters::Base) end |
#reset ⇒ nil
Empty the list of registered tests.
126 127 128 129 130 131 |
# File 'lib/inspec/runner_rspec.rb', line 126 def reset @tests = RSpec::Core::World.new # resets "pending examples" in reporter RSpec.configuration.reset configure_output end |
#run(with = nil) ⇒ int
Run all registered tests with an optional test runner.
95 96 97 98 99 |
# File 'lib/inspec/runner_rspec.rb', line 95 def run(with = nil) with ||= RSpec::Core::Runner.new(nil) @rspec_exit_code = with.run_specs(tests) @formatter.results end |
#set_control_checks_count_map(mapping) ⇒ Object
53 54 55 56 57 |
# File 'lib/inspec/runner_rspec.rb', line 53 def set_control_checks_count_map(mapping) formatters.each do |fmt| fmt.set_control_checks_count_map(mapping) end end |
#set_controls_count(controls_count) ⇒ Object
These control count related methods are called from load logic of runner library of inspec Start of control count related methods
47 48 49 50 51 |
# File 'lib/inspec/runner_rspec.rb', line 47 def set_controls_count(controls_count) formatters.each do |fmt| fmt.set_controls_count(controls_count) end end |
#tests ⇒ Array
Retrieve the list of tests that have been added.
87 88 89 |
# File 'lib/inspec/runner_rspec.rb', line 87 def tests @tests.ordered_example_groups end |