Sha256: d1bd5b3d52bd48d773a9c878da6548dce84b5e850b0c85a59d76282cfc59cfa8

Contents?: true

Size: 1.21 KB

Versions: 6

Compression:

Stored size: 1.21 KB

Contents

require 'stringio'

module RSpec
  module Support
    class StdErrSplitter
      def initialize(original)
        @orig_stderr    = original
        @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)
        @output_tracker.__send__(name, *args, &block)
        @orig_stderr.__send__(name, *args, &block)
      end

      def ==(other)
        @orig_stderr == other
      end

      # To work around JRuby error:
      # TypeError: $stderr must have write method, RSpec::StdErrSplitter given
      def write(line)
        if line !~ /^\S+gems\/ruby\-\S+:\d+: warning:/
          @orig_stderr.write(line)
          @output_tracker.write(line)
        end
      end

      def has_output?
        !output.empty?
      end

      def reset!
        @output_tracker = ::StringIO.new
      end

      def verify_example!(example)
        example.send(:fail,"Warnings were generated: #{output}") if has_output?
        reset!
      end

      def output
        @output_tracker.string
      end

    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
rspec-support-3.0.2 lib/rspec/support/spec/stderr_splitter.rb
rspec-support-3.0.1 lib/rspec/support/spec/stderr_splitter.rb
whos_dated_who-0.1.0 vendor/bundle/gems/rspec-support-3.0.0/lib/rspec/support/spec/stderr_splitter.rb
whos_dated_who-0.0.1 vendor/bundle/gems/rspec-support-3.0.0/lib/rspec/support/spec/stderr_splitter.rb
rspec-support-3.0.0 lib/rspec/support/spec/stderr_splitter.rb
rspec-support-3.0.0.rc1 lib/rspec/support/spec/stderr_splitter.rb