kettle-rb logo, Copyright (c) 2023 Peter Boling, CC BY-SA 4.0, see https://kettle-rb.gitlab.io/logos

Kettle::Soup::Cover

Version License: MIT Downloads Rank Open Source Helpers Depfu CodeCov Test Coverage Coveralls Test Coverage CodeClimate Test Coverage Maintainability CI Heads CI Current CI Supported CI Legacy CI Unsupported CI Test Coverage CI Style


Liberapay Patrons Sponsor Me on Github Buy me a coffee Polar Shield Donate to my FLOSS or refugee efforts at ko-fi.com Donate to my FLOSS or refugee efforts using Patreon

A Covered Kettle of SOUP (Software of Unknown Provenance)

The name is derived in part from the medical devices field, where this library is considered a package of SOUP.

Just add four lines of code to get a configured, curated, opinionated, set of dependencies for Test Coverage.

One of the major benefits of using this library is not having to figure out how to get multiple coverage output formats working. I did that for you, and I got all of them working, at the same time together, or al la carte. Kum-ba-ya.

A quick shot of raw coverage power, straight to your brain:

export K_SOUP_COV_DO=true # Means you want code coverage
export K_SOUP_COV_FORMATTERS="html,tty" # Set to some slice of "html,xml,rcov,lcov,json,tty"
export K_SOUP_COV_MIN_BRANCH=53 # Means you want to enforce X% branch coverage
export K_SOUP_COV_MIN_HARD=true # Means you want the build to fail if the coverage thresholds are not met
export K_SOUP_COV_MIN_LINE=69 # Means you want to enforce X% line coverage
export MAX_ROWS=5 # Setting for simplecov-console gem for tty output, limits to the worst N rows of bad coverage

I hope I've piqued your interest.

Info you can shake a stick at

Tokens to Remember Gem name Gem namespace
Works with MRI Ruby 3 Ruby 3.0 Compat Ruby 3.1 Compat Ruby 3.2 Compat Ruby 3.3 Compat Ruby 3.4 Compat Ruby HEAD Compat
Works with MRI Ruby 2 Ruby 2.7 Compat
Source Source on GitLab.com Source on Github.com The best SHA: dQw4w9WgXcQ!
Documentation Current release on RubyDoc.info HEAD on RubyDoc.info BDFL Blog Wiki
Compliance License: MIT ๐Ÿ“„ilo-declaration-img Security Policy CodeQL Contributor Covenant 2.1 SemVer 2.0.0 Keep-A-Changelog 1.0.0
Expert 1:1 Support Get help from me on Upwork or Get help from me on Codementor
Enterprise Support Get help from me on Tidelift
๐Ÿ’กSubscribe for support guarantees covering all FLOSS dependencies!
๐Ÿ’กTidelift is part of Sonar!
๐Ÿ’กTidelift pays maintainers to maintain the software you depend on!
๐Ÿ“Š@Pointy Haired Boss: An enterprise support subscription is "never gonna let you down", and supports open source maintainers!
Comrade BDFL ๐ŸŽ–๏ธ Follow Me on LinkedIn Follow Me on Ruby.Social Follow Me on Bluesky Contact BDFL My technical writing
... ๐Ÿ’– Find Me on WellFound: Find Me on CrunchBase My LinkTree More About Me

Installation

Install the gem and add to the application's Gemfile by executing:

$ bundle add kettle-soup-cover

If bundler is not being used to manage dependencies, install the gem by executing:

$ gem install kettle-soup-cover

Usage

In your spec/spec_helper.rb, just prior to loading the library under test:

# This does not require "simplecov",
#   because that has a side-effect of running `.simplecov`
require "kettle-soup-cover"

# Later in your spec setup, do this;
require "simplecov" if Kettle::Soup::Cover::DO_COV

In your .simplecov file:

require "kettle/soup/cover/config"
SimpleCov.start # you could do this somewhere else, up to you, but you do have to do it

See Advanced Usage below for more info, but the simplest thing is to run all the coverage things, which is configured by default on CI. To replicate that locally you could:

CI=true bundle exec rake test # or whatever command you run for tests.

That's it!

Rakefile

You'll need to have your test task defined. If you use spec instead, you can alias test to spec as follows:

desc "alias test task to spec"
task test: :spec

This gem provides a coverage task. It runs the test task (see just above about that), and opens the coverage results in a browser.

require "kettle-soup-cover"
Kettle::Soup::Cover.install_tasks

Filters

There are two built-in SimpleCov filters which can be loaded via Kettle::Soup::Cover.load_filters.

You could use them like this:

SimpleCov.add_group("Too Long", Kettle::Soup::Cover::Filters::GtLineFilter.new(1000))

Advanced Usage

There are a number of ENV variables that control things within this gem. All of them can be found, along with their default values, in lib/kettle/soup/cover.rb.

Handy List of ENV Variables

Most are self explanatory. I tried to follow POLS, the principle of least surprise, so they mostly DWTFYT. Want to help improve this documentation? PRs are easy!

K_SOUP_COV_COMMAND_NAME
K_SOUP_COV_DEBUG
K_SOUP_COV_DIR
K_SOUP_COV_DO
K_SOUP_COV_FILTER_DIRS
K_SOUP_COV_FORMATTERS
K_SOUP_COV_MERGE_TIMEOUT
K_SOUP_COV_MIN_BRANCH
K_SOUP_COV_MIN_HARD
K_SOUP_COV_MIN_LINE
K_SOUP_COV_MULTI_FORMATTERS
K_SOUP_COV_PREFIX
K_SOUP_COV_USE_MERGING
K_SOUP_COV_VERBOSE

Additionally, some of the included gems, like simplecov-console, have their own complete suite of ENV variables you can configure.

๐Ÿ” Security

See SECURITY.md.

๐Ÿค Contributing

If you need some ideas of where to help, you could work on adding more code coverage, or if it is already ๐Ÿ’ฏ (see below) check TODOs (see below), or check issues, or PRs, or use the gem and think about how it could be better.

We Keep A Changelog so if you make changes, remember to update it.

See CONTRIBUTING.md for more detailed instructions.

Code Coverage

Coverage Graph

๐Ÿช‡ Code of Conduct

Everyone interacting in this project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the Contributor Covenant 2.1.

๐ŸŒˆ Contributors

Contributors

Made with contributors-img.

Also see GitLab Contributors: https://gitlab.com/kettle-rb/kettle-soup-cover/-/graphs/main

โญ๏ธ Star History

Star History Chart

๐Ÿ“Œ Versioning

This Library adheres to Semantic Versioning 2.0.0. Violations of this scheme should be reported as bugs. Specifically, if a minor or patch version is released that breaks backward compatibility, a new version should be immediately released that restores compatibility. Breaking changes to the public API will only be introduced with new major versions.

๐Ÿ“Œ Is "Platform Support" part of the public API?

Yes. But I'm obligated to include notes...

SemVer should, but doesn't explicitly, say that dropping support for specific Platforms is a breaking change to an API. It is obvious to many, but not all, and since the spec is silent, the bike shedding is endless.

dropping support for a platform is both obviously and objectively a breaking change

To get a better understanding of how SemVer is intended to work over a project's lifetime, read this article from the creator of SemVer:

As a result of this policy, and the interpretive lens used by the maintainer, you can (and should) specify a dependency on these libraries using the Pessimistic Version Constraint with two digits of precision.

For example:

spec.add_dependency("kettle-soup-cover", "~> 1.0")

See CHANGELOG.md for list of releases.

๐Ÿ“„ License

The gem is available as open source under the terms of the MIT License License: MIT. See LICENSE.txt for the official Copyright Notice.

Copyright (c) 2023 - 2025 Peter H. Boling, RailsBling.com Rails Bling

๐Ÿค‘ One more thing

You made it to the bottom of the page, so perhaps you'll indulge me for another 20 seconds. I maintain many dozens of gems, including this one, because I want Ruby to be a great place for people to solve problems, big and small. Please consider supporting my efforts via the giant yellow link below, or one of the others at the head of this README.

Buy me a latte