Class: Gem::MockGemUi

Inherits:
StreamUI show all
Defined in:
lib/rubygems/mock_gem_ui.rb

Overview

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

Defined Under Namespace

Modules: TTY Classes: InputEOFError, SystemExitException, TermError

Instance Attribute Summary

Attributes inherited from StreamUI

#errs, #ins, #outs

Instance Method Summary collapse

Methods inherited from StreamUI

#_gets_noecho, #alert, #alert_error, #alert_warning, #ask_for_password, #ask_yes_no, #backtrace, #choose_from_list, #close, #debug, #download_reporter, #progress_reporter, #require_io_console, #say, #tty?

Methods included from Deprecate

deprecate, skip, skip=, skip_during

Constructor Details

#initialize(input = "") ⇒ MockGemUi

Returns a new instance of MockGemUi.



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/rubygems/mock_gem_ui.rb', line 45

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

Instance Method Details

#ask(question) ⇒ Object

Raises:



59
60
61
62
63
# File 'lib/rubygems/mock_gem_ui.rb', line 59

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

  super
end

#errorObject



73
74
75
# File 'lib/rubygems/mock_gem_ui.rb', line 73

def error
  @errs.string
end

#inputObject



65
66
67
# File 'lib/rubygems/mock_gem_ui.rb', line 65

def input
  @ins.string
end

#outputObject



69
70
71
# File 'lib/rubygems/mock_gem_ui.rb', line 69

def output
  @outs.string
end

#terminate_interaction(status = 0) ⇒ Object

Raises:



81
82
83
84
85
86
# File 'lib/rubygems/mock_gem_ui.rb', line 81

def terminate_interaction(status=0)
  @terminated = true

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

#terminated?Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/rubygems/mock_gem_ui.rb', line 77

def terminated?
  @terminated
end