forked from dresselm/moribus
-
Notifications
You must be signed in to change notification settings - Fork 2
/
.simplecov
42 lines (40 loc) · 1.16 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 "colorized_text"
include ColorizedText
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
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, SimpleCov.result.covered_percent
if actual < threshold
msg = "\nLow coverage: "
msg << red("#{actual}%")
msg << " is #{red 'under'} the threshold: "
msg << green("#{threshold}%.")
msg << "\n"
$stderr.puts msg
exit 1
else
# Precision: three decimal places:
actual_trunc = (actual * 1000).floor / 1000.0
msg = "\nCoverage: "
msg << green("#{actual}%")
msg << " is #{green 'over'} the threshold: "
if actual_trunc > threshold
msg << bold(yellow("#{threshold}%. "))
msg << "Please update the threshold to: "
msg << bold(green("#{actual_trunc}% "))
msg << "in ./.simplecov."
else
msg << green("#{threshold}%.")
end
msg << "\n"
$stdout.puts msg
end
end
end