Sha256: 5d032b140cf5662ae1d64bd58a0c77d8189f4b7c99d66ad4897545c42a0373b4

Contents?: true

Size: 898 Bytes

Versions: 9

Compression:

Stored size: 898 Bytes

Contents

require 'spec_helper'
require 'stringio'
require 'ostruct'

module Helpers
  attr_reader :last_run

  def capture
    _stdout, $stdout = $stdout, StringIO.new
    _stderr, $stderr = $stderr, StringIO.new
    _stdin,  $stdin  = $stdin,  StringIO.new
    yield
    capture_result(true)
  rescue SystemExit => e
    capture_result(e.success?)
  ensure
    $stdout = _stdout if _stdout
    $stderr = _stderr if _stderr
    $stdin  = _stdin  if _stdin
  end

  def run_cli(*args)
    args << ENV['TRAVIS_OPTS'] if ENV['TRAVIS_OPTS']
    capture do
      yield $stdin if block_given?
      $stdin.rewind
      Travis::CLI.run(*args)
    end
  end

  def stderr
    last_run.err if last_run
  end

  def stdout
    last_run.out if last_run
  end

  private

    def capture_result(success)
      @last_run = OpenStruct.new(:out => $stdout.string, :err => $stderr.string, :success? => success)
    end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
travis-1.2.8 spec/support/helpers.rb
travis-1.2.7 spec/support/helpers.rb
travis-1.2.6 spec/support/helpers.rb
travis-1.2.5 spec/support/helpers.rb
travis-1.2.4 spec/support/helpers.rb
travis-1.2.3 spec/support/helpers.rb
travis-1.2.2 spec/support/helpers.rb
travis-1.2.1 spec/support/helpers.rb
travis-1.2.0 spec/support/helpers.rb