Sha256: 0e95ced14ebd41f729e6b3c93008915d029e7c37335c2c498a8fff9ce807b367

Contents?: true

Size: 874 Bytes

Versions: 2

Compression:

Stored size: 874 Bytes

Contents

require 'stringio'

module RSpec
  class StdErrSplitter < (defined?(::BasicObject) ? ::BasicObject : ::Object)
    def initialize
      @orig_stderr    = $stderr
      @output_tracker = ::StringIO.new
    end

    respond_to_name = (::RUBY_VERSION.to_f < 1.9) ? :respond_to? : :respond_to_missing?
    define_method respond_to_name do |*args|
      @orig_stderr.respond_to?(*args) || super
    end

    def method_missing(name, *args, &block)
      @orig_stderr.__send__(name, *args, &block)
      @output_tracker.__send__(name, *args, &block)
    end

    # To work around JRuby error:
    # TypeError: $stderr must have write method, RSpec::StdErrSplitter given
    def write(*args)
      @orig_stderr.write(*args)
      @output_tracker.write(*args)
    end

    def has_output?
      !output.empty?
    end

    def output
      @output_tracker.string
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rspec-core-3.0.0.beta2 spec/support/stderr_splitter.rb
rspec-core-3.0.0.beta1 spec/support/stderr_splitter.rb