Class: HighLine::Test::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/highline/test/client.rb

Constant Summary collapse

DEFAULT_POST_INPUT_DELAY =
0.1

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeClient

Returns a new instance of Client.



10
11
12
13
# File 'lib/highline/test/client.rb', line 10

def initialize
  @delay = DEFAULT_POST_INPUT_DELAY
  setup
end

Instance Attribute Details

#child_pidObject

Returns the value of attribute child_pid.



8
9
10
# File 'lib/highline/test/client.rb', line 8

def child_pid
  @child_pid
end

#delayObject

The delay in milliseconds that the client waits after sending text via the #type method



7
8
9
# File 'lib/highline/test/client.rb', line 7

def delay
  @delay
end

Instance Method Details

#cleanupObject



32
33
34
35
36
37
38
# File 'lib/highline/test/client.rb', line 32

def cleanup
  return unless running?

  kill_child_process
  close_pipes
  setup
end

#outputObject



51
52
53
54
55
# File 'lib/highline/test/client.rb', line 51

def output
  return @output if @output
  @output_write.close unless @output_write.closed?
  @output = @output_read.readpartial(PIPE_BUFFER_SIZE)
end

#runObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/highline/test/client.rb', line 15

def run
  raise "Supply a block to provide a context in which the application is run" unless block_given?

  create_pipes

  @child_pid = fork

  if child_pid.nil?
    partial_reader = PartialReader.new(@input_read)
    driver = Driver.new(partial_reader, @output_write)
    yield driver

    # if the subject ever returns, kill the child process
    Process.kill(:KILL, Process.pid)
  end
end

#running?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/highline/test/client.rb', line 40

def running?
  not child_pid.nil?
end

#type(text) ⇒ Object



44
45
46
47
48
49
# File 'lib/highline/test/client.rb', line 44

def type(text)
  raise 'Client is not running' unless running?

  @input_write << "#{text}\n"
  sleep delay
end