diff --git a/lib/inspec/runner.rb b/lib/inspec/runner.rb index e6a1131b8..73178b6f7 100644 --- a/lib/inspec/runner.rb +++ b/lib/inspec/runner.rb @@ -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 = [] diff --git a/lib/inspec/runner_rspec.rb b/lib/inspec/runner_rspec.rb index f48b9e941..0412edd77 100644 --- a/lib/inspec/runner_rspec.rb +++ b/lib/inspec/runner_rspec.rb @@ -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 diff --git a/test/unit/runner_test.rb b/test/unit/runner_test.rb index 786a2a0aa..0bd61cd3f 100644 --- a/test/unit/runner_test.rb +++ b/test/unit/runner_test.rb @@ -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