@@ -10,49 +10,56 @@ def initialize(fail_on_warnings = true)
10
10
@output_dir = File . join ( app_root , 'tmp' )
11
11
FileUtils . mkdir_p ( output_dir )
12
12
@bundle_dir = File . join ( app_root , 'bundle' )
13
+ @output = STDOUT
13
14
end
14
15
15
- def before_tests
16
- $stderr. reopen ( stderr_file . path )
16
+ def execute!
17
17
$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 )
25
19
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
27
28
29
+ # rubocop:disable Metrics/AbcSize
30
+ def after_tests ( lines )
28
31
app_warnings , other_warnings = lines . partition { |line |
29
32
line . include? ( app_root ) && !line . include? ( bundle_dir )
30
33
}
31
34
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
37
38
38
- #{ '-' * 75 }
39
- WARNINGS
39
+ if app_warnings . any?
40
+ output . puts app_warnings . join ( "\n " )
41
+ else
42
+ output . puts 'None. Yay!'
40
43
end
41
44
42
45
if other_warnings . any?
43
46
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
47
50
end
48
51
52
+ output . puts
53
+ output . puts '-' * header . size
54
+
49
55
# fail the build...
50
56
if fail_on_warnings && app_warnings . any?
51
57
abort "Failing build due to app warnings: #{ app_warnings . inspect } "
52
58
end
53
59
end
60
+ # rubocop:enable Metrics/AbcSize
54
61
55
62
private
56
63
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
58
65
end
0 commit comments