Skip to content

Instantly share code, notes, and snippets.

@tommeier
Created March 28, 2014 23:32
Show Gist options
  • Save tommeier/9845210 to your computer and use it in GitHub Desktop.
Save tommeier/9845210 to your computer and use it in GitHub Desktop.
require 'active_support/core_ext/kernel/reporting'
require 'monitor'
# Monkey patch silence_stream to be thread safe
# -> Pull request on Rails: https://github.com/rails/rails/pull/13139
# -> But this will allow us to continue to see log output when running specs
# -> It could be we just patch ActiveRecord::SessionStore that triggers the `.quietly` calls
# on logging the `find_session_id` calls.
module Kernel
# Silences any stream for the duration of the block.
#
# silence_stream(STDOUT) do
# puts 'This will never be seen'
# end
#
def silence_stream(stream)
@@monitor ||= Monitor.new
@@monitor.synchronize do
begin
old_stream = stream.dup
stream.reopen(RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ ? 'NUL:' : '/dev/null')
stream.sync = true
yield
ensure
stream.reopen(old_stream)
end
end
end
end
@leods92
Copy link

leods92 commented Apr 22, 2015

Thank you. Capybara is behaving again! [2]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment