Sha256: 702d517738ef5944324af5475eb6798ab3f8798ed82eeacfba31fccbb9ca69eb

Contents?: true

Size: 1.41 KB

Versions: 129

Compression:

Stored size: 1.41 KB

Contents

require 'spec_helper'

RSpec.describe 'exec backend' do
  before :all do
    set :backend, :exec
  end

  context 'when executed process had exited before read stdout and stderr,' do
    let(:backend) { Specinfra::Backend::Exec.new }

    it 'can consume stdout and stderr from buffer' do
      allow(IO).to receive(:select).and_wrap_original { |m, *args| sleep 1; m.call(*args) }
      result = backend.run_command("ruby -e 'STDOUT.puts \"stdout\"; STDERR.puts \"stderr\"'")
      expect(result.stdout.chomp).to eq('stdout')
      expect(result.stderr.chomp).to eq('stderr')
    end
  end

  context 'when executed process has exited between reading stdout and stderr,' do
    let(:backend) { Specinfra::Backend::Exec.new }

    it 'can consume stdout and stderr from buffer' do
      backend.stdout_handler = proc { |o| sleep 1 }
      result = backend.run_command("ruby -e 'STDOUT.puts \"stdout\"; STDOUT.close; STDERR.puts \"stderr\"'")
      expect(result.stdout.chomp).to eq('stdout')
      expect(result.stderr.chomp).to eq('stderr')
    end
  end

  context 'Output of stderr_handler' do
    let(:backend) { Specinfra::Backend::Exec.new }
    subject(:stderr) do
      allow(IO).to receive(:select).and_wrap_original { |m, *args| sleep 1; m.call(*args) }
      err = ''
      backend.stderr_handler = proc { |e| err += e }
      backend.run_command('echo foo 1>&2')
      err
    end

    it { expect(stderr).to eq "foo\n" }
  end
end

Version data entries

129 entries across 129 versions & 1 rubygems

Version Path
specinfra-2.82.25 spec/backend/exec/consume_exited_process_spec.rb
specinfra-2.82.24 spec/backend/exec/consume_exited_process_spec.rb
specinfra-2.82.23 spec/backend/exec/consume_exited_process_spec.rb
specinfra-2.82.22 spec/backend/exec/consume_exited_process_spec.rb
specinfra-2.82.21 spec/backend/exec/consume_exited_process_spec.rb
specinfra-2.82.20 spec/backend/exec/consume_exited_process_spec.rb
specinfra-2.82.19 spec/backend/exec/consume_exited_process_spec.rb
specinfra-2.82.18 spec/backend/exec/consume_exited_process_spec.rb
specinfra-2.82.17 spec/backend/exec/consume_exited_process_spec.rb
specinfra-2.82.16 spec/backend/exec/consume_exited_process_spec.rb
specinfra-2.82.15 spec/backend/exec/consume_exited_process_spec.rb
specinfra-2.82.14 spec/backend/exec/consume_exited_process_spec.rb
specinfra-2.82.13 spec/backend/exec/consume_exited_process_spec.rb
specinfra-2.82.12 spec/backend/exec/consume_exited_process_spec.rb
specinfra-2.82.11 spec/backend/exec/consume_exited_process_spec.rb
specinfra-2.82.10 spec/backend/exec/consume_exited_process_spec.rb
specinfra-2.82.9 spec/backend/exec/consume_exited_process_spec.rb
specinfra-2.82.8 spec/backend/exec/consume_exited_process_spec.rb
specinfra-2.82.7 spec/backend/exec/consume_exited_process_spec.rb
specinfra-2.82.6 spec/backend/exec/consume_exited_process_spec.rb