Sha256: 42a14315cea8dd30b740e72bd8165d6642c42e94203778d026b595b873ad04bb

Contents?: true

Size: 933 Bytes

Versions: 36

Compression:

Stored size: 933 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']
    args << '--skip-version-check'
    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

36 entries across 36 versions & 1 rubygems

Version Path
travis-1.5.7.travis.345.4 spec/support/helpers.rb
travis-1.5.7.travis.341.4 spec/support/helpers.rb
travis-1.5.7.travis.338.4 spec/support/helpers.rb
travis-1.5.6 spec/support/helpers.rb
travis-1.5.6.travis.337.4 spec/support/helpers.rb
travis-1.5.6.travis.336.4 spec/support/helpers.rb
travis-1.5.6.travis.333.4 spec/support/helpers.rb
travis-1.5.6.travis.332.4 spec/support/helpers.rb
travis-1.5.6.travis.330.4 spec/support/helpers.rb
travis-1.5.6.travis.329.4 spec/support/helpers.rb
travis-1.5.6.travis.326.4 spec/support/helpers.rb
travis-1.5.6.travis.324.4 spec/support/helpers.rb
travis-1.5.6.travis.323.4 spec/support/helpers.rb
travis-1.5.6.travis.320.4 spec/support/helpers.rb
travis-1.5.6.travis.319.4 spec/support/helpers.rb
travis-1.5.6.travis.317.4 spec/support/helpers.rb
travis-1.5.6.travis.315.4 spec/support/helpers.rb
travis-1.5.6.travis.314.4 spec/support/helpers.rb
travis-1.5.6.travis.312.4 spec/support/helpers.rb
travis-1.5.6.travis.307.4 spec/support/helpers.rb