Module: Minitest::Cc

Defined in:
lib/minitest/cc.rb,
lib/minitest/cc/version.rb,
lib/minitest/cc/reporter.rb,
lib/minitest/cc/file_array.rb,
lib/minitest/cc/file_coverage.rb

Overview

Main module of the plugin

Author:

  • Andres

Defined Under Namespace

Classes: FileArray, FileCoverage, Reporter

Constant Summary collapse

MODES =
%i[lines branches methods].freeze
VERSION =

plugin version

'1.0.0'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.cattr_accessor(name) ⇒ Object

:nodoc:



20
21
22
# File 'lib/minitest/cc.rb', line 20

def self.cattr_accessor(name) # :nodoc:
  (class << self; self; end).attr_accessor name
end

.peek_resultObject

This method populate the FileArray variable with results



77
78
79
80
81
82
83
# File 'lib/minitest/cc.rb', line 77

def peek_result
  @results = Coverage.result
  Dir.glob(tracked_files.each { |f| File.expand_path(f) }).each do |d|
    full_path = File.expand_path(d)
    @files << FileCoverage.new(full_path, d, result_for_file(full_path))
  end
end

.result_for_file(file_path) ⇒ Hash?

Find the result for a file with the full path if the file was not tracked by Coverage this will return nil

Parameters:

  • file_path (String)

    Absolute path to the file

Returns:

  • (Hash, nil)

    Object with all the results for the selected file or nil



90
91
92
93
94
# File 'lib/minitest/cc.rb', line 90

def result_for_file(file_path)
  return if @results.empty?

  @results[file_path]
end

.resumeString

compose the string with resume of cc

Returns:

  • (String)

    String with averages



99
100
101
102
103
104
105
# File 'lib/minitest/cc.rb', line 99

def resume
  str = ''
  str += "Lines: #{@files.lines_average.round(2).to_s_color}%\t" if coverage_mode.include? :lines
  str += "Branches: #{@files.branches_average.round(2).to_s_color}%\t" if coverage_mode.include? :branches
  str += "Methods: #{@files.methods_average.round(2).to_s_color}%\t" if coverage_mode.include? :methods
  str
end

.start(*args) ⇒ Object

start coverage process this method recive the arguments direct and not depend on set coverage mode before start



56
57
58
59
# File 'lib/minitest/cc.rb', line 56

def start(*args)
  @coverage_mode = args.collect(&:to_sym).select { |a| MODES.include? a } unless args.empty?
  Coverage.start(@coverage_mode.collect { |m| [m, true] }.to_h)
end

.start_coverageObject

Deprecated.

Use Minitest::Cc#self#self.start(*args) instead.

Start the coverage process



46
47
48
# File 'lib/minitest/cc.rb', line 46

def start_coverage
  Coverage.start(@coverage_mode.collect { |m| [m, true] }.to_h)
end

.summaryObject

Print results after the runs



64
65
66
67
68
69
70
71
72
73
# File 'lib/minitest/cc.rb', line 64

def summary
  puts "\n\n# Coverage:\n\n"
  case cc_mode
  when :per_file
    @files.each { |f| puts f.to_s }
  else
    puts resume
  end
  puts "\nAverage: #{@files.total_coverage_percent.round(2).to_s_color}%"
end

Instance Method Details

#cc_modeSymbol

Returns mode of the summary. Could be :resume or :per_file.

Returns:

  • (Symbol)

    mode of the summary. Could be :resume or :per_file



25
# File 'lib/minitest/cc.rb', line 25

cattr_accessor :cc_mode

#coverage_modeArray

Returns mode of the coverage, this array could contain: :lines, :branches, :methods.

Returns:

  • (Array)

    mode of the coverage, this array could contain: :lines, :branches, :methods



37
# File 'lib/minitest/cc.rb', line 37

cattr_accessor :coverage_mode

#tracked_filesArray

Returns pattern to find files that must be cover by the tests.

Returns:

  • (Array)

    pattern to find files that must be cover by the tests



29
# File 'lib/minitest/cc.rb', line 29

cattr_accessor :tracked_files