Sha256: b906f300050c2ee9a1020f65a029db3f13c47e42dffec80e644ce5bac8e8d7be

Contents?: true

Size: 1.58 KB

Versions: 6

Compression:

Stored size: 1.58 KB

Contents

require 'serverspec'
require 'pathname'
require 'rspec/mocks/standalone'

include Serverspec::Helper::Exec
include Serverspec::Helper::DetectOS

PROJECT_ROOT = (Pathname.new(File.dirname(__FILE__)) + '..').expand_path

Dir[PROJECT_ROOT.join("spec/support/**/*.rb")].each { |file| require(file) }


module Serverspec
  module Backend
    module TestCommandRunner
      def do_run cmd
        if @example
          @example.metadata[:subject].set_command(cmd)
        end

        if cmd =~ /invalid/
          {
            :stdout      => ::Serverspec.configuration.stdout,
            :stderr      => ::Serverspec.configuration.stderr,
            :exit_status => 1,
            :exit_signal => nil
          }
        else
          {
            :stdout      => ::Serverspec.configuration.stdout,
            :stderr      => ::Serverspec.configuration.stderr,
            :exit_status => 0,
            :exit_signal => nil
          }
        end
      end
    end
    [Exec, Ssh].each do |clz|
      clz.class_eval do
        include TestCommandRunner
        def run_command(cmd)
          cmd = build_command(cmd)
          cmd = add_pre_command(cmd)
          do_run cmd
        end
      end
    end
    [Cmd, WinRM].each do |clz|
      clz.class_eval do
        include TestCommandRunner
        def run_command(cmd)
          cmd = build_command(cmd.script)
          cmd = add_pre_command(cmd)
          do_run cmd
        end
      end
    end
  end

  module Type
    class Base
      def set_command(command)
        @command = command
      end
      def command
        @command
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
serverspec-0.10.3 spec/spec_helper.rb
serverspec-0.10.2 spec/spec_helper.rb
serverspec-0.10.1 spec/spec_helper.rb
serverspec-0.10.0 spec/spec_helper.rb
serverspec-0.9.8 spec/spec_helper.rb
serverspec-0.9.7 spec/spec_helper.rb