Module: SimpleCov::RSpec::ListUncoveredOption Private

Defined in:
lib/simplecov-rspec/list_uncovered_option.rb

Overview

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

Resolves the list_uncovered: option (plus its LIST_UNCOVERED ENV override) into a normalized Array, in a fixed line/branch/method order.

Constant Summary collapse

ALL_CRITERIA =

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

The coverage criteria this gem knows how to report on

%i[line branch method].freeze
ALL_ENV_VALUES =

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

LIST_UNCOVERED environment variable values that mean "every criterion"

%w[yes on true 1 all].freeze
NONE_ENV_VALUES =

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

LIST_UNCOVERED environment variable values that mean "no criteria"

%w[false no off 0].freeze

Class Method Summary collapse

Class Method Details

.from_env(raw) ⇒ false, ...

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.

Parse a raw LIST_UNCOVERED environment variable value

Examples:

ListUncoveredOption.from_env('line,branch') # => [:line, :branch]

Parameters:

  • raw (String)

    the raw LIST_UNCOVERED environment variable value

Returns:

  • (false, :all, Array<Symbol>)


40
41
42
43
44
45
46
# File 'lib/simplecov-rspec/list_uncovered_option.rb', line 40

def from_env(raw)
  raw = raw.strip.downcase
  return false if raw.empty? || NONE_ENV_VALUES.include?(raw)
  return :all if ALL_ENV_VALUES.include?(raw)

  raw.split(',').map { |criterion| criterion.strip.to_sym }
end

.normalize(value) ⇒ Array<Symbol>

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.

Normalize a list_uncovered:-style value into an Array of Symbols

Examples:

ListUncoveredOption.normalize(:branch) # => [:branch]

Parameters:

  • value (false, true, :all, Symbol, Array<Symbol>)

Returns:

  • (Array<Symbol>)


53
54
55
56
57
58
59
60
61
62
63
# File 'lib/simplecov-rspec/list_uncovered_option.rb', line 53

def normalize(value)
  case value
  when nil, false then []
  when :all       then ALL_CRITERIA
  when Symbol     then validate([value])
  when Array      then validate(value)
  else
    raise ArgumentError,
          "list_uncovered must be false, :all, a Symbol, or an Array of Symbols; got #{value.inspect}"
  end
end

.resolve(value, env:, env_var:) ⇒ Array<Symbol>

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.

Resolve the effective criteria, applying the ENV override if present

Examples:

ListUncoveredOption.resolve(:all, env: {}, env_var: 'LIST_UNCOVERED') # => [:line, :branch, :method]

Parameters:

  • value (false, :all, Symbol, Array<Symbol>)

    the list_uncovered: argument

  • env (Hash)

    the environment variables

  • env_var (String)

    the ENV var name that overrides value

Returns:

  • (Array<Symbol>)

Raises:

  • (ArgumentError)

    if value is not one of the accepted forms, or names an unknown criterion



30
31
32
33
# File 'lib/simplecov-rspec/list_uncovered_option.rb', line 30

def resolve(value, env:, env_var:)
  value = from_env(env.fetch(env_var)) if env.key?(env_var)
  ALL_CRITERIA & normalize(value)
end

.validate(criteria) ⇒ Array<Symbol>

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.

Raise unless every given criterion is one this gem knows how to report on

Examples:

ListUncoveredOption.validate([:line]) # => [:line]

Parameters:

  • criteria (Array<Symbol>)

Returns:

  • (Array<Symbol>)

Raises:

  • (ArgumentError)

    if criteria contains anything outside ALL_CRITERIA



71
72
73
74
75
76
# File 'lib/simplecov-rspec/list_uncovered_option.rb', line 71

def validate(criteria)
  invalid = criteria - ALL_CRITERIA
  return criteria if invalid.empty?

  raise ArgumentError, "Unknown coverage criterion #{invalid.inspect}; must be one of #{ALL_CRITERIA.inspect}"
end