Class: Cuprum::Cli::Dependencies::StandardIo::Mock
- Inherits:
-
Cuprum::Cli::Dependencies::StandardIo
- Object
- Cuprum::Cli::Dependencies::StandardIo
- Cuprum::Cli::Dependencies::StandardIo::Mock
- Defined in:
- lib/cuprum/cli/dependencies/standard_io/mock.rb
Overview
Mock implementation of StandardIo for testing purposes.
Instance Attribute Summary collapse
-
#combined_stream ⇒ IO
readonly
A combined input/output stream representing all IO activity.
Class Method Summary collapse
-
.append_for_read(*messages, io:) ⇒ IO
Utility method for appending readable data to a StringIO stream.
Instance Method Summary collapse
-
#error_stream ⇒ IO
The error stream.
-
#initialize(error_stream: StringIO.new, input_stream: StringIO.new, output_stream: StringIO.new) ⇒ Mock
constructor
A new instance of Mock.
-
#input_stream ⇒ IO
The input stream.
-
#output_stream ⇒ IO
The output stream.
-
#read_input ⇒ String
Requests a newline-terminated string from the input stream.
-
#write_error(message = nil, newline: true) ⇒ nil
Writes the given message to the error stream.
-
#write_output(message = nil, newline: true) ⇒ nil
Writes the given message to the output stream.
Methods inherited from Cuprum::Cli::Dependencies::StandardIo
Constructor Details
#initialize(error_stream: StringIO.new, input_stream: StringIO.new, output_stream: StringIO.new) ⇒ Mock
Returns a new instance of Mock.
40 41 42 43 44 45 46 47 48 |
# File 'lib/cuprum/cli/dependencies/standard_io/mock.rb', line 40 def initialize( error_stream: StringIO.new, input_stream: StringIO.new, output_stream: StringIO.new ) super @combined_stream = StringIO.new end |
Instance Attribute Details
#combined_stream ⇒ IO (readonly)
Returns a combined input/output stream representing all IO activity.
51 52 53 |
# File 'lib/cuprum/cli/dependencies/standard_io/mock.rb', line 51 def combined_stream @combined_stream end |
Class Method Details
.append_for_read(*messages, io:) ⇒ IO
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/cuprum/cli/dependencies/standard_io/mock.rb', line 18 def self.append_for_read(*, io:) total_length = 0 .each do || += "\n" unless .end_with?("\n") io.print() total_length += .length end io.pos -= total_length io end |
Instance Method Details
#error_stream ⇒ IO
Returns the error stream.
54 |
# File 'lib/cuprum/cli/dependencies/standard_io/mock.rb', line 54 def error_stream = super # rubocop:disable Lint/UselessMethodDefinition |
#input_stream ⇒ IO
Returns the input stream.
57 |
# File 'lib/cuprum/cli/dependencies/standard_io/mock.rb', line 57 def input_stream = super # rubocop:disable Lint/UselessMethodDefinition |
#output_stream ⇒ IO
Returns the output stream.
60 |
# File 'lib/cuprum/cli/dependencies/standard_io/mock.rb', line 60 def output_stream = super # rubocop:disable Lint/UselessMethodDefinition |
#read_input ⇒ String
Requests a newline-terminated string from the input stream.
63 64 65 66 67 68 69 |
# File 'lib/cuprum/cli/dependencies/standard_io/mock.rb', line 63 def read_input = super combined_stream.print() if end |
#write_error(message = nil, newline: true) ⇒ nil
Writes the given message to the error stream.
If no error message is given, prints a newline only.
79 80 81 82 83 |
# File 'lib/cuprum/cli/dependencies/standard_io/mock.rb', line 79 def write_error( = nil, newline: true) super newline ? combined_stream.puts() : combined_stream.print() end |
#write_output(message = nil, newline: true) ⇒ nil
Writes the given message to the output stream.
If no message is given, prints a newline only.
72 73 74 75 76 |
# File 'lib/cuprum/cli/dependencies/standard_io/mock.rb', line 72 def write_output( = nil, newline: true) super newline ? combined_stream.puts() : combined_stream.print() end |