Sha256: d33506e27fca21815e42292873a771ce7d1ddaf9d8b93488b2ddca1c2a38b35c

Contents?: true

Size: 972 Bytes

Versions: 3

Compression:

Stored size: 972 Bytes

Contents

require 'stringio'
require 'rubygems/user_interaction'

##
# This Gem::StreamUI subclass records input and output to StringIO for
# retrieval during tests.

class Gem::MockGemUi < Gem::StreamUI
  class TermError < RuntimeError; end
  class SystemExitException < RuntimeError; end

  module TTY

    attr_accessor :tty

    def tty?()
      @tty = true unless defined?(@tty)
      @tty
    end

    def noecho
      yield self
    end
  end

  def initialize(input = "")
    ins = StringIO.new input
    outs = StringIO.new
    errs = StringIO.new

    ins.extend TTY
    outs.extend TTY
    errs.extend TTY

    super ins, outs, errs, true

    @terminated = false
  end

  def input
    @ins.string
  end

  def output
    @outs.string
  end

  def error
    @errs.string
  end

  def terminated?
    @terminated
  end

  def terminate_interaction(status=0)
    @terminated = true

    raise TermError unless status == 0
    raise SystemExitException, status
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rubygems-update-1.7.2 lib/rubygems/mock_gem_ui.rb
rubygems-update-1.7.1 lib/rubygems/mock_gem_ui.rb
rubygems-update-1.7.0 lib/rubygems/mock_gem_ui.rb