Remove warnings shown when running tests

* For some reason, ActiveRecord was printing a warning saying that
  "active_record/base" was already being loaded and there was a possible
  circular dependency. We fix this by explicitly requiring
  "active_record/base" before `$VERBOSE` is set to true.
* We were getting warnings when re-defining Kernel.capture,
  Kernel.silence_stream and Kernel.silence_stderr, so undefine them
  first.
This commit is contained in:
Elliot Winkler 2015-12-08 23:37:48 -07:00
parent 6b9f22a92f
commit 6cc7fd8ca2
2 changed files with 8 additions and 0 deletions

View File

@ -2,6 +2,8 @@ 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
undef_method :capture
def capture(stream)
stream = stream.to_s
captured_stream = Tempfile.new(stream)
@ -18,6 +20,8 @@ module Kernel
stream_io.reopen(origin_stream)
end
undef_method :silence_stream
def silence_stream(stream)
old_stream = stream.dup
stream.reopen(RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ ? 'NUL:' : '/dev/null')
@ -28,6 +32,8 @@ module Kernel
old_stream.close
end
undef_method :silence_stderr
def silence_stderr
silence_stream(STDERR) { yield }
end

View File

@ -10,6 +10,8 @@ $test_app = UnitTests::RailsApplication.new
$test_app.create
$test_app.load
require 'active_record/base'
ENV['BUNDLE_GEMFILE'] ||= app.gemfile_path
ENV['RAILS_ENV'] = 'test'