Class: Serverspec::Backend::WinRM

Inherits:
Base
  • Object
show all
Includes:
PowerShell::ScriptHelper
Defined in:
lib/serverspec/backend/winrm.rb

Instance Method Summary collapse

Methods included from PowerShell::ScriptHelper

#add_pre_command, #build_command, #create_script, #encode_script

Methods inherited from Base

#check_zero, #commands, #method_missing, #set_commands, #set_example

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Serverspec::Backend::Base

Instance Method Details

#run_command(cmd, opts = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/serverspec/backend/winrm.rb', line 6

def run_command(cmd, opts={})
  script = create_script(cmd)
  winrm = RSpec.configuration.winrm

  result = winrm.powershell(script)
  stdout, stderr = [:stdout, :stderr].map do |s|
    result[:data].select {|item| item.key? s}.map {|item| item[s]}.join
  end
  result[:exitcode] = 1 if result[:exitcode] == 0 and !stderr.empty?

  if @example
    @example.[:command] = script
    @example.[:stdout]  = stdout + stderr
  end

  { :stdout => stdout, :stderr => stderr,
    :exit_status => result[:exitcode], :exit_signal => nil }
end