PageRenderTime 310ms CodeModel.GetById 302ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/tools/Ruby/lib/ruby/site_ruby/1.8/rubygems/mock_gem_ui.rb

http://github.com/agross/netopenspace
Ruby | 64 lines | 43 code | 18 blank | 3 comment | 1 complexity | 858ce5be55b8d66ce98f122e85bef1d2 MD5 | raw file
 1require 'stringio'
 2require 'rubygems/user_interaction'
 3
 4##
 5# This Gem::StreamUI subclass records input and output to StringIO for
 6# retrieval during tests.
 7
 8class Gem::MockGemUi < Gem::StreamUI
 9  class TermError < RuntimeError; end
10  class SystemExitException < RuntimeError; end
11
12  module TTY
13
14    attr_accessor :tty
15
16    def tty?()
17      @tty = true unless defined?(@tty)
18      @tty
19    end
20
21    def noecho
22      yield self
23    end
24  end
25
26  def initialize(input = "")
27    ins = StringIO.new input
28    outs = StringIO.new
29    errs = StringIO.new
30
31    ins.extend TTY
32    outs.extend TTY
33    errs.extend TTY
34
35    super ins, outs, errs, true
36
37    @terminated = false
38  end
39
40  def input
41    @ins.string
42  end
43
44  def output
45    @outs.string
46  end
47
48  def error
49    @errs.string
50  end
51
52  def terminated?
53    @terminated
54  end
55
56  def terminate_interaction(status=0)
57    @terminated = true
58
59    raise TermError unless status == 0
60    raise SystemExitException, status
61  end
62
63end
64