Class: Inspec::RunnerRspec
- Inherits:
-
Object
- Object
- Inspec::RunnerRspec
- Defined in:
- lib/inspec/runner_rspec.rb
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=(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.
-
#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.
-
#tests ⇒ Array
Retrieve the list of tests that have been added.
Constructor Details
#initialize(conf) ⇒ RunnerRspec
Returns a new instance of RunnerRspec.
13 14 15 16 17 |
# File 'lib/inspec/runner_rspec.rb', line 13 def initialize(conf) @conf = conf @formatter = nil reset end |
Instance Method Details
#add_profile(profile) ⇒ nil
Add a full profile to the runner. Only pulls in metadata
32 33 34 35 36 37 38 |
# File 'lib/inspec/runner_rspec.rb', line 32 def add_profile(profile) RSpec.configuration.formatters .find_all { |c| c.is_a?(Inspec::Formatters::Base) } .each do |fmt| fmt.add_profile(profile) end end |
#add_test(example, rule) ⇒ nil
Add an example group to the list of registered tests.
57 58 59 60 |
# File 'lib/inspec/runner_rspec.rb', line 57 def add_test(example, rule) set_rspec_ids(example, rule) @tests.example_groups.push(example) end |
#backend=(backend) ⇒ nil
Configure the backend of the runner.
44 45 46 47 48 49 50 |
# File 'lib/inspec/runner_rspec.rb', line 44 def backend=(backend) RSpec.configuration.formatters .find_all { |c| c.is_a?(Inspec::Formatters::Base) } .each do |fmt| fmt.backend = backend end end |
#example_group(*args, &block) ⇒ RSpecExampleGroup
Create a new RSpec example group from arguments and block.
24 25 26 |
# File 'lib/inspec/runner_rspec.rb', line 24 def example_group(*args, &block) RSpec::Core::ExampleGroup.describe(*args, &block) end |
#exit_code ⇒ int
Return a proper exit code to the runner
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/inspec/runner_rspec.rb', line 82 def exit_code return @rspec_exit_code if @formatter.results.empty? stats = @formatter.results[:statistics][:controls] skipped = @formatter.results.dig(:profiles, 0, :status) == "skipped" if stats[:failed][:total] == 0 && stats[:skipped][:total] == 0 && !skipped 0 elsif stats[:failed][:total] > 0 @conf["distinct_exit"] ? 100 : 1 elsif stats[:skipped][:total] > 0 || skipped @conf["distinct_exit"] ? 101 : 0 else @rspec_exit_code end end |
#reset ⇒ nil
Empty the list of registered tests.
101 102 103 104 105 106 |
# File 'lib/inspec/runner_rspec.rb', line 101 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.
73 74 75 76 77 |
# File 'lib/inspec/runner_rspec.rb', line 73 def run(with = nil) with ||= RSpec::Core::Runner.new(nil) @rspec_exit_code = with.run_specs(tests) @formatter.results end |
#tests ⇒ Array
Retrieve the list of tests that have been added.
65 66 67 |
# File 'lib/inspec/runner_rspec.rb', line 65 def tests @tests.ordered_example_groups end |