Sha256: 5013abc7c8b6f2be0af48fb26141a6fb96d0424177e36ba1dad3a73a59e27210

Contents?: true

Size: 1.64 KB

Versions: 8

Compression:

Stored size: 1.64 KB

Contents

module RCov
  # 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.
  class VerifyTask < Rake::TaskLib
    # Name of the task. Defaults to :verify_rcov
    attr_accessor :name
    
    # Path to the index.html file generated by RCov, which
    # is the file containing the total coverage.
    # Defaults to 'coverage/index.html'
    attr_accessor :index_html
    
    # Whether or not to output details. Defaults to true.
    attr_accessor :verbose
    
    # The threshold value (in percent) for coverage. If the 
    # actual coverage is not equal to this value, the task will raise an 
    # exception. 
    attr_accessor :threshold
    
    def initialize(name=:verify_rcov)
      @name = name
      @index_html = 'coverage/index.html'
      @verbose = true
      yield self if block_given?
      raise "Threshold must be set" if @threshold.nil?
      define
    end
    
    def define
      desc "Verify that rcov coverage is at least #{threshold}%"
      task @name do
        total_coverage = nil
        File.open(index_html).each_line do |line|
          if line =~ /<tt.*>(\d+\.\d+)%<\/tt>&nbsp;<\/td>/
            total_coverage = eval($1)
            break
          end
        end
        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
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 3 rubygems

Version Path
puppet-0.22.4 test/lib/spec/rake/verify_rcov.rb
puppet-0.23.0 test/lib/spec/rake/verify_rcov.rb
puppet-0.23.1 test/lib/spec/rake/verify_rcov.rb
puppet-0.23.2 test/lib/spec/rake/verify_rcov.rb
riess-0.0.8 vendor/rspec-0.8.2/lib/spec/rake/verify_rcov.rb
rspec-0.8.0 lib/spec/rake/verify_rcov.rb
rspec-0.8.1 lib/spec/rake/verify_rcov.rb
rspec-0.8.2 lib/spec/rake/verify_rcov.rb