mirror of
https://github.com/inspec/inspec
synced 2025-02-18 15:08:44 +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/targets'
|
||||||
require 'inspec/metadata'
|
require 'inspec/metadata'
|
||||||
# spec requirements
|
# spec requirements
|
||||||
require 'rspec'
|
|
||||||
require 'rspec/its'
|
|
||||||
require 'inspec/rspec_json_formatter'
|
|
||||||
|
|
||||||
module Inspec
|
module Inspec
|
||||||
class Runner # rubocop:disable Metrics/ClassLength
|
class Runner # rubocop:disable Metrics/ClassLength
|
||||||
|
@ -22,12 +19,12 @@ module Inspec
|
||||||
@profile_id = conf[:id]
|
@profile_id = conf[:id]
|
||||||
@conf = conf.dup
|
@conf = conf.dup
|
||||||
@conf[:logger] ||= Logger.new(nil)
|
@conf[:logger] ||= Logger.new(nil)
|
||||||
@tests = RSpec::Core::World.new
|
|
||||||
|
|
||||||
# resets "pending examples" in reporter
|
@test_collector = @conf.delete(:test_collector) || begin
|
||||||
RSpec.configuration.reset
|
require 'inspec/runner_rspec'
|
||||||
|
RunnerRspec.new(@conf)
|
||||||
|
end
|
||||||
|
|
||||||
configure_output
|
|
||||||
configure_transport
|
configure_transport
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -39,10 +36,6 @@ module Inspec
|
||||||
res
|
res
|
||||||
end
|
end
|
||||||
|
|
||||||
def configure_output
|
|
||||||
RSpec.configuration.add_formatter(@conf['format'] || 'progress')
|
|
||||||
end
|
|
||||||
|
|
||||||
def configure_transport
|
def configure_transport
|
||||||
@backend = Inspec::Backend.create(@conf)
|
@backend = Inspec::Backend.create(@conf)
|
||||||
end
|
end
|
||||||
|
@ -109,12 +102,8 @@ module Inspec
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def run
|
def run(with = nil)
|
||||||
run_with(RSpec::Core::Runner.new(nil))
|
@test_collector.run(with)
|
||||||
end
|
|
||||||
|
|
||||||
def run_with(rspec_runner)
|
|
||||||
rspec_runner.run_specs(@tests.ordered_example_groups)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -164,19 +153,9 @@ module Inspec
|
||||||
dsl = ctx.method(:create_inner_dsl).call(backend)
|
dsl = ctx.method(:create_inner_dsl).call(backend)
|
||||||
example.send(:include, dsl)
|
example.send(:include, dsl)
|
||||||
|
|
||||||
set_rspec_ids(example, rule_id)
|
@test_collector.add_test(example, rule_id)
|
||||||
@tests.register(example)
|
|
||||||
end
|
end
|
||||||
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
|
||||||
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
|
# author: Dominik Richter
|
||||||
|
|
||||||
require 'helper'
|
require 'helper'
|
||||||
|
require 'inspec/profile_context'
|
||||||
|
require 'inspec/runner'
|
||||||
|
|
||||||
describe Inspec::Profile do
|
describe Inspec::Profile do
|
||||||
before {
|
before {
|
||||||
|
|
Loading…
Add table
Reference in a new issue