forked from albertosaurus/flat_map
-
Notifications
You must be signed in to change notification settings - Fork 1
/
.simplecov
42 lines (40 loc) · 1.34 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
require "simplecov-rcov-text"
require "colorize"
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
SimpleCov::Formatter::RcovTextFormatter,
SimpleCov::Formatter::HTMLFormatter
]
SimpleCov.start do
add_filter "/spec/"
# Fail the build when coverage is weak:
at_exit do
SimpleCov.result.format!
threshold, actual = 100.0, SimpleCov.result.covered_percent
if actual < threshold then # FAIL
msg = "\nLow coverage: "
msg << "#{actual}%".colorize(:red)
msg << ' is ' << 'under'.colorize(:red) << ' the threshold: '
msg << "#{threshold}%.".colorize(:green)
msg << "\n"
$stderr.puts msg
exit 1
else # PASS
# Precision: three decimal places:
actual_trunc = (actual * 1000).floor / 1000.0
msg = "\nCoverage: "
msg << "#{actual}%".colorize(:green)
if actual_trunc > threshold
msg << ' is ' << 'over'.colorize(:green) << ' the threshold: '
msg << "#{threshold}%. ".colorize(color: :yellow, mode: :bold)
msg << 'Please update the threshold to: '
msg << "#{actual_trunc}% ".colorize(color: :green, mode: :bold)
msg << 'in ./.simplecov.'
else
msg << ' is ' << 'at'.colorize(:green) << ' the threshold: '
msg << "#{threshold}%.".colorize(:green)
end
msg << "\n"
$stdout.puts msg
end
end
end