class RSpec::Cli::CliProcess
This class spawns your process and provides some helpers to interact with the process
Constants
- TERMINAL_COLOURS
Attributes
pid[R]
Public Class Methods
new(*args)
click to toggle source
# File lib/rspec/cli/cli_process.rb, line 17 def initialize(*args) raise ArgumentError, "wrong number of arguments" if args.empty? args.unshift(*args.shift) if Array === args.first @command = args end
Public Instance Methods
alive?()
click to toggle source
# File lib/rspec/cli/cli_process.rb, line 81 def alive? begin return status.nil? rescue return false end end
flush()
click to toggle source
# File lib/rspec/cli/cli_process.rb, line 23 def flush assert_spawned @master.flush end
gets()
click to toggle source
# File lib/rspec/cli/cli_process.rb, line 34 def gets assert_spawned @master.gets end
kill!(signal = "TERM")
click to toggle source
# File lib/rspec/cli/cli_process.rb, line 91 def kill!(signal = "TERM") assert_spawned @master.close Process.kill(signal, @pid) end
puts(*args)
click to toggle source
# File lib/rspec/cli/cli_process.rb, line 39 def puts(*args) assert_spawned @master.puts args @master.flush end
read_all(*args)
click to toggle source
# File lib/rspec/cli/cli_process.rb, line 28 def read_all(*args) assert_spawned @master.flush @master.read_all *args end
run!()
click to toggle source
# File lib/rspec/cli/cli_process.rb, line 60 def run! # Create master and slave pseudo terminal devices master_tty, slave_tty = PTY.open @master = IODecorator.new master_tty @slave = slave_tty @pid = PTY.spawn(*@command, in: @slave, out: @slave, err: @slave)[2] @slave.close self end
status()
click to toggle source
# File lib/rspec/cli/cli_process.rb, line 74 def status assert_spawned PTY.check(@pid) end
stdin()
click to toggle source
# File lib/rspec/cli/cli_process.rb, line 49 def stdin @slave end
stdout()
click to toggle source
# File lib/rspec/cli/cli_process.rb, line 45 def stdout @master end
write(arg)
click to toggle source
# File lib/rspec/cli/cli_process.rb, line 53 def write(arg) # This method can block if the argument is huge assert_spawned @master.write "#{arg}\n" @master.flush end
Private Instance Methods
assert_spawned()
click to toggle source
# File lib/rspec/cli/cli_process.rb, line 101 def assert_spawned raise "process hasn't spawned yet" if @pid.nil? end