Class: MarkdownExec::TestHashDelegatorHandleStream

Inherits:
Minitest::Test
  • Object
show all
Defined in:
lib/hash_delegator.rb

Overview

require ‘stringio’

Instance Method Summary collapse

Instance Method Details

#setupObject



6977
6978
6979
6980
6981
# File 'lib/hash_delegator.rb', line 6977

def setup
  @hd = HashDelegator.new(output_stdout: true)
  @hd.instance_variable_set(:@run_state,
                            OpenStruct.new(files: StreamsOut.new))
end

#test_handle_streamObject



6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
# File 'lib/hash_delegator.rb', line 6983

def test_handle_stream
  stream = StringIO.new("line 1\nline 2\n")
  file_type = ExecutionStreams::STD_OUT

  Thread.new { @hd.handle_stream(stream: stream, file_type: file_type) }

  @hd.wait_for_stream_processing
  assert_equal ["line 1\n", "line 2\n"],
               @hd.instance_variable_get(:@run_state)
                  .files.stream_lines(ExecutionStreams::STD_OUT)
end

#test_handle_stream_with_io_errorObject



6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
# File 'lib/hash_delegator.rb', line 6995

def test_handle_stream_with_io_error
  stream = StringIO.new("line 1\nline 2\n")
  file_type = ExecutionStreams::STD_OUT
  stream.stubs(:each_line).raises(IOError)

  Thread.new { @hd.handle_stream(stream: stream, file_type: file_type) }

  @hd.wait_for_stream_processing

  assert_equal [],
               @hd.instance_variable_get(:@run_state)
                  .files.stream_lines(ExecutionStreams::STD_OUT)
end