Sha256: 9adef07d0cb3f47eede550b3ac312f2e298e07e43e7c316f7876cdb3d4865730

Contents?: true

Size: 1.06 KB

Versions: 17

Compression:

Stored size: 1.06 KB

Contents

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

Version data entries

17 entries across 16 versions & 3 rubygems

Version Path
dirwatch-0.0.2 vendor/bundle/ruby/2.3.0/gems/byebug-9.1.0/lib/byebug/interfaces/test_interface.rb
tdiary-5.0.6 vendor/bundle/gems/byebug-9.1.0/lib/byebug/interfaces/test_interface.rb
byebug-9.1.0 lib/byebug/interfaces/test_interface.rb
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/byebug-9.0.6/lib/byebug/interfaces/test_interface.rb
tdiary-5.0.5 vendor/bundle/gems/byebug-9.0.6/lib/byebug/interfaces/test_interface.rb
tdiary-5.0.4 vendor/bundle/gems/byebug-9.0.6/lib/byebug/interfaces/test_interface.rb
byebug-9.0.6 lib/byebug/interfaces/test_interface.rb
byebug-9.0.5 lib/byebug/interfaces/test_interface.rb
byebug-9.0.4 lib/byebug/interfaces/test_interface.rb
byebug-9.0.3 lib/byebug/interfaces/test_interface.rb
byebug-9.0.2 lib/byebug/interfaces/test_interface.rb
byebug-9.0.1 lib/byebug/interfaces/test_interface.rb
byebug-9.0.0 lib/byebug/interfaces/test_interface.rb
byebug-8.2.5 lib/byebug/interfaces/test_interface.rb
byebug-8.2.4 lib/byebug/interfaces/test_interface.rb
byebug-8.2.3 lib/byebug/interfaces/test_interface.rb
byebug-8.2.2 lib/byebug/interfaces/test_interface.rb