Sha256: d6329f0488a2cb545be6573cac8668016af8365acca436d1dc378b8000c0d616

Contents?: true

Size: 1.84 KB

Versions: 92

Compression:

Stored size: 1.84 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
    
    # Require the threshold value be met exactly.  This is the default.
    attr_accessor :require_exact_threshold
    
    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
    
    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
        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
      end
    end
  end
end

Version data entries

92 entries across 92 versions & 20 rubygems

Version Path
hubbub-0.0.8 lib/vendor/plugins/rspec/lib/spec/rake/verify_rcov.rb
hubbub-0.0.6 lib/vendor/plugins/rspec/lib/spec/rake/verify_rcov.rb
simple-templater-0.0.1.4 gems/gems/rspec-1.2.9/lib/spec/rake/verify_rcov.rb
media-path-0.1.2 vendor/rspec/lib/spec/rake/verify_rcov.rb
simple-templater-0.0.1.3 vendor/rspec/lib/spec/rake/verify_rcov.rb
pupu-0.0.2.pre vendor/rspec/lib/spec/rake/verify_rcov.rb
media-path-0.1.1.pre vendor/rspec/lib/spec/rake/verify_rcov.rb
simple-templater-0.0.1.2 vendor/rspec/lib/spec/rake/verify_rcov.rb
media-path-0.1.1 vendor/rspec/lib/spec/rake/verify_rcov.rb
simple-templater-0.0.1.1 vendor/rspec/lib/spec/rake/verify_rcov.rb
pupu-0.0.2 vendor/rspec/lib/spec/rake/verify_rcov.rb
rango-0.0.6 vendor/rspec/lib/spec/rake/verify_rcov.rb
rango-0.1.pre vendor/rspec/lib/spec/rake/verify_rcov.rb
pupu-0.0.1 vendor/rspec/lib/spec/rake/verify_rcov.rb
media-path-0.1 vendor/rspec/lib/spec/rake/verify_rcov.rb
simple-templater-0.0.1 vendor/rspec/lib/spec/rake/verify_rcov.rb
merb-core-1.1.0.pre spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/lib/spec/rake/verify_rcov.rb
middleman-0.10.17 vendor/gems/gems/rspec-1.2.9/lib/spec/rake/verify_rcov.rb
middleman-0.10.16 vendor/gems/gems/rspec-1.2.9/lib/spec/rake/verify_rcov.rb
middleman-0.10.15 vendor/gems/gems/rspec-1.2.9/lib/spec/rake/verify_rcov.rb