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_backspace ⇒ Object
- #send_keys(text_to_send) ⇒ Object
- #send_return ⇒ Object
- #send_right_arrow ⇒ Object
- #send_up_arrow ⇒ 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
90 91 92 |
# File 'lib/blue-shell/runner.rb', line 90 def debug @expector.debug end |
#debug=(x) ⇒ Object
94 95 96 |
# File 'lib/blue-shell/runner.rb', line 94 def debug=(x) @expector.debug = x end |
#exit_code(timeout = 5) ⇒ Object Also known as: wait_for_exit
55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/blue-shell/runner.rb', line 55 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
72 73 74 |
# File 'lib/blue-shell/runner.rb', line 72 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
86 87 88 |
# File 'lib/blue-shell/runner.rb', line 86 def output @expector.output end |
#running? ⇒ Boolean
82 83 84 |
# File 'lib/blue-shell/runner.rb', line 82 def running? !!Process.getpgid(@pid) end |
#send_backspace ⇒ Object
43 44 45 |
# File 'lib/blue-shell/runner.rb', line 43 def send_backspace @stdin.print("\b \b") end |
#send_keys(text_to_send) ⇒ Object
47 48 49 |
# File 'lib/blue-shell/runner.rb', line 47 def send_keys(text_to_send) @stdin.puts(text_to_send) end |
#send_return ⇒ Object
51 52 53 |
# File 'lib/blue-shell/runner.rb', line 51 def send_return @stdin.puts end |
#send_right_arrow ⇒ Object
39 40 41 |
# File 'lib/blue-shell/runner.rb', line 39 def send_right_arrow @stdin.print("\e[C") end |
#send_up_arrow ⇒ Object
35 36 37 |
# File 'lib/blue-shell/runner.rb', line 35 def send_up_arrow @stdin.print("\e[A") end |
#success? ⇒ Boolean Also known as: successful?
76 77 78 |
# File 'lib/blue-shell/runner.rb', line 76 def success? @code.zero? end |