Top Level Namespace
- Includes:
- ExamplePrinter
Defined Under Namespace
Modules: Color, Console, Dictable, Enumerable, ExamplePrinter, FileTest, Find, InspectWith, Kernel, MiniTest, QualityExtensions, RFC822, Test, WithKnowledgeOfColor Classes: Array, BasicObject, C, ChainableSafeNil, Date, Dict, Dir, Exception, File, Fixnum, Float, Hash, Histogram, HtmlElement, InspectWithTestCase, MatchData, Matrix, Module, Month, Mutex, NamedCapturesTest, NilClass, Numeric, NumericError, Object, Pathname, RangeList, Regexp, SafeNil, String, Symbol, Table, Time, Vector
Instance Method Summary collapse
-
#filter_stderr(filter, &block) ⇒ Object
Applies
filter
to any $stderr output thatblock
tries to generate. - #filter_stdout(filter, &block) ⇒ Object
-
#simulate_input(input_string, &block) ⇒ Object
Simulates a user typing in
input_string
on the keyboard. - #uninterruptible ⇒ Object
Methods included from ExamplePrinter
Instance Method Details
#filter_stderr(filter, &block) ⇒ Object
Applies filter
to any $stderr output that block
tries to generate.
filter
should be a Proc that accepts attempted_output
as its parameter and returns the string that should actually be output.
filter_stderr(lambda{''}) do
noisy_command
end
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/quality_extensions/kernel/filter_output.rb', line 19 def filter_stderr(filter, &block) old_stderr = $stderr $stderr = StringIO.new begin yield ensure what_they_tried_to_output = $stderr.string $stderr = old_stderr $stderr.print filter.call(what_they_tried_to_output) end end |
#filter_stdout(filter, &block) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/quality_extensions/kernel/filter_output.rb', line 30 def filter_stdout(filter, &block) old_stderr = $stdout $stdout = StringIO.new begin yield ensure what_they_tried_to_output = $stdout.string $stdout = old_stderr $stdout.print filter.call(what_they_tried_to_output) end end |
#simulate_input(input_string, &block) ⇒ Object
Simulates a user typing in input_string
on the keyboard.
Useful for testing console apps that are ordinarily (they prompt the user for input).
output = simulate_inpute('foo') do
input = $stdin.gets
capture_output { do_stuff() }
end
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/quality_extensions/kernel/simulate_input.rb', line 22 def simulate_input(input_string, &block) original_stdin = $stdin $stdin = StringIO.new(input_string, 'r') begin yield rescue Exception raise ensure $stdin = original_stdin end end |
#uninterruptible ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/quality_extensions/kernel/uninterruptable.rb', line 14 def uninterruptible orig = $uninterruptible $uninterruptible = true yield ensure $uninterruptible = orig end |