Class: BlueShell::Runner
- Inherits:
-
Object
- Object
- BlueShell::Runner
- Defined in:
- lib/blue-shell/runner.rb
Instance Method Summary collapse
- #debug ⇒ Object
- #debug=(x) ⇒ Object
- #exit_code(timeout = 5) ⇒ Object (also: #wait_for_exit)
- #exited? ⇒ Boolean
- #expect(matcher, timeout = 30) ⇒ Object
-
#initialize(*args) ⇒ Runner
constructor
A new instance of Runner.
- #output ⇒ Object
- #running? ⇒ Boolean
- #send_keys(text_to_send) ⇒ Object
- #send_return ⇒ Object
- #success? ⇒ Boolean (also: #successful?)
Constructor Details
#initialize(*args) ⇒ Runner
Returns a new instance of Runner.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/blue-shell/runner.rb', line 6 def initialize(*args) @stdout, slave = PTY.open system('stty raw', :in => slave) read, @stdin = IO.pipe @pid = spawn(*(args.push(:in => read, :out => slave, :err => slave))) @expector = BufferedReaderExpector.new(@stdout, ENV['DEBUG_BACON']) if block_given? yield self else wait_for_exit() end end |
Instance Method Details
#debug ⇒ Object
78 79 80 |
# File 'lib/blue-shell/runner.rb', line 78 def debug @expector.debug end |
#debug=(x) ⇒ Object
82 83 84 |
# File 'lib/blue-shell/runner.rb', line 82 def debug=(x) @expector.debug = x end |
#exit_code(timeout = 5) ⇒ Object Also known as: wait_for_exit
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/blue-shell/runner.rb', line 43 def exit_code(timeout = 5) return @code if @code code = nil begin Timeout.timeout(timeout) do _, code = Process.waitpid2(@pid) end rescue Timeout::Error raise ::Timeout::Error.new("execution expired, output was:\n#{@expector.read_to_end}") end @code = numeric_exit_code(code) end |
#exited? ⇒ Boolean
60 61 62 |
# File 'lib/blue-shell/runner.rb', line 60 def exited? !running? end |
#expect(matcher, timeout = 30) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/blue-shell/runner.rb', line 26 def expect(matcher, timeout = 30) case matcher when Hash expect_branches(matcher, timeout) else @expector.expect(matcher, timeout) end end |
#output ⇒ Object
74 75 76 |
# File 'lib/blue-shell/runner.rb', line 74 def output @expector.output end |
#running? ⇒ Boolean
70 71 72 |
# File 'lib/blue-shell/runner.rb', line 70 def running? !!Process.getpgid(@pid) end |
#send_keys(text_to_send) ⇒ Object
35 36 37 |
# File 'lib/blue-shell/runner.rb', line 35 def send_keys(text_to_send) @stdin.puts(text_to_send) end |
#send_return ⇒ Object
39 40 41 |
# File 'lib/blue-shell/runner.rb', line 39 def send_return @stdin.puts end |
#success? ⇒ Boolean Also known as: successful?
64 65 66 |
# File 'lib/blue-shell/runner.rb', line 64 def success? @code.zero? end |