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 ⇒ Object (also: #wait_for_exit)
- #exited? ⇒ Boolean
- #expect(matcher) ⇒ 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?)
- #with_timeout(timeout, &block) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Runner
Returns a new instance of Runner.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/blue-shell/runner.rb', line 10 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
94 95 96 |
# File 'lib/blue-shell/runner.rb', line 94 def debug @expector.debug end |
#debug=(x) ⇒ Object
98 99 100 |
# File 'lib/blue-shell/runner.rb', line 98 def debug=(x) @expector.debug = x end |
#exit_code ⇒ Object Also known as: wait_for_exit
59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/blue-shell/runner.rb', line 59 def exit_code return @code if @code code = nil begin Timeout.timeout(BlueShell.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
76 77 78 |
# File 'lib/blue-shell/runner.rb', line 76 def exited? !running? end |
#expect(matcher) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/blue-shell/runner.rb', line 30 def expect(matcher) case matcher when Hash expect_branches(matcher) else @expector.expect(matcher) end end |
#output ⇒ Object
90 91 92 |
# File 'lib/blue-shell/runner.rb', line 90 def output @expector.output end |
#running? ⇒ Boolean
86 87 88 |
# File 'lib/blue-shell/runner.rb', line 86 def running? !!Process.getpgid(@pid) end |
#send_backspace ⇒ Object
47 48 49 |
# File 'lib/blue-shell/runner.rb', line 47 def send_backspace @stdin.print("\b \b") end |
#send_keys(text_to_send) ⇒ Object
51 52 53 |
# File 'lib/blue-shell/runner.rb', line 51 def send_keys(text_to_send) @stdin.puts(text_to_send) end |
#send_return ⇒ Object
55 56 57 |
# File 'lib/blue-shell/runner.rb', line 55 def send_return @stdin.puts end |
#send_right_arrow ⇒ Object
43 44 45 |
# File 'lib/blue-shell/runner.rb', line 43 def send_right_arrow @stdin.print("\e[C") end |
#send_up_arrow ⇒ Object
39 40 41 |
# File 'lib/blue-shell/runner.rb', line 39 def send_up_arrow @stdin.print("\e[A") end |
#success? ⇒ Boolean Also known as: successful?
80 81 82 |
# File 'lib/blue-shell/runner.rb', line 80 def success? @code.zero? end |
#with_timeout(timeout, &block) ⇒ Object
26 27 28 |
# File 'lib/blue-shell/runner.rb', line 26 def with_timeout(timeout, &block) BlueShell.with_timeout(timeout, &block) end |