@@ -10,49 +10,56 @@ def initialize(fail_on_warnings = true)
1010 @output_dir = File . join ( app_root , 'tmp' )
1111 FileUtils . mkdir_p ( output_dir )
1212 @bundle_dir = File . join ( app_root , 'bundle' )
13+ @output = STDOUT
1314 end
1415
15- def before_tests
16- $stderr. reopen ( stderr_file . path )
16+ def execute!
1717 $VERBOSE = true
18- at_exit { $stderr. reopen ( STDERR ) }
19- end
20-
21- def after_tests
22- stderr_file . rewind
23- lines = stderr_file . read . split ( "\n " )
24- stderr_file . close!
18+ $stderr. reopen ( stderr_file . path )
2519
26- $stderr. reopen ( STDERR )
20+ Minitest . after_run do
21+ stderr_file . rewind
22+ lines = stderr_file . read . split ( "\n " )
23+ stderr_file . close!
24+ $stderr. reopen ( STDERR )
25+ after_tests ( lines )
26+ end
27+ end
2728
29+ # rubocop:disable Metrics/AbcSize
30+ def after_tests ( lines )
2831 app_warnings , other_warnings = lines . partition { |line |
2932 line . include? ( app_root ) && !line . include? ( bundle_dir )
3033 }
3134
32- if app_warnings . any?
33- puts <<-WARNINGS
34- #{ '-' * 30 } app warnings: #{ '-' * 30 }
35-
36- #{ app_warnings . join ( "\n " ) }
35+ header = "#{ '-' * 22 } app warnings: #{ '-' * 22 } "
36+ output . puts
37+ output . puts header
3738
38- #{ '-' * 75 }
39- WARNINGS
39+ if app_warnings . any?
40+ output . puts app_warnings . join ( "\n " )
41+ else
42+ output . puts 'None. Yay!'
4043 end
4144
4245 if other_warnings . any?
4346 File . write ( File . join ( output_dir , 'warnings.txt' ) , other_warnings . join ( "\n " ) << "\n " )
44- puts
45- puts 'Non-app warnings written to tmp/warnings.txt'
46- puts
47+ output . puts
48+ output . puts 'Non-app warnings written to tmp/warnings.txt'
49+ output . puts
4750 end
4851
52+ output . puts
53+ output . puts '-' * header . size
54+
4955 # fail the build...
5056 if fail_on_warnings && app_warnings . any?
5157 abort "Failing build due to app warnings: #{ app_warnings . inspect } "
5258 end
5359 end
60+ # rubocop:enable Metrics/AbcSize
5461
5562 private
5663
57- attr_reader :stderr_file , :app_root , :output_dir , :bundle_dir , :fail_on_warnings
64+ attr_reader :stderr_file , :app_root , :output_dir , :bundle_dir , :fail_on_warnings , :output
5865end
0 commit comments