mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-23 06:16:50 +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:
commit
d448481b6b
26
.rubocop.yml
26
.rubocop.yml
@ -58,3 +58,29 @@ Style/MultilineOperationIndentation:
|
|||||||
Style/BlockDelimiters:
|
Style/BlockDelimiters:
|
||||||
Enabled: true
|
Enabled: true
|
||||||
EnforcedStyle: line_count_based
|
EnforcedStyle: line_count_based
|
||||||
|
|
||||||
|
########## test_helper.rb sanity
|
||||||
|
Style/EndBlock:
|
||||||
|
Exclude:
|
||||||
|
- test/test_helper.rb
|
||||||
|
|
||||||
|
Style/SpecialGlobalVars:
|
||||||
|
Exclude:
|
||||||
|
- test/test_helper.rb
|
||||||
|
|
||||||
|
Style/GlobalVars:
|
||||||
|
Exclude:
|
||||||
|
- test/test_helper.rb
|
||||||
|
|
||||||
|
Style/AndOr:
|
||||||
|
Exclude:
|
||||||
|
- test/test_helper.rb
|
||||||
|
- 'lib/active_model/serializer/lint.rb'
|
||||||
|
|
||||||
|
Style/Not:
|
||||||
|
Exclude:
|
||||||
|
- test/test_helper.rb
|
||||||
|
|
||||||
|
Style/ClassCheck:
|
||||||
|
Exclude:
|
||||||
|
- test/test_helper.rb
|
||||||
|
|||||||
@ -53,13 +53,6 @@ Style/AlignHash:
|
|||||||
Exclude:
|
Exclude:
|
||||||
- 'test/action_controller/json_api/pagination_test.rb'
|
- 'test/action_controller/json_api/pagination_test.rb'
|
||||||
|
|
||||||
# Offense count: 1
|
|
||||||
# Cop supports --auto-correct.
|
|
||||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
|
||||||
Style/AndOr:
|
|
||||||
Exclude:
|
|
||||||
- 'lib/active_model/serializer/lint.rb'
|
|
||||||
|
|
||||||
# Offense count: 25
|
# Offense count: 25
|
||||||
# Cop supports --auto-correct.
|
# Cop supports --auto-correct.
|
||||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||||
@ -105,7 +98,6 @@ Style/EachWithObject:
|
|||||||
Style/GuardClause:
|
Style/GuardClause:
|
||||||
Exclude:
|
Exclude:
|
||||||
- 'lib/active_model/serializer.rb'
|
- 'lib/active_model/serializer.rb'
|
||||||
- 'test/capture_warnings.rb'
|
|
||||||
|
|
||||||
# Offense count: 12
|
# Offense count: 12
|
||||||
# Cop supports --auto-correct.
|
# Cop supports --auto-correct.
|
||||||
|
|||||||
@ -41,6 +41,7 @@ SimpleCov.profiles.define 'app' do
|
|||||||
add_filter '/config/'
|
add_filter '/config/'
|
||||||
add_filter '/db/'
|
add_filter '/db/'
|
||||||
add_filter 'tasks'
|
add_filter 'tasks'
|
||||||
|
add_filter '/.bundle/'
|
||||||
end
|
end
|
||||||
|
|
||||||
## START TRACKING COVERAGE (before activating SimpleCov)
|
## START TRACKING COVERAGE (before activating SimpleCov)
|
||||||
|
|||||||
@ -16,7 +16,7 @@ cache:
|
|||||||
- vendor/bundle
|
- vendor/bundle
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- env CAPTURE_STDERR=${CAPTURE_STDERR:-false} bundle exec rake ci
|
- bundle exec rake ci
|
||||||
|
|
||||||
env:
|
env:
|
||||||
- "RAILS_VERSION=4.0"
|
- "RAILS_VERSION=4.0"
|
||||||
@ -31,8 +31,6 @@ matrix:
|
|||||||
- rvm: 2.1
|
- rvm: 2.1
|
||||||
env: RAILS_VERSION=master
|
env: RAILS_VERSION=master
|
||||||
include:
|
include:
|
||||||
- rvm: 2.2
|
|
||||||
env: CAPTURE_STDERR=true
|
|
||||||
- rvm: jruby-9.0.4.0
|
- rvm: jruby-9.0.4.0
|
||||||
env: JRUBY_OPTS='-Xcompat.version=2.0 --server -Xcompile.invokedynamic=false -Xcli.debug=true --debug'
|
env: JRUBY_OPTS='-Xcompat.version=2.0 --server -Xcompile.invokedynamic=false -Xcli.debug=true --debug'
|
||||||
allow_failures:
|
allow_failures:
|
||||||
|
|||||||
@ -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__))
|
FileUtils.mkdir_p(File.expand_path('../../tmp/cache', __FILE__))
|
||||||
|
|
||||||
gem 'minitest'
|
gem 'minitest'
|
||||||
require 'minitest/autorun'
|
begin
|
||||||
require 'minitest/reporters'
|
require 'minitest'
|
||||||
Minitest::Reporters.use!
|
rescue LoadError
|
||||||
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
|
|
||||||
# Minitest 4
|
# 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/autorun.rb
|
||||||
# https://github.com/seattlerb/minitest/blob/644a52fd0/lib/minitest/unit.rb#L768-L787
|
# https://github.com/seattlerb/minitest/blob/644a52fd0/lib/minitest/unit.rb#L768-L787
|
||||||
# Ensure backward compatibility with Minitest 4
|
# Ensure backward compatibility with Minitest 4
|
||||||
Minitest = MiniTest unless defined?(Minitest)
|
Minitest = MiniTest unless defined?(Minitest)
|
||||||
Minitest::Test = MiniTest::Unit::TestCase
|
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
|
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
|
end
|
||||||
|
require 'minitest/reporters'
|
||||||
|
Minitest::Reporters.use!
|
||||||
|
|
||||||
require 'active_model_serializers'
|
require 'active_model_serializers'
|
||||||
require 'active_model/serializer/railtie'
|
require 'active_model/serializer/railtie'
|
||||||
@ -71,6 +60,6 @@ require 'fixtures/active_record'
|
|||||||
require 'fixtures/poro'
|
require 'fixtures/poro'
|
||||||
|
|
||||||
ActiveSupport.on_load(:active_model_serializers) do
|
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)
|
ActiveModelSerializers.logger = Logger.new(IO::NULL)
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user