Sha256: c0282f68c498e03ff04c791a3f2a22ea8e0a95c28b72c92b4ba34c4f55dbe3b2

Contents?: true

Size: 1.13 KB

Versions: 1

Compression:

Stored size: 1.13 KB

Contents

module Byebug
  #
  # Custom interface for easier assertions
  #
  class TestInterface < Interface
    attr_reader :input_queue, :output_queue, :error_queue, :confirm_queue

    attr_accessor :test_block

    def initialize
      super()
      @input_queue, @output_queue = [], []
      @error_queue, @confirm_queue = [], []
    end

    def errmsg(*args)
      @error_queue.push(*args)
    end

    def read_command(*)
      return readline(true) unless @input_queue.empty?

      return unless test_block

      test_block.call
      self.test_block = nil
    end

    def puts(*args)
      @output_queue.push(*args)
    end

    def confirm(message)
      @confirm_queue << message
      readline(false)
    end

    def close
    end

    def inspect
      [
        "input_queue: #{input_queue.inspect}",
        "output_queue: #{output_queue.inspect}",
        "error_queue: #{error_queue.inspect}",
        "confirm_queue: #{confirm_queue.inspect}"
      ].join("\n")
    end

    private

    def readline(hist)
      cmd = @input_queue.shift
      cmd = cmd.is_a?(Proc) ? cmd.call : cmd
      save_history(cmd) if hist
      cmd
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
byebug-3.5.1 test/support/test_interface.rb