Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extracted shared examples for StdinProcessAdapter
- Loading branch information
Showing
3 changed files
with
57 additions
and
50 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
spec/remote_ruby/connection_adapter/local_stdin_adapter_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
shared_context 'STDIN adapter' do | ||
describe '#open' do | ||
let(:code) { '1 + 1' } | ||
let(:output_content) { 'output' } | ||
let(:error_content) { 'error' } | ||
let(:fake_stdin) { StringIO.new } | ||
let(:wait_thr) { double(:wait_thr, value: value) } | ||
let(:value) { double(:value, success?: success?, to_s: exit_code.to_s) } | ||
let(:success?) { true } | ||
let(:exit_code) { 0 } | ||
|
||
before(:example) do | ||
allow(adapter).to receive(:popen3).and_yield( | ||
fake_stdin, | ||
StringIO.new(output_content), | ||
StringIO.new(error_content), | ||
wait_thr | ||
) | ||
end | ||
|
||
it 'writes code to stdin' do | ||
adapter.open(code) {} | ||
expect(fake_stdin.string).to eq(code) | ||
end | ||
|
||
it 'yields streams' do | ||
adapter.open(code) do |stdout, stderr| | ||
expect(stdout.read).to eq(output_content) | ||
expect(stderr.read).to eq(error_content) | ||
end | ||
end | ||
|
||
it 'calls external command' do | ||
allow(adapter).to receive(:command).and_return('echo') | ||
expect(adapter).to receive(:popen3).with('echo') | ||
adapter.open(code) {} | ||
end | ||
|
||
context 'when process fails' do | ||
let(:success?) { false } | ||
let(:exit_code) { 127 } | ||
|
||
it 'raises error' do | ||
expect do | ||
adapter.open(code) {} | ||
end.to raise_error(RuntimeError, Regexp.new(value.to_s)) | ||
end | ||
end | ||
end | ||
end |