Sha256: a361ed7c796092e874526e702753573304648e7b3959f5ce57750da663f1e01c

Contents?: true

Size: 1.24 KB

Versions: 18

Compression:

Stored size: 1.24 KB

Contents

require 'open3'

module SpecInfra
  module Backend
    class Cmd < Base
      include PowerShell::ScriptHelper

      def run_command(cmd, opts={})
        script = create_script(cmd)
        result = execute_script %Q{powershell -encodedCommand #{encode_script(script)}}

        if @example
          @example.metadata[:command] = script
          @example.metadata[:stdout]  = result[:stdout] + result[:stderr]
        end
        CommandResult.new :stdout => result[:stdout], :stderr => result[:stderr],
          :exit_status => result[:status]
      end

      def execute_script script
        if Open3.respond_to? :capture3
          stdout, stderr, status = Open3.capture3(script)
          # powershell still exits with 0 even if there are syntax errors, although it spits the error out into stderr
          # so we have to resort to return an error exit code if there is anything in the standard error
          status = 1 if status == 0 and !stderr.empty?
          { :stdout => stdout, :stderr => stderr, :status => status }
        else
          stdout = `#{script} 2>&1`
          { :stdout => stdout, :stderr => nil, :status => $? }
        end
      end

      def check_os
        # Dirty hack for specs
        'Windows'
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
specinfra-1.0.0 lib/specinfra/backend/cmd.rb
specinfra-0.8.0 lib/specinfra/backend/cmd.rb
specinfra-0.7.3 lib/specinfra/backend/cmd.rb
specinfra-0.7.2 lib/specinfra/backend/cmd.rb
specinfra-0.7.1 lib/specinfra/backend/cmd.rb
specinfra-0.7.0 lib/specinfra/backend/cmd.rb
specinfra-0.6.1 lib/specinfra/backend/cmd.rb
specinfra-0.6.0 lib/specinfra/backend/cmd.rb
specinfra-0.5.9 lib/specinfra/backend/cmd.rb
specinfra-0.5.8 lib/specinfra/backend/cmd.rb
specinfra-0.5.7 lib/specinfra/backend/cmd.rb
specinfra-0.5.6 lib/specinfra/backend/cmd.rb
specinfra-0.5.5 lib/specinfra/backend/cmd.rb
specinfra-0.5.4 lib/specinfra/backend/cmd.rb
specinfra-0.5.3 lib/specinfra/backend/cmd.rb
specinfra-0.5.2 lib/specinfra/backend/cmd.rb
specinfra-0.5.1 lib/specinfra/backend/cmd.rb
specinfra-0.5.0 lib/specinfra/backend/cmd.rb