1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
# frozen_string_literal: true
module Byebug
#
# Custom interface for easier assertions
#
class TestInterface < Interface
attr_accessor :test_block
def initialize
super()
clear
end
def errmsg(message)
error.concat(prepare(message))
end
def print(message)
output.concat(prepare(message))
end
def puts(message)
output.concat(prepare(message))
end
def read_command(prompt)
cmd = super(prompt)
return cmd unless cmd.nil? && test_block
test_block.call
self.test_block = nil
end
def clear
@input = []
@output = []
@error = []
history.clear
end
def inspect
[
"Input:", input.join("\n"),
"Output:", output.join("\n"),
"Error:", error.join("\n")
].join("\n")
end
def readline(prompt)
puts(prompt)
cmd = input.shift
cmd.is_a?(Proc) ? cmd.call : cmd
end
private
def prepare(message)
return message.map(&:to_s) if message.respond_to?(:map)
message.to_s.split("\n")
end
end
end
|