Sha256: 42a3aad7f9f5d222e0805cbb4a717a93fa0ee9528871051ada3dc7a2eaf8ab34

Contents?: true

Size: 820 Bytes

Versions: 7

Compression:

Stored size: 820 Bytes

Contents

module Kernel
  # #capture, #silence_stream, and #silence_stderr are deprecated after Rails
  # 4.2 and will be removed in 5.0, so just override them completely here

  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
    return captured_stream.read
  ensure
    captured_stream.unlink
    stream_io.reopen(origin_stream)
  end

  def silence_stream(stream)
    old_stream = stream.dup
    stream.reopen(RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ ? 'NUL:' : '/dev/null')
    stream.sync = true
    yield
  ensure
    stream.reopen(old_stream)
    old_stream.close
  end

  def silence_stderr
    silence_stream(STDERR) { yield }
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/shoulda-matchers-2.8.0/spec/support/unit/capture.rb
shoulda-matchers-3.0.1 spec/support/unit/capture.rb
shoulda-matchers-3.0.0 spec/support/unit/capture.rb
shoulda-matchers-3.0.0.rc1 spec/support/unit/capture.rb
shoulda-matchers-2.8.0 spec/support/unit/capture.rb
shoulda-matchers-2.8.0.rc2 spec/support/unit/capture.rb
shoulda-matchers-2.8.0.rc1 spec/support/unit/capture.rb