Skip to content

Commit

Permalink
Add specs for xProcess#write
Browse files Browse the repository at this point in the history
  • Loading branch information
mvz committed Jan 15, 2022
1 parent 2781e97 commit 239c163
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
28 changes: 28 additions & 0 deletions spec/aruba/processes/in_process_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ def execute!
end
end

let(:stdin_runner) do
Class.new(base_runner) do
def execute!
@stdin.rewind
item = @stdin.gets.to_s.chomp
@stdout.puts "Hello, #{item}!"
end
end
end

let(:failed_runner) do
Class.new(base_runner) do
def execute!
Expand Down Expand Up @@ -141,4 +151,22 @@ def run_process(&block)
.to raise_error(TypeError, "no implicit conversion of String into Integer")
end
end

describe '#write' do
let(:main_class) { stdin_runner }

it 'writes single strings to the process' do
process.write "World"
process.start
process.stop
expect(process.stdout).to eq "Hello, World!\n"
end

it 'writes multiple strings to the process' do
process.write "Wor", "ld"
process.start
process.stop
expect(process.stdout).to eq "Hello, World!\n"
end
end
end
20 changes: 20 additions & 0 deletions spec/aruba/processes/spawn_process_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,26 @@
end
end

describe '#write' do
let(:command_line) { "ruby -e 'puts gets'" }

it 'writes single strings to the process' do
process.start
process.write "hello\n"
process.stop

expect(process.stdout).to eq "hello\n"
end

it 'writes multiple strings to the process' do
process.start
process.write "hel", "lo\n"
process.stop

expect(process.stdout).to eq "hello\n"
end
end

describe "#stop" do
before { process.start }

Expand Down

0 comments on commit 239c163

Please sign in to comment.