Module: RSpec::KnifeTestUtils

Included in:
KnifeTestHelper
Defined in:
lib/test/knife-utils/knife_test_utils.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.command_setting(shellout_command) ⇒ Object

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



32
33
34
35
36
37
38
# 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) ⇒ Object



6
7
8
9
10
11
12
13
# 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

Instance Method Details

#knife(knife_command) ⇒ Object



26
27
28
# File 'lib/test/knife-utils/knife_test_utils.rb', line 26

def knife(knife_command)
  run "knife #{knife_command}"
end

#run(command_line) ⇒ Object

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



18
19
20
21
22
23
24
# 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