Sha256: 58843ade46f104262cb4fcb295b541ba006540a845b573a65d188a9e4fc1772d

Contents?: true

Size: 1.35 KB

Versions: 16

Compression:

Stored size: 1.35 KB

Contents

require 'colored'

# @private
module RCov

  class VerifyTask < Rake::TaskLib

    attr_accessor :name
    attr_accessor :index_html
    attr_accessor :verbose
    attr_accessor :threshold
    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
        output_coverage(total_coverage)
      end
    end

    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
  end
end

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
formtastic-2.2.1 lib/tasks/verify_rcov.rb
formtastic-2.2.0 lib/tasks/verify_rcov.rb
formtastic-2.2.0.rc lib/tasks/verify_rcov.rb
formtastic-2.1.1 lib/tasks/verify_rcov.rb
formtastic-2.1.0 lib/tasks/verify_rcov.rb
formtastic-2.1.0.rc lib/tasks/verify_rcov.rb
formtastic-2.1.0.beta1 lib/tasks/verify_rcov.rb
formtastic-2.0.2 lib/tasks/verify_rcov.rb
formtastic-2.0.1 lib/tasks/verify_rcov.rb
formtastic-2.0.0 lib/tasks/verify_rcov.rb
formtastic-2.0.0.rc5 lib/tasks/verify_rcov.rb
formtastic-2.0.0.rc4 lib/tasks/verify_rcov.rb
formtastic-2.0.0.rc3 lib/tasks/verify_rcov.rb
formtastic-2.0.0.rc2 lib/tasks/verify_rcov.rb
formtastic-2.0.0.rc1 lib/tasks/verify_rcov.rb
nuatt-formtastic-0.2.3 lib/tasks/verify_rcov.rb