123456789_123456789_123456789_123456789_123456789_

Class: Gem::MockGemUi

Relationships & Source Files
Namespace Children
Modules:
TTY
Exceptions:
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
self, StreamUI
Inherits: Gem::StreamUI
Defined in: lib/rubygems/mock_gem_ui.rb

Overview

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

Class Method Summary

StreamUI - Inherited

.new

Creates a new StreamUI wrapping in_stream for user input, out_stream for standard output, err_stream for error output.

Deprecate - Extended

deprecate

Simple deprecation method that deprecates name by wrapping it up in a dummy method.

rubygems_deprecate

Simple deprecation method that deprecates name by wrapping it up in a dummy method.

rubygems_deprecate_command

Deprecation method to deprecate Rubygems commands.

skip_during

Temporarily turn off warnings.

Instance Attribute Summary

StreamUI - Inherited

#errs

The error stream.

#ins

The input stream.

#outs

The output stream.

#tty?

Returns true if TTY methods should be used on this StreamUI.

Instance Method Summary

StreamUI - Inherited

#_gets_noecho,
#alert

Display an informational alert.

#alert_error

Display an error message in a location expected to get error messages.

#alert_warning

Display a warning on stderr.

#ask

Ask a question.

#ask_for_password

Ask for a password.

#ask_yes_no

Ask a question.

#backtrace

Prints a formatted backtrace to the errors stream if backtraces are enabled.

#choose_from_list

Choose from a list of options.

#close,
#download_reporter

Return a download reporter object chosen from the current verbosity.

#progress_reporter

Return a progress reporter object chosen from the current verbosity.

#require_io_console,
#say

Display a statement.

#terminate_interaction

Terminate the application with exit code status, running any exit handlers that might have been defined.

Constructor Details

.new(input = "") ⇒ MockGemUi

[ GitHub ]

  
# File 'lib/rubygems/mock_gem_ui.rb', line 43

def initialize(input = "")
  require "stringio"
  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

Instance Attribute Details

#terminated?Boolean (readonly)

[ GitHub ]

  
# File 'lib/rubygems/mock_gem_ui.rb', line 76

def terminated?
  @terminated
end

Instance Method Details

#ask(question)

Raises:

[ GitHub ]

  
# File 'lib/rubygems/mock_gem_ui.rb', line 58

def ask(question)
  raise InputEOFError, question if @ins.eof?

  super
end

#error

[ GitHub ]

  
# File 'lib/rubygems/mock_gem_ui.rb', line 72

def error
  @errs.string
end

#input

[ GitHub ]

  
# File 'lib/rubygems/mock_gem_ui.rb', line 64

def input
  @ins.string
end

#output

[ GitHub ]

  
# File 'lib/rubygems/mock_gem_ui.rb', line 68

def output
  @outs.string
end

#terminate_interaction(status = 0)

Raises:

[ GitHub ]

  
# File 'lib/rubygems/mock_gem_ui.rb', line 80

def terminate_interaction(status=0)
  @terminated = true

  raise TermError, status if status != 0
  raise SystemExitException
end