Class RCov::VerifyTask

  1. 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.


public class

  1. new

public instance

  1. define


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
require_exact_threshold [RW] Require the threshold value be met exactly. This is the default.
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

new (name=:verify_rcov) {|self if block_given?| ...}
[show source]
# File lib/spec/rake/verify_rcov.rb, line 25
    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?

Public instance methods

define ()
[show source]
# File lib/spec/rake/verify_rcov.rb, line 35
    def define
      desc "Verify that rcov coverage is at least #{threshold}%"
      task @name do
        total_coverage = 0 do |line|
          if line =~ /<tt class='coverage_total'>\s*(\d+\.\d+)%\s*<\/tt>/
            total_coverage = $1.to_f
        puts "Coverage: #{total_coverage}% (threshold: #{threshold}%)" if verbose
        raise "Coverage must be at least #{threshold}% but was #{total_coverage}%" if total_coverage < threshold
        raise "Coverage has increased above the threshold of #{threshold}% to #{total_coverage}%. You should update your threshold value." if (total_coverage > threshold) and require_exact_threshold