mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
Merge pull request #1386 from bf4/warnings_fix_again
Remove capture_warnings testing. Is fickle and Rubocop linting is good enough
This commit is contained in:
@@ -1,75 +0,0 @@
|
||||
# https://raw.githubusercontent.com/metric_fu/metric_fu/master/spec/capture_warnings.rb
|
||||
require 'tempfile'
|
||||
require 'fileutils'
|
||||
|
||||
class CaptureWarnings
|
||||
def initialize(fail_on_warnings = true)
|
||||
@fail_on_warnings = fail_on_warnings
|
||||
@stderr_file = Tempfile.new('app.stderr')
|
||||
@app_root ||= Dir.pwd
|
||||
@output_dir = File.join(app_root, 'tmp')
|
||||
FileUtils.mkdir_p(output_dir)
|
||||
@ignore_dirs = [
|
||||
File.join(app_root, '.bundle'),
|
||||
File.join(app_root, 'bundle'),
|
||||
File.join(app_root, 'vendor')
|
||||
]
|
||||
@output = STDOUT
|
||||
end
|
||||
|
||||
def execute!
|
||||
$VERBOSE = true
|
||||
$stderr.reopen(stderr_file.path)
|
||||
|
||||
Minitest.after_run do
|
||||
stderr_file.rewind
|
||||
lines = stderr_file.read.split("\n")
|
||||
stderr_file.close!
|
||||
$stderr.reopen(STDERR)
|
||||
after_tests(lines)
|
||||
end
|
||||
end
|
||||
|
||||
def after_tests(lines)
|
||||
app_warnings, other_warnings = lines.partition do |line|
|
||||
line.include?(app_root) && ignore_dirs.none? { |ignore_dir| line.include?(ignore_dir) }
|
||||
end
|
||||
|
||||
if app_warnings.any?
|
||||
warnings_message = app_warnings.join("\n")
|
||||
print_warnings = true
|
||||
else
|
||||
warnings_message = 'None. Yay!'
|
||||
ENV['FULL_BUILD'] ||= ENV['CI']
|
||||
running_ci = ENV['FULL_BUILD'] =~ /\Atrue\z/i
|
||||
print_warnings = running_ci
|
||||
end
|
||||
|
||||
if other_warnings.any?
|
||||
File.write(File.join(output_dir, 'warnings.txt'), other_warnings.join("\n") << "\n")
|
||||
warnings_message << "\nNon-app warnings written to tmp/warnings.txt"
|
||||
print_warnings = true
|
||||
end
|
||||
|
||||
header = "#{'-' * 22} app warnings: #{'-' * 22}"
|
||||
message = <<-EOF.strip_heredoc
|
||||
|
||||
#{header}
|
||||
|
||||
#{warnings_message}
|
||||
|
||||
#{'-' * header.size}
|
||||
EOF
|
||||
|
||||
output.puts(message) if print_warnings
|
||||
|
||||
# fail the build...
|
||||
if fail_on_warnings && app_warnings.any?
|
||||
abort "Failing build due to app warnings: #{app_warnings.inspect}"
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
attr_reader :stderr_file, :app_root, :output_dir, :ignore_dirs, :fail_on_warnings, :output
|
||||
end
|
||||
@@ -21,37 +21,26 @@ require 'fileutils'
|
||||
FileUtils.mkdir_p(File.expand_path('../../tmp/cache', __FILE__))
|
||||
|
||||
gem 'minitest'
|
||||
require 'minitest/autorun'
|
||||
require 'minitest/reporters'
|
||||
Minitest::Reporters.use!
|
||||
if defined?(Minitest::Test)
|
||||
$minitest_version = 5 # rubocop:disable Style/GlobalVars
|
||||
# Minitest 5
|
||||
# https://github.com/seattlerb/minitest/blob/e21fdda9d/lib/minitest/autorun.rb
|
||||
# https://github.com/seattlerb/minitest/blob/e21fdda9d/lib/minitest.rb#L45-L59
|
||||
else
|
||||
$minitest_version = 4 # rubocop:disable Style/GlobalVars
|
||||
begin
|
||||
require 'minitest'
|
||||
rescue LoadError
|
||||
# Minitest 4
|
||||
require 'minitest/autorun'
|
||||
$minitest_version = 4
|
||||
# https://github.com/seattlerb/minitest/blob/644a52fd0/lib/minitest/autorun.rb
|
||||
# https://github.com/seattlerb/minitest/blob/644a52fd0/lib/minitest/unit.rb#L768-L787
|
||||
# Ensure backward compatibility with Minitest 4
|
||||
Minitest = MiniTest unless defined?(Minitest)
|
||||
Minitest::Test = MiniTest::Unit::TestCase
|
||||
def Minitest.after_run(&block)
|
||||
MiniTest::Unit.after_tests(&block)
|
||||
end
|
||||
end
|
||||
|
||||
# If there's no failure info, try disabling capturing stderr:
|
||||
# `env CAPTURE_STDERR=false rake`
|
||||
# This is way easier than writing a Minitest plugin
|
||||
# for 4.x and 5.x.
|
||||
if ENV['CAPTURE_STDERR'] !~ /false|1/i
|
||||
require 'capture_warnings'
|
||||
CaptureWarnings.new(_fail_build = true).execute!
|
||||
else
|
||||
$VERBOSE = true
|
||||
# Minitest 5
|
||||
require 'minitest/autorun'
|
||||
$minitest_version = 5
|
||||
# https://github.com/seattlerb/minitest/blob/e21fdda9d/lib/minitest/autorun.rb
|
||||
# https://github.com/seattlerb/minitest/blob/e21fdda9d/lib/minitest.rb#L45-L59
|
||||
end
|
||||
require 'minitest/reporters'
|
||||
Minitest::Reporters.use!
|
||||
|
||||
require 'active_model_serializers'
|
||||
require 'active_model/serializer/railtie'
|
||||
@@ -71,6 +60,6 @@ require 'fixtures/active_record'
|
||||
require 'fixtures/poro'
|
||||
|
||||
ActiveSupport.on_load(:active_model_serializers) do
|
||||
$action_controller_logger = ActiveModelSerializers.logger # rubocop:disable Style/GlobalVars
|
||||
$action_controller_logger = ActiveModelSerializers.logger
|
||||
ActiveModelSerializers.logger = Logger.new(IO::NULL)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user