Forked from tommeier/make_silence_stream_thread_safe.rb
Last active
August 29, 2015 14:03
-
-
Save alexmchale/b68a2c72ed1f432418d9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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