Sha256: 3f0f8f6ab176c5164a0f72d3d780cdef6cf229d395bd35736bc3d9e545871f69

Contents?: true

Size: 945 Bytes

Versions: 47

Compression:

Stored size: 945 Bytes

Contents

# frozen_string_literal: true

module ActiveSupport
  module Testing
    module Stream # :nodoc:
      private
        def silence_stream(stream)
          old_stream = stream.dup
          stream.reopen(IO::NULL)
          stream.sync = true
          yield
        ensure
          stream.reopen(old_stream)
          old_stream.close
        end

        def quietly(&block)
          silence_stream(STDOUT) do
            silence_stream(STDERR, &block)
          end
        end

        def capture(stream)
          stream = stream.to_s
          captured_stream = Tempfile.new(stream)
          stream_io = eval("$#{stream}")
          origin_stream = stream_io.dup
          stream_io.reopen(captured_stream)

          yield

          stream_io.rewind
          captured_stream.read
        ensure
          captured_stream.close
          captured_stream.unlink
          stream_io.reopen(origin_stream)
        end
    end
  end
end

Version data entries

47 entries across 44 versions & 8 rubygems

Version Path
activesupport-7.0.8.7 lib/active_support/testing/stream.rb
activesupport-7.0.8.6 lib/active_support/testing/stream.rb
activesupport-7.0.8.5 lib/active_support/testing/stream.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.8.4/lib/active_support/testing/stream.rb
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/activesupport-7.0.5.1/lib/active_support/testing/stream.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/activesupport-7.0.5.1/lib/active_support/testing/stream.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/activesupport-7.0.5.1/lib/active_support/testing/stream.rb
activesupport-7.0.8.4 lib/active_support/testing/stream.rb
activesupport-7.0.8.1 lib/active_support/testing/stream.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/activesupport-7.0.3.1/lib/active_support/testing/stream.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/activesupport-7.0.2.3/lib/active_support/testing/stream.rb
activesupport-7.0.8 lib/active_support/testing/stream.rb
activesupport-7.0.7.2 lib/active_support/testing/stream.rb
activesupport-7.0.7.1 lib/active_support/testing/stream.rb
activesupport-7.0.7 lib/active_support/testing/stream.rb
mlh-rubocop-config-1.0.2 vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.6/lib/active_support/testing/stream.rb
fablicop-1.10.3 vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.6/lib/active_support/testing/stream.rb
fablicop-1.10.3 vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.5/lib/active_support/testing/stream.rb
activesupport-7.0.6 lib/active_support/testing/stream.rb
activesupport-7.0.5.1 lib/active_support/testing/stream.rb