Skip to content

Commit ec42303

Browse files
authored
Merge pull request #179 from github/kpaulisse-simplecov-erb
Use simplecov-erb gem for test coverage and enforce 100% test coverage
2 parents 2e94eda + d1530b1 commit ec42303

File tree

7 files changed

+24
-61
lines changed

7 files changed

+24
-61
lines changed

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ matrix:
88
include:
99
# Build with latest ruby
1010
- rvm: 2.5
11-
env: RUBOCOP_TEST="true" RSPEC_TEST="true" PUPPET_VERSIONS="3.8.7"
11+
env: RUBOCOP_TEST="false" RSPEC_TEST="true" ENFORCE_COVERAGE="true" PUPPET_VERSIONS="3.8.7"
1212
- rvm: 2.5
13-
env: RUBOCOP_TEST="false" RSPEC_TEST="true" PUPPET_VERSIONS="4.10.8"
13+
env: RUBOCOP_TEST="false" RSPEC_TEST="true" ENFORCE_COVERAGE="true" PUPPET_VERSIONS="4.10.8"
1414
- rvm: 2.5
15-
env: RUBOCOP_TEST="false" RSPEC_TEST="true" PUPPET_VERSIONS="5.0.0"
15+
env: RUBOCOP_TEST="true" RSPEC_TEST="true" ENFORCE_COVERAGE="true" PUPPET_VERSIONS="5.0.0"
1616
# Build with older ruby versions
1717
- rvm: 2.4
1818
env: RUBOCOP_TEST="false" RSPEC_TEST="true" PUPPET_VERSIONS="3.8.7"

octocatalog-diff.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ EOF
3737
s.add_development_dependency 'rubocop', '= 0.48.1'
3838

3939
s.add_development_dependency 'simplecov', '~> 0.14.1'
40-
s.add_development_dependency 'simplecov-json'
40+
s.add_development_dependency 'simplecov-erb', '~> 0.1.1'
4141

4242
puppet_version = ENV['PUPPET_VERSION'] || DEFAULT_PUPPET_VERSION
4343
s.add_development_dependency 'puppet', "~> #{puppet_version}"

script/cibuild

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ fi
6969
if [ "$RSPEC_TEST" = "true" ]; then
7070
SAVED_PATH="$PATH"
7171
RSPEC_EXITCODE="0"
72+
COVERAGE_EXITCODE="0"
7273
for pv in $PUPPET_VERSIONS ; do
7374
export PUPPET_VERSION="$pv"
7475

@@ -105,7 +106,12 @@ if [ "$RSPEC_TEST" = "true" ]; then
105106
if [ "$exitcode" -ne 0 ]; then RSPEC_EXITCODE="$exitcode"; fi
106107

107108
# Quick coverage report
108-
"$DIR/script/display-coverage-report" "$DIR/coverage/coverage.json"
109+
cat "$DIR/coverage/coverage.txt"
110+
if grep -q "100% test coverage. You're all set, friend" "$DIR/coverage/coverage.txt"; then
111+
:
112+
else
113+
COVERAGE_EXITCODE=1
114+
fi
109115
echo ""
110116

111117
# To avoid travis getting hung if it gets confused, we'll run each of these
@@ -136,11 +142,19 @@ if [ "$RSPEC_TEST" = "true" ]; then
136142
rm -f "${DIR}/.puppet_version"
137143
else
138144
RSPEC_EXITCODE=-1
145+
COVERAGE_EXITCODE=-1
139146
echo ""
140147
fi
141148

142149
# Finish off script
143150
echo "Finished script/cibuild:"
144-
[ "$RUBOCOP_EXITCODE" -ge 0 ] && echo " - rubocop: exit ${RUBOCOP_EXITCODE}"
145-
[ "$RSPEC_EXITCODE" -ge 0 ] && echo " - rspec: exit ${RSPEC_EXITCODE}"
146-
if [ "$RUBOCOP_EXITCODE" -gt 0 ] || [ "$RSPEC_EXITCODE" -gt 0 ]; then exit 1; else exit 0; fi
151+
[ "$RUBOCOP_EXITCODE" -ge 0 ] && echo " - rubocop: exit ${RUBOCOP_EXITCODE}"
152+
[ "$RSPEC_EXITCODE" -ge 0 ] && echo " - rspec: exit ${RSPEC_EXITCODE}"
153+
[ "$COVERAGE_EXITCODE" -ge 0 ] && echo " - coverage: exit ${COVERAGE_EXITCODE}"
154+
if [ "$RUBOCOP_EXITCODE" -gt 0 ] || [ "$RSPEC_EXITCODE" -gt 0 ]; then
155+
exit 1
156+
fi
157+
if [ "$COVERAGE_EXITCODE" -gt 0 ] && [ "$ENFORCE_COVERAGE" == "true" ]; then
158+
exit 1
159+
fi
160+
exit 0

script/display-coverage-report

Lines changed: 0 additions & 51 deletions
This file was deleted.

spec/octocatalog-diff/tests/spec_helper.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
# Enable SimpleCov coverage testing?
88
if ENV['COVERAGE']
99
require 'simplecov'
10-
require 'simplecov-json'
10+
require 'simplecov-erb'
1111
SimpleCov.formatters = [
1212
SimpleCov::Formatter::HTMLFormatter,
13-
SimpleCov::Formatter::JSONFormatter
13+
SimpleCov::Formatter::ERBFormatter
1414
]
1515
SimpleCov.start do
1616
# don't show specs as missing coverage for themselves

vendor/cache/simplecov-erb-0.1.1.gem

5.5 KB
Binary file not shown.

vendor/cache/simplecov-json-0.2.gem

-4.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)