Class: SimpleCov::RSpec

Inherits:
Object
  • Object
show all
Defined in:
lib/simplecov-rspec.rb,
lib/simplecov-rspec/uncovered_report.rb,
lib/simplecov-rspec/list_uncovered_option.rb,
lib/simplecov-rspec/described_source_files.rb,
lib/simplecov-rspec/list_uncovered_files_option.rb

Overview

Configure SimpleCov to enforce coverage thresholds for RSpec, on top of what SimpleCov itself already provides.

SimpleCov (>= 1.0) can already enforce minimum_coverage for line, branch, and method coverage, and will exit with a non-zero status when a threshold is missed. This gem layers four things SimpleCov doesn't do on its own:

  1. Suppresses coverage failures when RSpec is run in dry-run mode (e.g. from an IDE).
  2. Lists (or summarizes) the individual uncovered lines, branches, and methods.
  3. Scopes that listing to the files you name, or to the code the run described.
  4. Lets all of the above be overridden from the environment, for CI.

Simply add the line SimpleCov::RSpec.start in place of SimpleCov.start in the project's spec_helper.rb. This line must appear before the project is required.

Examples:

Initialize SimpleCov with defaults (100% line coverage required)

SimpleCov::RSpec.start

Require 100% line coverage and 90% branch coverage

SimpleCov::RSpec.start(minimum_coverage: { line: 100, branch: 90 })

List every uncovered line, branch, and method when coverage is incomplete

SimpleCov::RSpec.start(minimum_coverage: { line: 100, branch: 90 }, list_uncovered: :all)

Report only counts, with a hint on how to see the details

SimpleCov::RSpec.start(list_uncovered: :all, list_uncovered_detail: false)

Scope the listing to the code the run described

SimpleCov::RSpec.start(list_uncovered: :all, list_uncovered_files: :described)

Pass a configuration block to SimpleCov.start

SimpleCov::RSpec.start { formatter SimpleCov::Formatter::LcovFormatter }

Defined Under Namespace

Modules: DescribedSourceFiles, ListUncoveredFilesOption, ListUncoveredOption Classes: UncoveredReport

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#envHash (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The environment variables consulted for overrides



# File 'lib/simplecov-rspec.rb', line 48

#simplecov_moduleModule (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The SimpleCov module being configured



# File 'lib/simplecov-rspec.rb', line 48

#start_config_blockProc? (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

A configuration block passed through to SimpleCov.start



# File 'lib/simplecov-rspec.rb', line 48

Class Method Details

.described_source_filesArray<String>

The source files defining the classes this RSpec run described

What list_uncovered_files: :described scopes to. Call it directly to build a scope of your own — to add files the run touches but does not describe, say:

list_uncovered_files: -> { SimpleCov::RSpec.described_source_files + ['lib/support.rb'] }

Only meaningful once the run has defined its examples, which is why it is passed as a callable rather than called at start.

A described class contributes nothing when it is anonymous, defined in C, or no longer reachable by name, since there is no source file to report on.

Examples:

Scope the listing to the code under test, plus one more file

SimpleCov::RSpec.start(
  list_uncovered: :all,
  list_uncovered_files: -> { SimpleCov::RSpec.described_source_files + ['lib/support.rb'] }
)


199
# File 'lib/simplecov-rspec.rb', line 199

def self.described_source_files = DescribedSourceFiles.call

.start(minimum_coverage: { line: 100 }, fail_on_low_coverage: true, list_uncovered: false, list_uncovered_detail: true, rspec_dry_run: ::RSpec.configuration.dry_run?, env: ENV, &start_config_block) ⇒ Void

Configure and start SimpleCov for RSpec

Examples:

Initialize SimpleCov with defaults

SimpleCov::RSpec.start

Examples:

Initialize SimpleCov with a test coverage threshold other than 100%

SimpleCov::RSpec.start(minimum_coverage: 90)

Initialize SimpleCov to not fail the test run if the coverage is below the threshold

SimpleCov::RSpec.start(fail_on_low_coverage: false)

# OR use an environment variable to override the default
FAIL_ON_LOW_COVERAGE=true rspec

Initialize SimpleCov to list the lines, branches, and methods not covered by tests

SimpleCov::RSpec.start(list_uncovered: :all)

# OR use an environment variable to override the default
LIST_UNCOVERED=all rspec

List uncovered items for one file only

SimpleCov::RSpec.start(list_uncovered: :all, list_uncovered_files: 'lib/example_project/parser.rb')

# OR use an environment variable to override the default
LIST_UNCOVERED_FILES=lib/example_project/parser.rb rspec

Scope the listing to the classes the run actually described

SimpleCov::RSpec.start(list_uncovered: :all, list_uncovered_files: :described)

# OR use an environment variable to override the default
LIST_UNCOVERED_FILES=described rspec


174
# File 'lib/simplecov-rspec.rb', line 174

def self.start(...) = new(...).send(:start)