Sha256: 55639855b35164c4486cffa46ae8765d6789cf8893bbb078358a0b6c1c69ca9f

Contents?: true

Size: 962 Bytes

Versions: 356

Compression:

Stored size: 962 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' << '--skip-completion-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

356 entries across 356 versions & 3 rubygems

Version Path
travis-1.11.1 spec/support/helpers.rb
travis-1.11.0 spec/support/helpers.rb
travis-1.10.1.travis.1341.9 spec/support/helpers.rb
travis-1.10.1.travis.1321.9 spec/support/helpers.rb
travis-1.10.1.travis.1312.9 spec/support/helpers.rb
travis-1.10.1.travis.1311.9 spec/support/helpers.rb
travis-1.10.1.travis.1305.9 spec/support/helpers.rb
travis-1.10.0 spec/support/helpers.rb
travis-1.9.2.travis.1304.9 spec/support/helpers.rb
travis-1.9.2.travis.1303.9 spec/support/helpers.rb
travis-1.10.0.pre.rc4 spec/support/helpers.rb
travis-1.10.0.pre.rc3 spec/support/helpers.rb
travis-1.10.0.pre.rc2 spec/support/helpers.rb
travis-1.9.2.travis.1288.9 spec/support/helpers.rb
travis-1.9.2.travis.1285.9 spec/support/helpers.rb
travis-1.9.2.travis.1279.9 spec/support/helpers.rb
travis-1.10.0.pre.rc1 spec/support/helpers.rb
travis-1.9.2.travis.1254.9 spec/support/helpers.rb
travis-1.9.2.travis.1236.9 spec/support/helpers.rb
travis-1.9.2.travis.1224.9 spec/support/helpers.rb