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.



8
9
10
11
12
13
# 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



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

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

#errmsg(message) ⇒ Object



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

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

#inspectObject



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

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


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

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

#puts(message) ⇒ Object



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

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

#read_command(prompt) ⇒ Object



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

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



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

def readline(prompt)
  puts(prompt)

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