Class: RCov::VerifyTask
- Defined in:
- lib/spec/rake/verify_rcov.rb
Overview
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.
Instance Attribute Summary collapse
-
#index_html ⇒ Object
Path to the index.html file generated by RCov, which is the file containing the total coverage.
-
#name ⇒ Object
Name of the task.
-
#threshold ⇒ Object
The threshold value (in percent) for coverage.
-
#verbose ⇒ Object
Whether or not to output details.
Instance Method Summary collapse
- #define ⇒ Object
-
#initialize(name = :verify_rcov) {|_self| ... } ⇒ VerifyTask
constructor
A new instance of VerifyTask.
Constructor Details
#initialize(name = :verify_rcov) {|_self| ... } ⇒ VerifyTask
Returns a new instance of VerifyTask.
22 23 24 25 26 27 28 29 |
# File 'lib/spec/rake/verify_rcov.rb', line 22 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 |
Instance Attribute Details
#index_html ⇒ Object
Path to the index.html file generated by RCov, which is the file containing the total coverage. Defaults to ‘coverage/index.html’
12 13 14 |
# File 'lib/spec/rake/verify_rcov.rb', line 12 def index_html @index_html end |
#name ⇒ Object
Name of the task. Defaults to :verify_rcov
7 8 9 |
# File 'lib/spec/rake/verify_rcov.rb', line 7 def name @name end |
#threshold ⇒ Object
The threshold value (in percent) for coverage. If the actual coverage is not equal to this value, the task will raise an exception.
20 21 22 |
# File 'lib/spec/rake/verify_rcov.rb', line 20 def threshold @threshold end |
#verbose ⇒ Object
Whether or not to output details. Defaults to true.
15 16 17 |
# File 'lib/spec/rake/verify_rcov.rb', line 15 def verbose @verbose end |
Instance Method Details
#define ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/spec/rake/verify_rcov.rb', line 31 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> <\/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 |