mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06: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:
|
||||
Enabled: true
|
||||
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:
|
||||
- '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
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||
@ -105,7 +98,6 @@ Style/EachWithObject:
|
||||
Style/GuardClause:
|
||||
Exclude:
|
||||
- 'lib/active_model/serializer.rb'
|
||||
- 'test/capture_warnings.rb'
|
||||
|
||||
# Offense count: 12
|
||||
# Cop supports --auto-correct.
|
||||
|
||||
@ -41,6 +41,7 @@ SimpleCov.profiles.define 'app' do
|
||||
add_filter '/config/'
|
||||
add_filter '/db/'
|
||||
add_filter 'tasks'
|
||||
add_filter '/.bundle/'
|
||||
end
|
||||
|
||||
## START TRACKING COVERAGE (before activating SimpleCov)
|
||||
|
||||
@ -16,7 +16,7 @@ cache:
|
||||
- vendor/bundle
|
||||
|
||||
script:
|
||||
- env CAPTURE_STDERR=${CAPTURE_STDERR:-false} bundle exec rake ci
|
||||
- bundle exec rake ci
|
||||
|
||||
env:
|
||||
- "RAILS_VERSION=4.0"
|
||||
@ -31,8 +31,6 @@ matrix:
|
||||
- rvm: 2.1
|
||||
env: RAILS_VERSION=master
|
||||
include:
|
||||
- rvm: 2.2
|
||||
env: CAPTURE_STDERR=true
|
||||
- rvm: jruby-9.0.4.0
|
||||
env: JRUBY_OPTS='-Xcompat.version=2.0 --server -Xcompile.invokedynamic=false -Xcli.debug=true --debug'
|
||||
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__))
|
||||
|
||||
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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user