Class: Coco::Configuration

Inherits:
Hash
  • Object
show all
Defined in:
lib/coco/configuration.rb

Overview

Public: I know the configuration of coco. You can override the default configuration by putting a ‘.coco.yml’ file in YAML format in the project root directory.

Examples

# Read the threshold value
config = Configuration.new
config[:threshold]
# => 100

# To override the threshold, put this line in '.coco.yml' file:
# :threshold: 70

Note you can set the threshold above 100% (to be sure to see all files) but you cannot set it under 0.

Constant Summary collapse

DEFAULT_OPTIONS =
{
  threshold: 100,
  include: ['lib'],
  exclude: %w( spec test ),
  single_line_report: true,
  always_run: true,
  show_link_in_terminal: false,
  exclude_above_threshold: true,
  theme: 'light',
  exit_if_coverage_below: 0,
}.freeze

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Public: Initialize a Configuration.



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/coco/configuration.rb', line 38

def initialize
  merge!(DEFAULT_OPTIONS)
  if File.exist?('.coco.yml')
    merge!(YAML.load_file('.coco.yml'))
  # Deprecated: Support of '.coco' file will be removed in v1.0.
  elsif File.exist?('.coco')
    warn(DeprecatedMessage.for_legacy_config_file)
    merge!(YAML.load_file('.coco'))
  end

  ensure_known_theme
  ensure_threeshold_compatibility
  ensure_directories_compatibility
  ensure_excludes_compatibility
  expand_directories
  remove_directories
end

Instance Method Details

#run_this_time?Boolean

Public: Code coverage not have to run with every test/spec runs.

Here are the rules: If the configuration key :always_run is set to true, we always run the coverage. In case the configuration key :always_run is set to false, we have to check for an environment variable named ‘COCO’ to decide if we launch the coverage or not. When ‘COCO’ doesn’t exist, or is the empty string, or ‘0’, or ‘false’, we don’t run coverage. When ‘COCO’ is set to any other value, we start coverage.

Returns true if coverage should start.

Returns:

  • (Boolean)


68
69
70
71
72
73
74
# File 'lib/coco/configuration.rb', line 68

def run_this_time?
  if self[:always_run]
    true
  else
    ![nil, '', '0', 'false'].include?(ENV['COCO'])
  end
end