Sha256: 3bc90d67ea050a7e4de5955de85b7452b60ec432582beb862d43d4d9b0ad14a4

Contents?: true

Size: 1.1 KB

Versions: 6

Compression:

Stored size: 1.1 KB

Contents

module Byebug
  #
  # Custom interface for easier assertions
  #
  class TestInterface < Interface
    attr_accessor :test_block

    def initialize
      super()
      @input = []
      @output = []
      @error = []
    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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
byebug-8.2.1 lib/byebug/interfaces/test_interface.rb
byebug-8.2.0 lib/byebug/interfaces/test_interface.rb
byebug-8.1.0 lib/byebug/interfaces/test_interface.rb
byebug-8.0.1 lib/byebug/interfaces/test_interface.rb
byebug-8.0.0 lib/byebug/interfaces/test_interface.rb
byebug-7.0.0 lib/byebug/interfaces/test_interface.rb