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.
-
#initialize(conf) ⇒ RunnerRspec
constructor
A new instance of RunnerRspec.
-
#report ⇒ Hash
Provide an output hash of the run’s report.
-
#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.
15 16 17 18 19 20 |
# File 'lib/inspec/runner_rspec.rb', line 15 def initialize(conf) @conf = conf @formatter = nil reset_tests configure_output end |
Instance Method Details
#add_profile(profile) ⇒ nil
Add a full profile to the runner. Only pulls in metadata
35 36 37 38 39 40 41 |
# File 'lib/inspec/runner_rspec.rb', line 35 def add_profile(profile) RSpec.configuration.formatters .find_all { |c| c.is_a? InspecRspecJson } .each do |fmt| fmt.add_profile(profile) end end |
#add_test(example, rule) ⇒ nil
Add an example group to the list of registered tests.
60 61 62 63 |
# File 'lib/inspec/runner_rspec.rb', line 60 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.
47 48 49 50 51 52 53 |
# File 'lib/inspec/runner_rspec.rb', line 47 def backend=(backend) RSpec.configuration.formatters .find_all { |c| c.is_a? InspecRspecJson } .each do |fmt| fmt.backend = backend end end |
#example_group(*args, &block) ⇒ RSpecExampleGroup
Create a new RSpec example group from arguments and block.
27 28 29 |
# File 'lib/inspec/runner_rspec.rb', line 27 def example_group(*args, &block) RSpec::Core::ExampleGroup.describe(*args, &block) end |
#report ⇒ Hash
Provide an output hash of the run’s report
84 85 86 87 88 |
# File 'lib/inspec/runner_rspec.rb', line 84 def report reporter = @formatter || RSpec.configuration.formatters[0] return nil if reporter.nil? || !reporter.respond_to?(:output_hash) reporter.output_hash end |
#run(with = nil) ⇒ int
Run all registered tests with an optional test runner.
76 77 78 79 |
# File 'lib/inspec/runner_rspec.rb', line 76 def run(with = nil) with ||= RSpec::Core::Runner.new(nil) with.run_specs(tests) end |
#tests ⇒ Array
Retrieve the list of tests that have been added.
68 69 70 |
# File 'lib/inspec/runner_rspec.rb', line 68 def tests @tests.ordered_example_groups end |