mirror of
https://github.com/inspec/inspec
synced 2024-11-27 07:00:39 +00:00
Allow ad-hoc runners to use rspec formats. (#2621)
Signed-off-by: Jared Quick <jquick@chef.io>
This commit is contained in:
parent
56387c96d0
commit
f5f9873bfd
3 changed files with 18 additions and 9 deletions
|
@ -42,14 +42,16 @@ module Inspec
|
|||
@ignore_supports = @conf[:ignore_supports]
|
||||
@create_lockfile = @conf[:create_lockfile]
|
||||
@cache = Inspec::Cache.new(@conf[:vendor_cache])
|
||||
|
||||
# parse any ad-hoc runners reporter formats
|
||||
# this has to happen before we load the test_collector
|
||||
@conf = Inspec::BaseCLI.parse_reporters(@conf) if @conf[:type].nil?
|
||||
|
||||
@test_collector = @conf.delete(:test_collector) || begin
|
||||
require 'inspec/runner_rspec'
|
||||
RunnerRspec.new(@conf)
|
||||
end
|
||||
|
||||
# parse any ad-hoc runners reporter formats
|
||||
@conf = Inspec::BaseCLI.parse_reporters(@conf) if @conf[:type].nil?
|
||||
|
||||
# list of profile attributes
|
||||
@attributes = []
|
||||
|
||||
|
|
|
@ -94,18 +94,18 @@ module Inspec
|
|||
#
|
||||
#
|
||||
def set_optional_formatters
|
||||
return if @conf[:reporter].nil?
|
||||
if @conf[:reporter].key?('json-rspec')
|
||||
return if @conf['reporter'].nil?
|
||||
if @conf['reporter'].key?('json-rspec')
|
||||
# We cannot pass in a nil output path. Rspec only accepts a valid string or a IO object.
|
||||
if @conf[:reporter]['json-rspec']&.[]('file').nil?
|
||||
if @conf['reporter']['json-rspec']&.[]('file').nil?
|
||||
RSpec.configuration.add_formatter(Inspec::Formatters::RspecJson)
|
||||
else
|
||||
RSpec.configuration.add_formatter(Inspec::Formatters::RspecJson, @conf[:reporter]['json-rspec']['file'])
|
||||
end
|
||||
@conf[:reporter].delete('json-rspec')
|
||||
@conf['reporter'].delete('json-rspec')
|
||||
end
|
||||
|
||||
formats = @conf[:reporter].select { |k, _v| %w{documentation progress html}.include?(k) }
|
||||
formats = @conf['reporter'].select { |k, _v| %w{documentation progress html}.include?(k) }
|
||||
formats.each do |k, v|
|
||||
# We cannot pass in a nil output path. Rspec only accepts a valid string or a IO object.
|
||||
if v&.[]('file').nil?
|
||||
|
@ -113,7 +113,7 @@ module Inspec
|
|||
else
|
||||
RSpec.configuration.add_formatter(k.to_sym, v['file'])
|
||||
end
|
||||
@conf[:reporter].delete(k)
|
||||
@conf['reporter'].delete(k)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -27,6 +27,13 @@ describe Inspec::Runner do
|
|||
expected = { 'json' => { 'stdout' => true } }
|
||||
config['reporter'].must_equal expected
|
||||
end
|
||||
|
||||
it 'delets format if set to a rspec format' do
|
||||
opts = { command_runner: :generic, backend_cache: true, 'format' => 'progress' }
|
||||
runner = Inspec::Runner.new(opts)
|
||||
config = runner.instance_variable_get(:"@conf")
|
||||
config['reporter'].must_equal Hash.new
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when backend caching is enabled' do
|
||||
|
|
Loading…
Reference in a new issue