Class RCov::VerifyTask
In: lib/spec/rake/verify_rcov.rb
Parent: Rake::TaskLib

A task that can verify that the RCov coverage doesn‘t drop below a certain threshold. It should be run after running Spec::Rake::SpecTask.

Methods

define   new  

Attributes

index_html  [RW]  Path to the index.html file generated by RCov, which is the file containing the total coverage. Defaults to ‘coverage/index.html‘
name  [RW]  Name of the task. Defaults to :verify_rcov
threshold  [RW]  The threshold value (in percent) for coverage. If the actual coverage is not equal to this value, the task will raise an exception.
verbose  [RW]  Whether or not to output details. Defaults to true.

Public Class methods

[Source]

    # File lib/spec/rake/verify_rcov.rb, line 22
22:     def initialize(name=:verify_rcov)
23:       @name = name
24:       @index_html = 'coverage/index.html'
25:       @verbose = true
26:       yield self if block_given?
27:       raise "Threshold must be set" if @threshold.nil?
28:       define
29:     end

Public Instance methods

[Source]

    # File lib/spec/rake/verify_rcov.rb, line 31
31:     def define
32:       desc "Verify that rcov coverage is at least #{threshold}%"
33:       task @name do
34:         total_coverage = nil
35:         File.open(index_html).each_line do |line|
36:           if line =~ /<tt>(\d+\.\d+)%<\/tt>&nbsp;<\/td>/
37:             total_coverage = eval($1)
38:             break
39:           end
40:         end
41:         puts "Coverage: #{total_coverage}% (threshold: #{threshold}%)" if verbose
42:         raise "Coverage must be at least #{threshold}% but was #{total_coverage}%" if total_coverage < threshold
43:         raise "Coverage has increased above the threshold of #{threshold}% to #{total_coverage}%. You should update your threshold value." if total_coverage > threshold
44:       end
45:     end

[Validate]