Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/spec/acceptance/child_process_spec.rb
Views: 11766
require 'acceptance_spec_helper'12RSpec.describe Acceptance::ChildProcess do3context 'when a process is opened successfully' do4let(:stdin_pipes) { ::IO.pipe }5let(:stdin_reader) { stdin_pipes[0] }6let(:stdin_writer) { stdin_pipes[1] }7let(:stdout_and_stderr_pipes) { ::IO.pipe }8let(:stdout_and_stderr_pipes_reader) { stdout_and_stderr_pipes[0] }9let(:stdout_and_stderr_pipes_writer) { stdout_and_stderr_pipes[1] }10let(:wait_thread) { double(:wait_thread, alive?: true, pid: nil) }1112subject(:mock_process) do13clazz = Class.new(described_class) do14attr_reader :mock_stdin_reader15attr_reader :mock_stdout_and_stderr_writer1617def run(stdin, stdout_and_stderr, wait_thread)18self.stdin = stdin19self.stdout_and_stderr = stdout_and_stderr20self.stdin.sync = true21self.stdout_and_stderr.sync = true22self.wait_thread = wait_thread23end24end25clazz.new26end2728def mock_write(data)29stdout_and_stderr_pipes_writer.write(data)30end3132before(:each) do33mock_process.run(stdin_writer, stdout_and_stderr_pipes_reader, wait_thread)34end3536after(:each) do37subject.close38end3940describe '#readline' do41context 'when there is exactly one line available' do42it 'reads one line' do43mock_write("hello world\n")44expect(subject.readline).to eq("hello world\n")45end46end4748context 'when there are multiple lines available' do49it 'reads one line' do50mock_write("hello world\nfoo bar\n")51expect(subject.readline).to eq("hello world\n")52end5354it 'reads multiple lines' do55mock_write("hello world\nfoo bar\n")56expect(subject.readline).to eq("hello world\n")57expect(subject.readline).to eq("foo bar\n")58end59end60end6162describe '#recv_available' do63context 'when there is exactly one line available' do64it 'reads one line' do65mock_write("hello world\n")66expect(subject.recv_available).to eq("hello world\n")67end68end6970context 'when there are multiple lines available' do71it 'reads one line' do72mock_write("hello world\nfoo bar\n")73expect(subject.recv_available).to eq("hello world\nfoo bar\n")74end75end76end7778describe '#recvuntil' do79context 'when there are multiple lines of data available' do80it 'reads one line' do81mock_write <<~EOF82motd83login:84EOF85expect(subject.recvuntil("login:")).to eq("motd\nlogin:")86end87end88end8990describe '#sendline' do91it 'writes the available data' do92subject.sendline("hello world")9394expect(stdin_reader.read_nonblock(1024)).to eq("hello world\n")95end96end9798describe '#alive?' do99it 'returns the wait thread status' do100expect(subject.alive?).to eq(wait_thread.alive?)101end102end103end104end105106107