class Scmd::CommandSpy

Constants

InputCall
SignalCall
TimeoutCall

Attributes

cmd_str[R]
env[R]
exitstatus[RW]
kill_calls[R]
options[R]
pid[RW]
run_bang_calls[R]
run_calls[R]
start_calls[R]
stderr[RW]
stdout[RW]
stop_calls[R]
wait_calls[R]

Public Class Methods

new(cmd_str, opts = nil) click to toggle source
# File lib/scmd/command_spy.rb, line 12
def initialize(cmd_str, opts = nil)
  opts ||= {}
  @cmd_str = cmd_str
  @env     = opts[:env]
  @options = opts[:options]

  @run_calls,  @run_bang_calls, @start_calls = [], [], []
  @wait_calls, @stop_calls,     @kill_calls  = [], [], []

  @running = false

  @stdout, @stderr, @pid, @exitstatus = "", "", 1, 0
end

Public Instance Methods

==(other) click to toggle source
Calls superclass method
# File lib/scmd/command_spy.rb, line 95
def ==(other)
  if other.is_a?(CommandSpy)
    cmd_str         == other.cmd_str        &&
    env             == other.env            &&
    options         == other.options        &&
    run_calls       == other.run_calls      &&
    run_bang_calls  == other.run_bang_calls &&
    start_calls     == other.start_calls    &&
    wait_calls      == other.wait_calls     &&
    stop_calls      == other.stop_calls     &&
    kill_calls      == other.kill_calls     &&
    pid             == other.pid            &&
    exitstatus      == other.exitstatus     &&
    stdout          == other.stdout         &&
    stderr          == other.stderr
  else
    super
  end
end
kill(signal = nil) click to toggle source
# File lib/scmd/command_spy.rb, line 74
def kill(signal = nil)
  @kill_calls.push(SignalCall.new(signal))
  @running = false
end
kill_called?() click to toggle source
# File lib/scmd/command_spy.rb, line 79
def kill_called?
  !@kill_calls.empty?
end
run(input = nil) click to toggle source
# File lib/scmd/command_spy.rb, line 26
def run(input = nil)
  @run_calls.push(InputCall.new(input))
  Scmd.calls.push(Scmd::Call.new(self, input)) if ENV["SCMD_TEST_MODE"]
  self
end
run!(input = nil) click to toggle source
# File lib/scmd/command_spy.rb, line 36
def run!(input = nil)
  @run_bang_calls.push(InputCall.new(input))
  Scmd.calls.push(Scmd::Call.new(self, input)) if ENV["SCMD_TEST_MODE"]
  self
end
run_bang_called?() click to toggle source
# File lib/scmd/command_spy.rb, line 42
def run_bang_called?
  !@run_bang_calls.empty?
end
run_called?() click to toggle source
# File lib/scmd/command_spy.rb, line 32
def run_called?
  !@run_calls.empty?
end
running?() click to toggle source
# File lib/scmd/command_spy.rb, line 83
def running?
  !!@running
end
start(input = nil) click to toggle source
# File lib/scmd/command_spy.rb, line 46
def start(input = nil)
  @start_calls.push(InputCall.new(input))
  Scmd.calls.push(Scmd::Call.new(self, input)) if ENV["SCMD_TEST_MODE"]
  @running = true
end
start_called?() click to toggle source
# File lib/scmd/command_spy.rb, line 52
def start_called?
  !@start_calls.empty?
end
stop(timeout = nil) click to toggle source
# File lib/scmd/command_spy.rb, line 65
def stop(timeout = nil)
  @stop_calls.push(TimeoutCall.new(timeout))
  @running = false
end
stop_called?() click to toggle source
# File lib/scmd/command_spy.rb, line 70
def stop_called?
  !@stop_calls.empty?
end
success?() click to toggle source
# File lib/scmd/command_spy.rb, line 87
def success?
  @exitstatus == 0
end
to_s() click to toggle source
# File lib/scmd/command_spy.rb, line 91
def to_s
  @cmd_str.to_s
end
wait(timeout = nil) click to toggle source
# File lib/scmd/command_spy.rb, line 56
def wait(timeout = nil)
  @wait_calls.push(TimeoutCall.new(timeout))
  @running = false
end
wait_called?() click to toggle source
# File lib/scmd/command_spy.rb, line 61
def wait_called?
  !@wait_calls.empty?
end