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, #last_if_empty, #prepare_input, #read_file, #read_input

Methods included from Helpers::FileHelper

#get_line, #get_lines, #n_lines, #normalize, #shortpath, #virtual_file?

Constructor Details

#initializeTestInterface

Returns a new instance of TestInterface.



10
11
12
13
14
# File 'lib/byebug/interfaces/test_interface.rb', line 10

def initialize
  super()

  clear
end

Instance Attribute Details

#test_blockObject

Returns the value of attribute test_block.



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

def test_block
  @test_block
end

Instance Method Details

#clearObject



37
38
39
40
41
42
# File 'lib/byebug/interfaces/test_interface.rb', line 37

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

#errmsg(message) ⇒ Object



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

def errmsg(message)
  error.concat(prepare(message))
end

#inspectObject



44
45
46
47
48
49
50
# File 'lib/byebug/interfaces/test_interface.rb', line 44

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


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

def print(message)
  output.concat(prepare(message))
end

#puts(message) ⇒ Object



24
25
26
# File 'lib/byebug/interfaces/test_interface.rb', line 24

def puts(message)
  output.concat(prepare(message))
end

#read_command(prompt) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/byebug/interfaces/test_interface.rb', line 28

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



52
53
54
55
56
57
# File 'lib/byebug/interfaces/test_interface.rb', line 52

def readline(prompt)
  puts(prompt)

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