Sha256: 36c4260c980d1a4c96839ba430d9026cd5d1211ec5df94bc75a1995610fdd049

Contents?: true

Size: 923 Bytes

Versions: 3

Compression:

Stored size: 923 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

  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

    @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 Gem::SystemExitException, status
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rubygems-update-1.5.3 lib/rubygems/mock_gem_ui.rb
rubygems-update-1.5.2 lib/rubygems/mock_gem_ui.rb
rubygems-update-1.5.0 lib/rubygems/mock_gem_ui.rb