forked from bf4/active_model_serializers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.simplecov
110 lines (97 loc) · 3 KB
/
.simplecov
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# https://github.com/colszowka/simplecov#using-simplecov-for-centralized-config
# see https://github.com/colszowka/simplecov/blob/master/lib/simplecov/defaults.rb
# vim: set ft=ruby
## DEFINE VARIABLES
@minimum_coverage = ENV.fetch('COVERAGE_MINIMUM') {
case (defined?(RUBY_ENGINE) && RUBY_ENGINE) || "ruby"
when 'jruby', 'rbx'
96.0
else
98.1
end
}.to_f.round(2)
# rubocop:disable Style/DoubleNegation
ENV['FULL_BUILD'] ||= ENV['CI']
@running_ci = !!(ENV['FULL_BUILD'] =~ /\Atrue\z/i)
@generate_report = @running_ci || !!(ENV['COVERAGE'] =~ /\Atrue\z/i)
@output = STDOUT
# rubocop:enable Style/DoubleNegation
## CONFIGURE SIMPLECOV
SimpleCov.profiles.define 'app' do
coverage_dir 'coverage'
load_profile 'test_frameworks'
add_group 'Libraries', 'lib'
add_group 'Long files' do |src_file|
src_file.lines.count > 100
end
class MaxLinesFilter < SimpleCov::Filter
def matches?(source_file)
source_file.lines.count < filter_argument
end
end
add_group 'Short files', MaxLinesFilter.new(5)
# Exclude these paths from analysis
add_filter '/config/'
add_filter '/db/'
add_filter 'tasks'
add_filter '/.bundle/'
end
## START TRACKING COVERAGE (before activating SimpleCov)
require 'coverage'
Coverage.start
## ADD SOME CUSTOM REPORTING AT EXIT
SimpleCov.at_exit do
next if $! and not ($!.kind_of? SystemExit and $!.success?)
header = "#{'*' * 20} SimpleCov Results #{'*' * 20}"
results = SimpleCov.result.format!.join("\n")
exit_message = <<-EOF
#{header}
{{RESULTS}}
{{FAILURE_MESSAGE}}
#{'*' * header.size}
EOF
percent = Float(SimpleCov.result.covered_percent)
if percent < @minimum_coverage
failure_message = <<-EOF
Spec coverage was not high enough: #{percent.round(2)}% is < #{@minimum_coverage}%
EOF
exit_message.sub!('{{RESULTS}}', results).sub!('{{FAILURE_MESSAGE}}', failure_message)
@output.puts exit_message
abort(failure_message) if @generate_report
elsif @running_ci
exit_message.sub!('{{RESULTS}}', results).sub!('{{FAILURE_MESSAGE}}', <<-EOF)
Nice job! Spec coverage (#{percent.round(2)}%) is still at or above #{@minimum_coverage}%
EOF
@output.puts exit_message
end
end
## CAPTURE CONFIG IN CLOSURE 'AppCoverage.start'
## to defer running until test/test_helper.rb is loaded.
# rubocop:disable Style/MultilineBlockChain
AppCoverage = Class.new do
def initialize(&block)
@block = block
end
def start
@block.call
end
end.new do
SimpleCov.start 'app'
if @generate_report
if @running_ci
require 'codeclimate-test-reporter'
@output.puts '[COVERAGE] Running with SimpleCov Simple Formatter and CodeClimate Test Reporter'
formatters = [
SimpleCov::Formatter::SimpleFormatter,
CodeClimate::TestReporter::Formatter
]
else
@output.puts '[COVERAGE] Running with SimpleCov HTML Formatter'
formatters = [SimpleCov::Formatter::HTMLFormatter]
end
else
formatters = []
end
SimpleCov.formatters = formatters
end
# rubocop:enable Style/MultilineBlockChain