Class: RCov::VerifyTask
- Inherits:
-
Rake::TaskLib
- Object
- Rake::TaskLib
- RCov::VerifyTask
- Defined in:
- lib/tasks/verify_rcov.rb
Instance Attribute Summary collapse
-
#index_html ⇒ Object
Returns the value of attribute index_html.
-
#name ⇒ Object
Returns the value of attribute name.
-
#require_exact_threshold ⇒ Object
Returns the value of attribute require_exact_threshold.
-
#threshold ⇒ Object
Returns the value of attribute threshold.
-
#verbose ⇒ Object
Returns the value of attribute verbose.
Instance Method Summary collapse
- #define ⇒ Object
-
#initialize(name = :verify_rcov) {|_self| ... } ⇒ VerifyTask
constructor
A new instance of VerifyTask.
- #output_coverage(total_coverage) ⇒ Object
Constructor Details
#initialize(name = :verify_rcov) {|_self| ... } ⇒ VerifyTask
Returns a new instance of VerifyTask.
14 15 16 17 18 19 20 21 22 |
# File 'lib/tasks/verify_rcov.rb', line 14 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 |
Instance Attribute Details
#index_html ⇒ Object
Returns the value of attribute index_html.
9 10 11 |
# File 'lib/tasks/verify_rcov.rb', line 9 def index_html @index_html end |
#name ⇒ Object
Returns the value of attribute name.
8 9 10 |
# File 'lib/tasks/verify_rcov.rb', line 8 def name @name end |
#require_exact_threshold ⇒ Object
Returns the value of attribute require_exact_threshold.
12 13 14 |
# File 'lib/tasks/verify_rcov.rb', line 12 def require_exact_threshold @require_exact_threshold end |
#threshold ⇒ Object
Returns the value of attribute threshold.
11 12 13 |
# File 'lib/tasks/verify_rcov.rb', line 11 def threshold @threshold end |
#verbose ⇒ Object
Returns the value of attribute verbose.
10 11 12 |
# File 'lib/tasks/verify_rcov.rb', line 10 def verbose @verbose end |
Instance Method Details
#define ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/tasks/verify_rcov.rb', line 24 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 |
#output_coverage(total_coverage) ⇒ Object
38 39 40 41 42 |
# File 'lib/tasks/verify_rcov.rb', line 38 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 |