Class: Byebug::TestInterface

Inherits:
Interface show all
Defined in:
lib/byebug/interfaces/test_interface.rb

Overview

Custom interface for easier assertions

Instance Attribute Summary collapse

Attributes inherited from Interface

#command_queue, #error, #history, #input, #output

Instance Method Summary collapse

Methods inherited from Interface

#autorestore, #autosave, #close, #confirm, #read_file, #read_input

Methods included from FileFunctions

#get_line, #get_lines, #n_lines, #normalize

Constructor Details

#initializeTestInterface

Returns a new instance of TestInterface.



8
9
10
11
# File 'lib/byebug/interfaces/test_interface.rb', line 8

def initialize
  super()
  @input, @output, @error = [], [], []
end

Instance Attribute Details

#test_blockObject

Returns the value of attribute test_block.



6
7
8
# File 'lib/byebug/interfaces/test_interface.rb', line 6

def test_block
  @test_block
end

Instance Method Details

#clearObject



34
35
36
37
# File 'lib/byebug/interfaces/test_interface.rb', line 34

def clear
  @input, @output, @error = [], [], []
  history.clear
end

#errmsg(message) ⇒ Object



13
14
15
# File 'lib/byebug/interfaces/test_interface.rb', line 13

def errmsg(message)
  error.concat(message.to_s.split("\n"))
end

#inspectObject



39
40
41
42
43
44
45
# File 'lib/byebug/interfaces/test_interface.rb', line 39

def inspect
  [
    'Input:', input.join("\n"),
    'Output:', output.join("\n"),
    'Error:', error.join("\n")
  ].join("\n")
end


17
18
19
# File 'lib/byebug/interfaces/test_interface.rb', line 17

def print(message)
  output.concat(message.to_s.split("\n"))
end

#puts(message) ⇒ Object



21
22
23
# File 'lib/byebug/interfaces/test_interface.rb', line 21

def puts(message)
  output.concat(message.to_s.split("\n"))
end

#read_command(prompt) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/byebug/interfaces/test_interface.rb', line 25

def read_command(prompt)
  cmd = super(prompt)

  return cmd unless cmd.nil? && test_block

  test_block.call
  self.test_block = nil
end

#readline(prompt) ⇒ Object



47
48
49
50
51
52
# File 'lib/byebug/interfaces/test_interface.rb', line 47

def readline(prompt)
  puts(prompt)

  cmd = input.shift
  cmd.is_a?(Proc) ? cmd.call : cmd
end