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.76.5 spec/backend/exec/consume_exited_process_spec.rb
specinfra-2.76.4 spec/backend/exec/consume_exited_process_spec.rb
specinfra-2.76.3 spec/backend/exec/consume_exited_process_spec.rb
specinfra-2.76.2 spec/backend/exec/consume_exited_process_spec.rb
specinfra-2.76.1 spec/backend/exec/consume_exited_process_spec.rb
specinfra-2.76.0 spec/backend/exec/consume_exited_process_spec.rb
specinfra-2.75.1 spec/backend/exec/consume_exited_process_spec.rb
specinfra-2.75.0 spec/backend/exec/consume_exited_process_spec.rb
specinfra-2.74.0 spec/backend/exec/consume_exited_process_spec.rb
specinfra-2.73.4 spec/backend/exec/consume_exited_process_spec.rb
specinfra-2.73.3 spec/backend/exec/consume_exited_process_spec.rb
specinfra-2.73.2 spec/backend/exec/consume_exited_process_spec.rb
specinfra-2.73.1 spec/backend/exec/consume_exited_process_spec.rb
specinfra-2.73.0 spec/backend/exec/consume_exited_process_spec.rb
specinfra-2.72.1 spec/backend/exec/consume_exited_process_spec.rb
specinfra-2.72.0 spec/backend/exec/consume_exited_process_spec.rb
specinfra-2.71.3 spec/backend/exec/consume_exited_process_spec.rb
specinfra-2.71.2 spec/backend/exec/consume_exited_process_spec.rb
specinfra-2.71.1 spec/backend/exec/consume_exited_process_spec.rb
specinfra-2.71.0 spec/backend/exec/consume_exited_process_spec.rb