Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save alexmchale/b68a2c72ed1f432418d9 to your computer and use it in GitHub Desktop.
Save alexmchale/b68a2c72ed1f432418d9 to your computer and use it in GitHub Desktop.
require 'active_support/core_ext/kernel/reporting'
require 'active_support/core_ext/module/aliasing'
require 'monitor'
# This is my variation on Tom Meier's monkey-patch to fix a problem in Rails
# I've run into with RSpec. I've tweaked it a bit to use `alias_method_chain`
# instead of just overloading the original method and copying its code.
#
# See the original Gist here:
#
# https://gist.github.com/tommeier/9845210
#
# Here are Tom Meier's notes on the problem:
#
# 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
def silence_stream_with_monitor(stream, &block)
@@monitor ||= Monitor.new
@@monitor.synchronize do
silence_stream_without_monitor(stream, &block)
end
end
alias_method_chain :silence_stream, :monitor
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment