Like RuboCop but for code coverage
Inspects files in a git diff and warns on methods, classes and blocks which need test coverage. Use it locally or as part of an automated build to shorten your code coverage feedback loop!
undercover alternatives and similar gems
Based on the "Code Analysis and Metrics" category.
Alternatively, view undercover alternatives based on common mentions on social networks and blogs.
9.8 9.8 L4 undercover VS RubocopA Ruby static code analyzer and formatter, based on the community Ruby style guide. [Moved to: https://github.com/rubocop/rubocop]
9.5 5.7 L5 undercover VS Scientist:microscope: A Ruby library for carefully refactoring critical paths.
9.0 4.9 L5 undercover VS SimpleCovCode coverage for Ruby with a powerful configuration library and automatic merging of coverage across test suites
5.4 1.9 L3 undercover VS FlogFlog reports the most tortured code in an easy to read pain report. The higher the score, the more pain the code is in.
5.0 1.9 L5 undercover VS FlayFlay analyzes code for structural similarities. Differences in literal values, variable, class, method names, whitespace, programming style, braces vs do/end, etc are all ignored.
3.0 7.3 undercover VS bundler-leakKnown-leaky gems verification for bundler: `bundle leak` to check your app and find leaky gems in your Gemfile :gem::droplet:
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of undercover or a related project?
Like RuboCop but for code coverage. Inspects files in a git diff and warns on changed methods, classes and blocks which need to be tested. Use it locally or as part of an automated build to shorten your code coverage feedback loop!
- Visit https://undercover-ci.com to set up actionable GitHub code review checks, or use one of the integrations
- Learn how to find untested code changes locally with the CLI
A sample output of
undercover ran before a commit may look like this:
And like this, given that specs were added:
Add this line to your application's Gemfile:
And then execute:
Or install it yourself as:
$ gem install undercover
Setting up required LCOV reporting
To make your specs or tests compatible with
undercover by providing an LCOV report, please add
simplecov-lcov to your test setup.
# Gemfile group :test do gem 'simplecov' gem 'simplecov-lcov' end # the very top of spec_helper.rb require 'simplecov' require 'simplecov-lcov' SimpleCov::Formatter::LcovFormatter.config.report_with_single_file = true SimpleCov.formatter = SimpleCov::Formatter::LcovFormatter SimpleCov.start do add_filter(/^\/spec\//) # For RSpec add_filter(/^\/test\//) # For Minitest enable_coverage(:branch) # Report branch coverage to trigger branch-level undercover warnings end require 'undercover' # ...
Then run your test suite once through to generate the initial
coverage/lcov/*.lcov file before you can run the
Invoked with no arguments, Undercover will flag all untested methods and classes from the current diff:
-c --compare ref flag to specify a git ref (commit hash, branch name, tag) to compare against. This is a recommended usage for CI/CD build environments, as
exit 1 if there are any warnings.
undercover --compare origin/master
docs/ for CI configuration examples:
- [Travis CI](docs/travis.yml)
- [CircleCI - simple](docs/circleci_config.yml)
- [CircleCI - advanced](docs/circleci_advanced.yml)
Merging coverage results (sample gist) is required for parallel tests before processing with
Code review integrations
A few options exist to provide automated comments from
undercover in Pull Request reviews, which is the most streamlined way to add Undercover to your development workflow.
- UndercoverCI -
undercoverPull Request feedback delivered natively with GitHub Checks
Options can be passed when running the command from the command line:
undercover -h Usage: undercover [options] -l, --lcov path LCOV report file path -p, --path path Project directory -g, --git-dir dir Override `.git` with a custom directory -c, --compare ref Generate coverage warnings for all changes after `ref` -h, --help Prints this help --version Show version
A configuration file named
.undercover can be created at the top level of a project's directory containing the same set of options for the CLI.
-l path/to/different.lcov -c origin/master
The options set in the file can be overriden by passing arguments when invoking the executable.
Options assume that the program is run from the top level of the project directory.
I wanted to create a tool to help others and myself ensure that tests are written for all the recent code changes. This should be useful for any ruby project, but especially those large or legacy codebases that lack testing (and we can't or don't want to invest in full test coverage).
The goal was to provide automated warnings, that are:
- relevant, so scoped to the actual code changes
- timely, so we don't end up writing tests long after the implementation
- actionable, so we can fix them before the code is committed or reaches production
For more background, please read the blog post.
After checking out the repo, run
bundle to install dependencies. Then, run
rake to run the tests and RuboCop. You can also run
pry -r 'undercover' for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run
bundle exec rake install. To release a new version, update the version number in
version.rb, and then run
bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the
.gem file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at https://github.com/grodowski/undercover.
The gem is available as open source under the terms of the MIT License.
*Note that all licence references and agreements mentioned in the undercover README section above are relevant to that project's source code only.