mirror of
https://github.com/inspec/inspec
synced 2024-11-27 07:00:39 +00:00
completely separate rspec runner parts
This commit is contained in:
parent
21a92a0c4e
commit
dd2d93fd6f
3 changed files with 61 additions and 28 deletions
|
@ -10,9 +10,6 @@ require 'inspec/profile_context'
|
|||
require 'inspec/targets'
|
||||
require 'inspec/metadata'
|
||||
# spec requirements
|
||||
require 'rspec'
|
||||
require 'rspec/its'
|
||||
require 'inspec/rspec_json_formatter'
|
||||
|
||||
module Inspec
|
||||
class Runner # rubocop:disable Metrics/ClassLength
|
||||
|
@ -22,12 +19,12 @@ module Inspec
|
|||
@profile_id = conf[:id]
|
||||
@conf = conf.dup
|
||||
@conf[:logger] ||= Logger.new(nil)
|
||||
@tests = RSpec::Core::World.new
|
||||
|
||||
# resets "pending examples" in reporter
|
||||
RSpec.configuration.reset
|
||||
@test_collector = @conf.delete(:test_collector) || begin
|
||||
require 'inspec/runner_rspec'
|
||||
RunnerRspec.new(@conf)
|
||||
end
|
||||
|
||||
configure_output
|
||||
configure_transport
|
||||
end
|
||||
|
||||
|
@ -39,10 +36,6 @@ module Inspec
|
|||
res
|
||||
end
|
||||
|
||||
def configure_output
|
||||
RSpec.configuration.add_formatter(@conf['format'] || 'progress')
|
||||
end
|
||||
|
||||
def configure_transport
|
||||
@backend = Inspec::Backend.create(@conf)
|
||||
end
|
||||
|
@ -109,12 +102,8 @@ module Inspec
|
|||
end
|
||||
end
|
||||
|
||||
def run
|
||||
run_with(RSpec::Core::Runner.new(nil))
|
||||
end
|
||||
|
||||
def run_with(rspec_runner)
|
||||
rspec_runner.run_specs(@tests.ordered_example_groups)
|
||||
def run(with = nil)
|
||||
@test_collector.run(with)
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -164,19 +153,9 @@ module Inspec
|
|||
dsl = ctx.method(:create_inner_dsl).call(backend)
|
||||
example.send(:include, dsl)
|
||||
|
||||
set_rspec_ids(example, rule_id)
|
||||
@tests.register(example)
|
||||
@test_collector.add_test(example, rule_id)
|
||||
end
|
||||
end
|
||||
|
||||
def set_rspec_ids(example, id)
|
||||
example.metadata[:id] = id
|
||||
example.filtered_examples.each do |e|
|
||||
e.metadata[:id] = id
|
||||
end
|
||||
example.children.each do |child|
|
||||
set_rspec_ids(child, id)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
52
lib/inspec/runner_rspec.rb
Normal file
52
lib/inspec/runner_rspec.rb
Normal file
|
@ -0,0 +1,52 @@
|
|||
# encoding: utf-8
|
||||
# author: Dominik Richter
|
||||
# author: Christoph Hartmann
|
||||
|
||||
require 'rspec/core'
|
||||
require 'rspec/its'
|
||||
require 'inspec/rspec_json_formatter'
|
||||
|
||||
module Inspec
|
||||
class RunnerRspec
|
||||
def initialize
|
||||
reset_tests
|
||||
configure_output
|
||||
end
|
||||
|
||||
def reset_tests
|
||||
@tests = RSpec::Core::World.new
|
||||
# resets "pending examples" in reporter
|
||||
RSpec.configuration.reset
|
||||
end
|
||||
|
||||
def configure_output
|
||||
RSpec.configuration.add_formatter(@conf['format'] || 'progress')
|
||||
end
|
||||
|
||||
def add_test(example, rule_id)
|
||||
set_rspec_ids(example, rule_id)
|
||||
@tests.register(example)
|
||||
end
|
||||
|
||||
def tests
|
||||
@tests.ordered_example_groups
|
||||
end
|
||||
|
||||
def run(with = nil)
|
||||
with ||= RSpec::Core::Runner.new(nil)
|
||||
with.run_specs(@test_collector.tests)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_rspec_ids(example, id)
|
||||
example.metadata[:id] = id
|
||||
example.filtered_examples.each do |e|
|
||||
e.metadata[:id] = id
|
||||
end
|
||||
example.children.each do |child|
|
||||
set_rspec_ids(child, id)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -3,6 +3,8 @@
|
|||
# author: Dominik Richter
|
||||
|
||||
require 'helper'
|
||||
require 'inspec/profile_context'
|
||||
require 'inspec/runner'
|
||||
|
||||
describe Inspec::Profile do
|
||||
before {
|
||||
|
|
Loading…
Reference in a new issue