Class: SimpleCov::RSpec

Inherits:
Object
  • Object
show all
Defined in:
lib/simplecov-rspec.rb

Overview

Configure SimpleCov to fail RSpec if the test coverage falls below a given threshold

Configures RSpec to:

  1. Fail (and exit with with a non-zero exitcode) if the test coverage is below the configured threshold and
  2. (optionally) list the lines of code not covered by tests.

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

SimpleCov::RSpec.start

Initialize SimpleCov with a test coverage threshold other than 100%

SimpleCov::RSpec.start(coverage_threshold: 90, fail_on_low_coverage: true, list_uncovered_lines: false)

Pass a configuration block to SimpleCov::RSpec.start

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

Bash script to run tests in an infinite loop writing failures to fail.txt:

while true; do FAIL_ON_LOW_COVERAGE=TRUE rspec >> fail.txt; done

Defined Under Namespace

Classes: UncoveredLine

Class Method Summary collapse

Class Method Details

.start(coverage_threshold: 100, fail_on_low_coverage: true, list_uncovered_lines: false, 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(coverage_threshold: 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
ENV['FAIL_ON_LOW_COVERAGE'] = 'true'
SimpleCov::RSpec.start

# OR use an environment variable to override the default from the rspec command line
FAIL_ON_LOW_COVERAGE=TRUE rspec

Initialize SimpleCov to list the lines not covered by tests

SimpleCov::RSpec.start(list_uncovered_lines: true)

# OR use an environment variable to override the default
ENV['LIST_UNCOVERED_LINES'] = 'true'
SimpleCov::RSpec.start

# OR use an environment variable to override the default from the rspec command line
LIST_UNCOVERED_LINES=TRUE rspec


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

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