class Coco::Project

A project reports statistics about the code coverage.

Constants

EXIT_ON_LOW_COVERAGE_CODE

Public Class Methods

new(raw_result, out) click to toggle source
# File lib/coco/project.rb, line 16
def initialize(raw_result, out)
  @raw_result = raw_result
  @out = out
  @config = Configuration.new
end
run(raw_result, out = STDOUT) click to toggle source

raw_result - The hash obtain by the call to `Coverage.result`. out - The output where results will be displayed, by

default this is stdout.
# File lib/coco/project.rb, line 12
def self.run(raw_result, out = STDOUT)
  new(raw_result, out).run
end

Public Instance Methods

run() click to toggle source
# File lib/coco/project.rb, line 22
def run
  return unless @config.run_this_time?

  report_on_console
  report_in_html

  maybe_exit_if_low_coverage
end

Private Instance Methods

coverage_is_satisfying?() click to toggle source
# File lib/coco/project.rb, line 43
def coverage_is_satisfying?
  Summary.new(result, uncovered).average >= @config[:exit_if_coverage_below]
end
maybe_exit_if_low_coverage() click to toggle source
# File lib/coco/project.rb, line 33
def maybe_exit_if_low_coverage
  return if coverage_is_satisfying?

  message = "Sadly, the code coverage is below the required value of " +
            "#{@config[:exit_if_coverage_below]}%"
  @out.puts ColoredString.new(message).red

  exit(EXIT_ON_LOW_COVERAGE_CODE)
end
report_code_files() click to toggle source
# File lib/coco/project.rb, line 59
def report_code_files
  files = HtmlFormatter.new(result.coverable_files).format
  HtmlFilesWriter.new(files, @config[:theme]).write
end
report_in_html() click to toggle source
# File lib/coco/project.rb, line 54
def report_in_html
  report_code_files
  report_index
end
report_index() click to toggle source
# File lib/coco/project.rb, line 64
def report_index
  index = HtmlIndexFormatter.new(uncovered, result,
                                 @config[:threshold]).format
  HtmlIndexWriter.new(index).write
end
report_on_console() click to toggle source
# File lib/coco/project.rb, line 47
def report_on_console
  formatter = ConsoleFormatter.new(uncovered, @config[:threshold],
                                   result, @config)
  @out.puts formatter.format
  @out.puts formatter.link if @config[:show_link_in_terminal]
end
result() click to toggle source
# File lib/coco/project.rb, line 70
def result
  @result ||= CoverageResult.new(@config, @raw_result)
end
sources() click to toggle source
# File lib/coco/project.rb, line 78
def sources
  SourceLister.new(@config).list
end
uncovered() click to toggle source
# File lib/coco/project.rb, line 74
def uncovered
  @uncovered ||= UncoveredLister.new(sources, result.coverable_files).list
end