Skip to content

Commit

Permalink
resolves #196 enable code coverage reports (PR #197)
Browse files Browse the repository at this point in the history
  • Loading branch information
mojavelinux committed Dec 20, 2018
1 parent 5c9fe8f commit 64566d9
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .deep_cover.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
DeepCover.configure do
output 'coverage/report-deep-cover'
paths %w(./lib)
reporter :text if ENV['CI']
reporter :istanbul if ENV['DEEP_COVER_REPORTER'] == 'istanbul'
end
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
/*.gem
/.bundle/
/build/
/coverage/
/deep_cover/
/pkg/
/Gemfile.lock
.idea
Expand Down
4 changes: 4 additions & 0 deletions .simplecov
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SimpleCov.start do
add_filter %w(/.bundle/ /spec/)
coverage_dir 'coverage/report-simplecov'
end
7 changes: 5 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,23 @@ git:
depth: 2
language: ruby
rvm:
- &release_rvm 2.5.3
- 2.4.5
- 2.3.8
- jruby-9.2.5.0
- jruby-9.1.17.0
matrix:
include:
- rvm: &release_rvm 2.5.3
install: bundle install --jobs=3 --retry=3
script: bundle exec rake spec
notifications:
email:
on_success: never
on_failure: change
deploy:
provider: rubygems
gem: jekyll-asciidoc
api_key: ${RUBYGEMS_API_KEY}
gem: jekyll-asciidoc
on:
tags: true
repo: asciidoctor/jekyll-asciidoc
Expand Down
36 changes: 36 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1497,6 +1497,42 @@ Then, run RSpec with the `focus` flag enabled:

You should see that RSpec only runs the specifications that have this flag.

=== Generating Code Coverage

To generate a code coverage report when running tests using simplecov, set the `COVERAGE` environment variable as follows when running the tests:

$ COVERAGE=true bundle exec rake spec

You'll see a total coverage score as well as a link to the HTML report in the output.
The HTML report helps you understand which lines and branches were missed, if any.

Despite being fast, the downside of using simplecov is that it misses branches.
You can use deep-cover to generate a more thorough report.
To do so, set the `COVERAGE` environment variable as follows when running the tests:

$ COVERAGE=deep bundle exec rake spec

You'll see a total coverage score, a detailed coverage report, and a link to HTML report in the output.
The HTML report helps you understand which lines and branches were missed, if any.

////
As an alternative to deep cover's native HTML reporter, you can also use istanbul / nyc.
First, you'll need to have the `nyc` command available on your system:
$ npm install -g nyc
or
$ yarn global add nyc
Next, in addition to the `COVERAGE` environment variable, also set the `DEEP_COVER_REPORTER` environment variable as follows when running the tests:
$ COVERAGE=deep DEEP_COVER_REPORTER=istanbul bundle exec rake spec
You'll see a total coverage score, a detailed coverage report, and a link to HTML report in the output.
The HTML report helps you understand which lines and branches were missed, if any.
////

=== Installing the Gem Locally

You can install the development version of the gem as follows:
Expand Down
4 changes: 1 addition & 3 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ default_tasks = []

begin
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec) do |t|
t.rspec_opts = ['-c']
end
RSpec::Core::RakeTask.new :spec
default_tasks << :spec
rescue LoadError
end
Expand Down
2 changes: 2 additions & 0 deletions jekyll-asciidoc.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,7 @@ Gem::Specification.new do |s|
s.add_runtime_dependency 'jekyll', '>= 3.0.0'

s.add_development_dependency 'rake', '~> 12.3.2'
s.add_development_dependency 'deep-cover-core', '~> 0.7.0'
s.add_development_dependency 'rspec', '~> 3.8.0'
s.add_development_dependency 'simplecov', '~> 0.16.1'
end
8 changes: 8 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
if ENV['COVERAGE'] == 'deep'
ENV['DEEP_COVER'] = 'true'
require 'deep_cover'
elsif ENV['COVERAGE'] == 'true'
require 'deep_cover/builtin_takeover'
require 'simplecov'
end

require 'jekyll'
require 'fileutils'

Expand Down

0 comments on commit 64566d9

Please sign in to comment.