module RSpec::KnifeTestUtils

Public Class Methods

command_setting(shellout_command) click to toggle source

Convenience function for grabbing a hash of several important Mixlib::Shellout command configuration parameters.

# File lib/test/knife-utils/knife_test_utils.rb, line 32
def self.command_setting(shellout_command)
  keys = %i{cwd user group umask timeout valid_exit_codes environment}
  keys.inject({}) do |hash, attr|
    hash[attr] = shellout_command.send(attr)
    hash
  end
end
included(base) click to toggle source
# File lib/test/knife-utils/knife_test_utils.rb, line 6
def self.included(base)
  base.class_eval do
    subject { knife_run }
    let(:knife_run) { run command }
    let(:command)   { raise "Define let(:command) in the spec" }
    let(:cmd_output) { @op }
  end
end

Public Instance Methods

knife(knife_command) click to toggle source
# File lib/test/knife-utils/knife_test_utils.rb, line 26
def knife(knife_command)
  run "knife #{knife_command}"
end
run(command_line) click to toggle source

Convenience method for actually running a knife command in our testing repository. Returns the Mixlib::Shellout object ready for inspection.

# File lib/test/knife-utils/knife_test_utils.rb, line 18
def run(command_line)
  shell_out = Mixlib::ShellOut.new("#{command_line}")
  shell_out.timeout = 3000
  shell_out.tap(&:run_command)
  @op = shell_out.exitstatus == 1 ? shell_out.stderr : shell_out.stdout
  shell_out
end