Skip to content

Commit

Permalink
Refactor to make Rubocop happy.
Browse files Browse the repository at this point in the history
  • Loading branch information
coderanger committed Jan 14, 2016
1 parent c6cc281 commit 61ca096
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions lib/kitchen/verifier/inspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,9 @@ class Inspec < Kitchen::Verifier::Base

# (see Base#call)
def call(state)
transport_data = instance.transport.diagnose.merge(state)

runner_options = if instance.transport.is_a?(Kitchen::Transport::Ssh)
runner_options_for_ssh(transport_data)
elsif instance.transport.is_a?(Kitchen::Transport::Winrm)
runner_options_for_winrm(transport_data)
else
raise Kitchen::UserError.new("Verifier #{name} does not support the #{instance.transport.name} Transport")
end
runner_options['format'] = config[:format] unless config[:format].nil?

tests = helper_files + local_suite_files

runner = ::Inspec::Runner.new(runner_options)
runner = ::Inspec::Runner.new(runner_options(instance.transport, state))
runner.add_tests(tests)
debug("Running specs from: #{tests.inspect}")
exit_code = runner.run
Expand Down Expand Up @@ -97,6 +86,23 @@ def local_suite_files
end
end

# Returns a configuration Hash that can be passed to a `Inspec::Runner`.
#
# @return [Hash] a configuration hash of string-based keys
# @api private
def runner_options(transport, state = {})
transport_data = transport.diagnose.merge(state)
if transport.is_a?(Kitchen::Transport::Ssh)
runner_options_for_ssh(transport_data)
elsif transport.is_a?(Kitchen::Transport::Winrm)
runner_options_for_winrm(transport_data)
else
fail Kitchen::UserError.new, "Verifier #{name} does not support the #{transport.name} Transport"
end.tap do |runner_options|
runner_options['format'] = config[:format] unless config[:format].nil?
end
end

# Returns a configuration Hash that can be passed to a `Inspec::Runner`.
#
# @return [Hash] a configuration hash of string-based keys
Expand Down

0 comments on commit 61ca096

Please sign in to comment.