module SimpleCov::Configuration

def adapters

def adapters
  warn "#{Kernel.caller.first}: [DEPRECATION] #adapters is deprecated. Use #profiles instead."
  profiles
end

def add_filter(filter_argument = nil, &filter_proc)


on how to define your own filter classes
* as an instance of a subclass of SimpleCov::Filter. See the documentation there
SimpleCov.add_filter ['app/models', 'app/helpers'] # ignores both dirs
paths and then ignored (basically string filter multiple times)
* as an array of strings that are matched against all sorce files' file
end # Will exclude environment.rb files from the results
File.basename(src_file.filename) == 'environment.rb'
SimpleCov.add_filter do |src_file|
return a true or false value, depending on whether the file should be removed
* as a block which will be passed the source file in question and should either
SimpleCov.add_filter 'app/models' # will reject all your models
* as a String that will then be matched against all source files' file paths,

There are four ways to define a filter:
Add a filter to the processing chain.
def add_filter(filter_argument = nil, &filter_proc)
  filters << parse_filter(filter_argument, &filter_proc)
end

def add_group(group_name, filter_argument = nil, &filter_proc)


(while filters exclude when the filter is applicable).
argument is the desired group name and files PASSING the filter end up in the group
Define a group for files. Works similar to add_filter, only that the first
def add_group(group_name, filter_argument = nil, &filter_proc)
  groups[group_name] = parse_filter(filter_argument, &filter_proc)
end

def at_exit(&block)


end
SimpleCov.result.format!
puts "Coverage done"
SimpleCov.at_exit do

Configure with:

By default, it will call SimpleCov.result.format!

Gets or sets the behavior to process coverage results.
def at_exit(&block)
  return proc {} unless running || block_given?
  @at_exit = block if block_given?
  @at_exit ||= proc { SimpleCov.result.format! }
end

def branch_coverage?

def branch_coverage?
  branch_coverage_supported? && coverage_criterion_enabled?(:branch)
end

def clear_coverage_criteria

def clear_coverage_criteria
  @coverage_criteria = nil
end

def command_name(name = nil)

also check out the corresponding section in README.rdoc
You can specify it manually with SimpleCov.command_name("test:units") - please

is set to the shell command that the current suite is running on.
them properly. If it fails to recognize the current command, the command name
unit tests, functional tests, integration tests, rpsec and cucumber and label
arguments the current test suite is running on and should automatically detect
merging and caching. It first tries to make a guess based upon the command line
The name of the command (a.k.a. Test Suite) currently running. Used for result
def command_name(name = nil)
  @name = name unless name.nil?
  @name ||= SimpleCov::CommandGuesser.guess
  @name
end

def configure(&block)


options at once.
This is equivalent to SimpleCov.add_filter 'foobar' and thus makes it easier to set a bunch of configure

end
add_filter 'foobar'
SimpleCov.configure do

you're calling.
Allows you to configure simplecov in a block instead of prepending SimpleCov to all config methods
def configure(&block)
  Docile.dsl_eval(self, &block)
end

def coverage_criteria

def coverage_criteria
  @coverage_criteria ||= Set[DEFAULT_COVERAGE_CRITERION]
end

def coverage_criterion(criterion = nil)

Parameters:
  • criterion (Symbol) --
def coverage_criterion(criterion = nil)
  return @coverage_criterion ||= DEFAULT_COVERAGE_CRITERION unless criterion
  raise_if_criterion_unsupported(criterion)
  @coverage_criterion = criterion
end

def coverage_criterion_enabled?(criterion)

def coverage_criterion_enabled?(criterion)
  coverage_criteria.member?(criterion)
end

def coverage_dir(dir = nil)


Configure with SimpleCov.coverage_dir('cov')

The name of the output and cache directory. Defaults to 'coverage'
def coverage_dir(dir = nil)
  return @coverage_dir if defined?(@coverage_dir) && dir.nil?
  @coverage_path = nil # invalidate cache
  @coverage_dir = (dir || "coverage")
end

def coverage_path


values. Will create the directory if it's missing
and SimpleCov.coverage_dir, so you can adjust this by configuring those
Returns the full path to the output directory using SimpleCov.root
def coverage_path
  @coverage_path ||= begin
    coverage_path = File.expand_path(coverage_dir, root)
    FileUtils.mkdir_p coverage_path
    coverage_path
  end
end

def coverage_start_arguments_supported?

def coverage_start_arguments_supported?
  # safe to cache as within one process this value should never
  # change
  return @coverage_start_arguments_supported if defined?(@coverage_start_arguments_supported)
  @coverage_start_arguments_supported = begin
    require "coverage"
    !Coverage.method(:start).arity.zero?
  end
end

def enable_coverage(criterion)

def enable_coverage(criterion)
  raise_if_criterion_unsupported(criterion)
  coverage_criteria << criterion
end

def filters


Returns the list of configured filters. Add filters using SimpleCov.add_filter.
def filters
  @filters ||= []
end

def formatter(formatter = nil)


Configure with: SimpleCov.formatter(SimpleCov::Formatter::SimpleFormatter)

Gets or sets the configured formatter.
def formatter(formatter = nil)
  return @formatter if defined?(@formatter) && formatter.nil?
  @formatter = formatter
  raise "No formatter configured. Please specify a formatter using SimpleCov.formatter = SimpleCov::Formatter::SimpleFormatter" unless @formatter
  @formatter
end

def formatters


Gets the configured formatters.
def formatters
  if @formatter.is_a?(SimpleCov::Formatter::MultiFormatter)
    @formatter.formatters
  else
    Array(formatter)
  end
end

def formatters=(formatters)


Sets the configured formatters.
def formatters=(formatters)
  @formatter = SimpleCov::Formatter::MultiFormatter.new(formatters)
end

def groups


Returns the configured groups. Add groups using SimpleCov.add_group
def groups
  @groups ||= {}
end

def maximum_coverage_drop(coverage_drop = nil)


Default is 100% (disabled)

SimpleCov will return non-zero if the coverage decreases by more than this threshold.
Defines the maximum coverage drop at once allowed for the testsuite to pass.
def maximum_coverage_drop(coverage_drop = nil)
  @maximum_coverage_drop ||= (coverage_drop || 100).to_f.round(2)
end

def merge_timeout(seconds = nil)


Configure with SimpleCov.merge_timeout(3600) # 1hr

Default is 600 seconds (10 minutes)

Of course, this only applies when merging is active (e.g. SimpleCov.use_merging is not false!)

purged from the resultset cache)
more seconds ago than specified here, it won't be taken into account when merging (and is also
i.e. If you run cucumber features, then later rake test, if the stored cucumber resultset is
Defines the maximum age (in seconds) of a resultset to still be included in merged results.
def merge_timeout(seconds = nil)
  @merge_timeout = seconds if seconds.is_a?(Integer)
  @merge_timeout ||= 600
end

def minimum_coverage(coverage = nil)


Default is 0% (disabled)

SimpleCov will return non-zero if the current coverage is below this threshold.
Defines the minimum overall coverage required for the testsuite to pass.
def minimum_coverage(coverage = nil)
  return @minimum_coverage ||= {} unless coverage
  coverage = {DEFAULT_COVERAGE_CRITERION => coverage} if coverage.is_a?(Numeric)
  coverage.keys.each { |criterion| raise_if_criterion_disabled(criterion) }
  coverage.values.each do |percent|
    minimum_possible_coverage_exceeded("minimum_coverage") if percent && percent > 100
  end
  @minimum_coverage = coverage
end

def minimum_coverage_by_file(coverage = nil)


Default is 0% (disabled)

is below this threshold.
SimpleCov will return non-zero if the current coverage of the least covered file
Defines the minimum coverage per file required for the testsuite to pass.
def minimum_coverage_by_file(coverage = nil)
  minimum_possible_coverage_exceeded("minimum_coverage_by_file") if coverage && coverage > 100
  @minimum_coverage_by_file ||= (coverage || 0).to_f.round(2)
end

def minimum_possible_coverage_exceeded(coverage_option)

def minimum_possible_coverage_exceeded(coverage_option)
  warn "The coverage you set for #{coverage_option} is greater than 100%"
end

def nocov_token(nocov_token = nil)


Configure with SimpleCov.nocov_token('skip') or it's alias SimpleCov.skip_token('skip')

can be configured to be any other string using this.
the coverage metrics by wrapping it inside # :nocov: comment blocks. The nocov token
Certain code blocks (i.e. Ruby-implementation specific code) can be excluded from
def nocov_token(nocov_token = nil)
  return @nocov_token if defined?(@nocov_token) && nocov_token.nil?
  @nocov_token = (nocov_token || "nocov")
end

def parse_filter(filter_argument = nil, &filter_proc)


The actual filter processor. Not meant for direct use
def parse_filter(filter_argument = nil, &filter_proc)
  filter = filter_argument || filter_proc
  if filter
    SimpleCov::Filter.build_filter(filter)
  else
    raise ArgumentError, "Please specify either a filter or a block to filter with"
  end
end

def print_error_status


configured with the #print_error_status= method.
Whether we should print non-success status codes. This can be
def print_error_status
  defined?(@print_error_status) ? @print_error_status : true
end

def profiles


Returns the hash of available profiles
def profiles
  @profiles ||= SimpleCov::Profiles.new
end

def project_name(new_name = nil)


the SimpleCov.root is this.
Returns the project name - currently assuming the last dirname in
def project_name(new_name = nil)
  return @project_name if defined?(@project_name) && @project_name && new_name.nil?
  @project_name = new_name if new_name.is_a?(String)
  @project_name ||= File.basename(root.split("/").last).capitalize.tr("_", " ")
end

def raise_if_criterion_disabled(criterion)

def raise_if_criterion_disabled(criterion)
  raise_if_criterion_unsupported(criterion)
  # rubocop:disable Style/IfUnlessModifier
  unless coverage_criterion_enabled?(criterion)
    raise "Coverage criterion #{criterion}, is disabled! Please enable it first through enable_coverage #{criterion} (if supported)"
  end
  # rubocop:enable Style/IfUnlessModifier
end

def raise_if_criterion_unsupported(criterion)

def raise_if_criterion_unsupported(criterion)
  # rubocop:disable Style/IfUnlessModifier
  unless SUPPORTED_COVERAGE_CRITERIA.member?(criterion)
    raise "Unsupported coverage criterion #{criterion}, supported values are #{SUPPORTED_COVERAGE_CRITERIA}"
  end
  # rubocop:enable Style/IfUnlessModifier
end

def refuse_coverage_drop


SimpleCov will return non-zero if the coverage decreases.
Refuses any coverage drop. That is, coverage is only allowed to increase.
def refuse_coverage_drop
  maximum_coverage_drop 0
end

def root(root = nil)


Configure with SimpleCov.root('/my/project/path')

current working directory.
The root for the project. This defaults to the
def root(root = nil)
  return @root if defined?(@root) && root.nil?
  @root = File.expand_path(root || Dir.getwd)
end

def track_files(glob)


will not be present in the final report.
or not they were explicitly required. Without this, un-required files
Coverage results will always include files matched by this glob, whether
def track_files(glob)
  @tracked_files = glob
end

def tracked_files


explicitly required.
Returns the glob that will be used to include files that were not
def tracked_files
  @tracked_files if defined?(@tracked_files)
end

def use_merging(use = nil)


are joined and combined into a single coverage report
Defines whether to use result merging so all your test suites (test:units, test:functionals, cucumber, ...)
def use_merging(use = nil)
  @use_merging = use unless use.nil?
  @use_merging = true unless defined?(@use_merging) && @use_merging == false
end