Class: Scmd::CommandSpy
- Inherits:
-
Object
- Object
- Scmd::CommandSpy
- Defined in:
- lib/scmd/command_spy.rb
Defined Under Namespace
Classes: InputCall, SignalCall, TimeoutCall
Instance Attribute Summary collapse
-
#cmd_str ⇒ Object
readonly
Returns the value of attribute cmd_str.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#exitstatus ⇒ Object
Returns the value of attribute exitstatus.
-
#kill_calls ⇒ Object
readonly
Returns the value of attribute kill_calls.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#pid ⇒ Object
Returns the value of attribute pid.
-
#run_bang_calls ⇒ Object
readonly
Returns the value of attribute run_bang_calls.
-
#run_calls ⇒ Object
readonly
Returns the value of attribute run_calls.
-
#start_calls ⇒ Object
readonly
Returns the value of attribute start_calls.
-
#stderr ⇒ Object
Returns the value of attribute stderr.
-
#stdout ⇒ Object
Returns the value of attribute stdout.
-
#stop_calls ⇒ Object
readonly
Returns the value of attribute stop_calls.
-
#wait_calls ⇒ Object
readonly
Returns the value of attribute wait_calls.
Instance Method Summary collapse
- #==(other_spy) ⇒ Object
-
#initialize(cmd_str, opts = nil) ⇒ CommandSpy
constructor
A new instance of CommandSpy.
- #kill(signal = nil) ⇒ Object
- #kill_called? ⇒ Boolean
- #run(input = nil) ⇒ Object
- #run!(input = nil) ⇒ Object
- #run_bang_called? ⇒ Boolean
- #run_called? ⇒ Boolean
- #running? ⇒ Boolean
- #start(input = nil) ⇒ Object
- #start_called? ⇒ Boolean
- #stop(timeout = nil) ⇒ Object
- #stop_called? ⇒ Boolean
- #success? ⇒ Boolean
- #to_s ⇒ Object
- #wait(timeout = nil) ⇒ Object
- #wait_called? ⇒ Boolean
Constructor Details
#initialize(cmd_str, opts = nil) ⇒ CommandSpy
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# 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 |
Instance Attribute Details
#cmd_str ⇒ Object (readonly)
Returns the value of attribute cmd_str.
7 8 9 |
# File 'lib/scmd/command_spy.rb', line 7 def cmd_str @cmd_str end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
7 8 9 |
# File 'lib/scmd/command_spy.rb', line 7 def env @env end |
#exitstatus ⇒ Object
Returns the value of attribute exitstatus.
10 11 12 |
# File 'lib/scmd/command_spy.rb', line 10 def exitstatus @exitstatus end |
#kill_calls ⇒ Object (readonly)
Returns the value of attribute kill_calls.
9 10 11 |
# File 'lib/scmd/command_spy.rb', line 9 def kill_calls @kill_calls end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/scmd/command_spy.rb', line 7 def @options end |
#pid ⇒ Object
Returns the value of attribute pid.
10 11 12 |
# File 'lib/scmd/command_spy.rb', line 10 def pid @pid end |
#run_bang_calls ⇒ Object (readonly)
Returns the value of attribute run_bang_calls.
8 9 10 |
# File 'lib/scmd/command_spy.rb', line 8 def run_bang_calls @run_bang_calls end |
#run_calls ⇒ Object (readonly)
Returns the value of attribute run_calls.
8 9 10 |
# File 'lib/scmd/command_spy.rb', line 8 def run_calls @run_calls end |
#start_calls ⇒ Object (readonly)
Returns the value of attribute start_calls.
8 9 10 |
# File 'lib/scmd/command_spy.rb', line 8 def start_calls @start_calls end |
#stderr ⇒ Object
Returns the value of attribute stderr.
10 11 12 |
# File 'lib/scmd/command_spy.rb', line 10 def stderr @stderr end |
#stdout ⇒ Object
Returns the value of attribute stdout.
10 11 12 |
# File 'lib/scmd/command_spy.rb', line 10 def stdout @stdout end |
#stop_calls ⇒ Object (readonly)
Returns the value of attribute stop_calls.
9 10 11 |
# File 'lib/scmd/command_spy.rb', line 9 def stop_calls @stop_calls end |
#wait_calls ⇒ Object (readonly)
Returns the value of attribute wait_calls.
9 10 11 |
# File 'lib/scmd/command_spy.rb', line 9 def wait_calls @wait_calls end |
Instance Method Details
#==(other_spy) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/scmd/command_spy.rb', line 95 def ==(other_spy) if other_spy.kind_of?(CommandSpy) self.cmd_str == other_spy.cmd_str && self.env == other_spy.env && self. == other_spy. && self.run_calls == other_spy.run_calls && self.run_bang_calls == other_spy.run_bang_calls && self.start_calls == other_spy.start_calls && self.wait_calls == other_spy.wait_calls && self.stop_calls == other_spy.stop_calls && self.kill_calls == other_spy.kill_calls && self.pid == other_spy.pid && self.exitstatus == other_spy.exitstatus && self.stdout == other_spy.stdout && self.stderr == other_spy.stderr else super end end |
#kill(signal = nil) ⇒ Object
74 75 76 77 |
# File 'lib/scmd/command_spy.rb', line 74 def kill(signal = nil) @kill_calls.push(SignalCall.new(signal)) @running = false end |
#kill_called? ⇒ Boolean
79 80 81 |
# File 'lib/scmd/command_spy.rb', line 79 def kill_called? !@kill_calls.empty? end |
#run(input = nil) ⇒ Object
26 27 28 29 30 |
# 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) ⇒ Object
36 37 38 39 40 |
# 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? ⇒ Boolean
42 43 44 |
# File 'lib/scmd/command_spy.rb', line 42 def run_bang_called? !@run_bang_calls.empty? end |
#run_called? ⇒ Boolean
32 33 34 |
# File 'lib/scmd/command_spy.rb', line 32 def run_called? !@run_calls.empty? end |
#running? ⇒ Boolean
83 84 85 |
# File 'lib/scmd/command_spy.rb', line 83 def running? !!@running end |
#start(input = nil) ⇒ Object
46 47 48 49 50 |
# 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? ⇒ Boolean
52 53 54 |
# File 'lib/scmd/command_spy.rb', line 52 def start_called? !@start_calls.empty? end |
#stop(timeout = nil) ⇒ Object
65 66 67 68 |
# File 'lib/scmd/command_spy.rb', line 65 def stop(timeout = nil) @stop_calls.push(TimeoutCall.new(timeout)) @running = false end |
#stop_called? ⇒ Boolean
70 71 72 |
# File 'lib/scmd/command_spy.rb', line 70 def stop_called? !@stop_calls.empty? end |
#success? ⇒ Boolean
87 88 89 |
# File 'lib/scmd/command_spy.rb', line 87 def success? @exitstatus == 0 end |
#to_s ⇒ Object
91 92 93 |
# File 'lib/scmd/command_spy.rb', line 91 def to_s @cmd_str.to_s end |
#wait(timeout = nil) ⇒ Object
56 57 58 59 |
# File 'lib/scmd/command_spy.rb', line 56 def wait(timeout = nil) @wait_calls.push(TimeoutCall.new(timeout)) @running = false end |
#wait_called? ⇒ Boolean
61 62 63 |
# File 'lib/scmd/command_spy.rb', line 61 def wait_called? !@wait_calls.empty? end |