Class: Autocoverage

Inherits:
Auto show all
Defined in:
lib/autocoverage.rb

Direct Known Subclasses

Rspec

Defined Under Namespace

Classes: Rspec

Constant Summary

Constants inherited from Auto

Auto::SEP, Auto::WINDOZE

Instance Attribute Summary collapse

Attributes inherited from Auto

#file_masks, #modified, #output, #sleep, #wants_to_quit, #working_dirs

Instance Method Summary collapse

Methods inherited from Auto

add_discovery, add_hook, autodiscover, #find_files, #hook, #last_modified_time, #method_missing, #old_method_missing, #reset, run, #run, #run_metric, #wait_for_changes

Constructor Details

#initialize(*args) ⇒ Autocoverage

Returns a new instance of Autocoverage.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/autocoverage.rb', line 10

def initialize(*args)
  super(*args)
  
  @threshold = 100.0
  @opts = ["--no-html", "--text-report", "--exclude", "#{test_runner},test,examples"]
  @previous_coverage = nil
  @working_dirs = %w( lib test )

  @file_masks = {
    :lib => /^lib\/.*\.rb$/,
    :test => /^test\/(.*\/)?test_.*rb$/
  }
  
  hook :initialize
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Auto

Instance Attribute Details

#coverageObject

Returns the value of attribute coverage.



8
9
10
# File 'lib/autocoverage.rb', line 8

def coverage
  @coverage
end

#previous_coverageObject

Returns the value of attribute previous_coverage.



8
9
10
# File 'lib/autocoverage.rb', line 8

def previous_coverage
  @previous_coverage
end

#thresholdObject

Returns the value of attribute threshold.



8
9
10
# File 'lib/autocoverage.rb', line 8

def threshold
  @threshold
end

Instance Method Details

#coverage_results(results) ⇒ Object



55
56
57
# File 'lib/autocoverage.rb', line 55

def coverage_results(results)
  results.scan(/^\d{0,3}\.\d+%\s+\d+ file\(s\)\s+\d+ Lines\s+\d+ LOC$/)
end

#handle_results(results) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/autocoverage.rb', line 32

def handle_results(results)
  coverage_result = coverage_results(results).first
  return if coverage_result.nil?
  
  @coverage = coverage_result.scan(/^\d{0,3}\.\d+/).first.to_f
  
  if @threshold > @coverage
    hook :failed
  else
    hook :passed
  end
  
  if @previous_coverage
    if @previous_coverage < @coverage
      hook :increased
    elsif @previous_coverage > @coverage
      hook :decreased
    end
  end
  
  @previous_coverage = @coverage
end

#make_cmdObject



26
27
28
# File 'lib/autocoverage.rb', line 26

def make_cmd
  "#{ruby} -S \"#{rcov}\" #{@opts.join(' ')} #{test_runner} -- #{test_files.join(' ')}"
end