Sha256: 943f2680678091bb175203f87be6877be9187adc65fb01ee7f66d602b3d4ddc5

Contents?: true

Size: 1.64 KB

Versions: 3

Compression:

Stored size: 1.64 KB

Contents

require_relative 'spec_helper'

RSpec.describe 'output handling' do
  attr_reader :clazz

  before do
    @clazz = Clazz.new
  end

  it 'captures stdout only' do
    expect do
      clazz.process(
        'echo stdout > /dev/stdout && echo stderr > /dev/null',
        puts_output: :always)
    end.to output("stdout\n").to_stdout
        .and(not_output.to_stderr)
  end

  it 'captures stderr only' do
    expect do
      clazz.process(
        'echo stdout > /dev/null && echo stderr > /dev/stderr',
        puts_output: :always)
    end.to output("stderr\n").to_stdout
        .and(not_output.to_stderr)
  end

  it 'captures stdout and stderr' do
    expect do
      clazz.process(
        'echo stdout > /dev/stdout && echo stderr > /dev/stderr',
        puts_output: :always)
    end.to output("stdout\nstderr\n").to_stdout
        .and(not_output.to_stderr)
  end

  describe 'when :puts_output == :never' do
    describe 'when include_output_in_exception is false' do
      it 'show warning' do
        expect do
          clazz.process(
            'echo stdout > /dev/stdout',
            puts_output: :never,
            include_output_in_exception: false)
        end.to output(/all error output will be suppressed if process fails/).to_stderr
            .and(not_output.to_stdout)
      end
    end

    describe 'when include_output_in_exception == true' do
      it 'do not show warning' do
        expect do
          clazz.process(
            'echo stdout > /dev/stdout',
            puts_output: :never)
        end.to output(/unless process fails with an exit code other than \[0\]/).to_stderr
            .and(not_output.to_stdout)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
process_helper-0.0.3 spec/output_handling_spec.rb
process_helper-0.0.2 spec/output_handling_spec.rb
process_helper-0.0.1 spec/output_handling_spec.rb