Sha256: e91142f8536593c9aa4571915ac519127f82ea75397bb00b0bf4562fd8e19bda

Contents?: true

Size: 1.38 KB

Versions: 2

Compression:

Stored size: 1.38 KB

Contents

require File.dirname(__FILE__) + '/spec_helper'

describe DarkIO do
  it 'should return an array of size 2 when capturing both stdout and stderr' do
    out = DarkIO::capture_output(:stderr => true, :stdout => true) do
      STDOUT.print('Hello, World!')
      STDERR.print('Hello, World!')
    end
    out.should be_a_kind_of(Array)
    out.size.should == 2
  end

  it 'should return a string when capturing either stdout or stderr' do
    out = DarkIO::capture_output(:stderr => true, :stdout => false) do
      STDERR.print('Hello, World!')
    end
    out.should be_a_kind_of(String)
    out = DarkIO::capture_output(:stdout => true, :stderr => false) do
      STDOUT.print('Hello, World!')
    end
    out.should be_a_kind_of(String)
  end

  it 'should return nil if not capturing anything' do
    DarkIO::capture_output(:stderr => false, :stdout => false) do
      STDOUT.print('Hello, World!')
      STDERR.print('Hello, World!')
    end.nil?.should be_true
  end

  it 'should capture output' do
    HW = 'Hello, World!'
    out = DarkIO::capture_output { HW.print }
    out.should == HW
    out = DarkIO::capture_output(:stderr => true) do
      (HW + 'STDOUT').print
      STDERR.print(HW + 'STDERR')
    end
    out.shift.should == HW + 'STDOUT'
    out.shift.should == HW + 'STDERR'
    out = DarkIO::capture_output(:stderr => true, :stdout => false) { STDERR.print(HW) }
    out.should == HW
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
darkhelmet-darkext-0.12.0 spec/io_spec.rb
darkext-0.12.0 spec/io_spec.rb