Class: RCov::VerifyTask

Inherits:
Rake::TaskLib
  • Object
show all
Defined in:
lib/tasks/verify_rcov.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = :verify_rcov) {|_self| ... } ⇒ VerifyTask

Returns a new instance of VerifyTask.

Yields:

  • (_self)

Yield Parameters:



14
15
16
17
18
19
20
21
22
# File 'lib/tasks/verify_rcov.rb', line 14

def initialize(name=:verify_rcov)
  @name = name
  @index_html = 'coverage/index.html'
  @verbose = true
  @require_exact_threshold = true
  yield self if block_given?
  raise "Threshold must be set" if @threshold.nil?
  define
end

Instance Attribute Details

#index_htmlObject

Returns the value of attribute index_html.



9
10
11
# File 'lib/tasks/verify_rcov.rb', line 9

def index_html
  @index_html
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#require_exact_thresholdObject

Returns the value of attribute require_exact_threshold.



12
13
14
# File 'lib/tasks/verify_rcov.rb', line 12

def require_exact_threshold
  @require_exact_threshold
end

#thresholdObject

Returns the value of attribute threshold.



11
12
13
# File 'lib/tasks/verify_rcov.rb', line 11

def threshold
  @threshold
end

#verboseObject

Returns the value of attribute verbose.



10
11
12
# File 'lib/tasks/verify_rcov.rb', line 10

def verbose
  @verbose
end

Instance Method Details

#defineObject



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/tasks/verify_rcov.rb', line 24

def define
  desc "Verify that rcov coverage is at least #{threshold}%"
  task @name do
    total_coverage = 0
    File.open(index_html).each_line do |line|
      if line =~ /<tt class='coverage_total'>\s*(\d+\.\d+)%\s*<\/tt>/
        total_coverage = $1.to_f
        break
      end
    end
    output_coverage(total_coverage)
  end
end

#output_coverage(total_coverage) ⇒ Object



38
39
40
41
42
# File 'lib/tasks/verify_rcov.rb', line 38

def output_coverage(total_coverage)
  puts "Coverage: #{total_coverage}% (threshold: #{threshold}%)".green if verbose && total_coverage >= threshold
  raise "Coverage must be at least #{threshold}% but was #{total_coverage}%".red if total_coverage < threshold
  raise "Coverage has increased above the threshold of #{threshold}% to #{total_coverage}%. You should update your threshold value.".red if (total_coverage > threshold) and require_exact_threshold
end