Skip to content

Commit

Permalink
Refactor Rake::Verify to use concord
Browse files Browse the repository at this point in the history
  • Loading branch information
John Backus committed Oct 5, 2015
1 parent 64fa8b3 commit 1312e7d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion config/flay.yml
@@ -1,3 +1,3 @@
---
threshold: 9
total_score: 169
total_score: 170
30 changes: 16 additions & 14 deletions lib/yardstick/rake/verify.rb
Expand Up @@ -9,6 +9,8 @@ module Yardstick
module Rake
# A rake task for verifying the doc thresholds
class Verify < ::Rake::TaskLib
include Concord.new(:name, :config, :threshold)

# Initialize a Verify task
#
# @example
Expand All @@ -29,9 +31,9 @@ class Verify < ::Rake::TaskLib
#
# @api public
def initialize(name = :verify_measurements, options = {}, &block)
@name = name
@config = Config.coerce(options, &block)
@threshold = @config.threshold
config = Config.coerce(options, &block)

super(name, config, config.threshold)

assert_threshold
define
Expand All @@ -51,7 +53,7 @@ def initialize(name = :verify_measurements, options = {}, &block)
#
# @api public
def verify_measurements
puts "YARD-Coverage: #{total_coverage}% (threshold: #{@threshold}%)" if @config.verbose?
puts "YARD-Coverage: #{total_coverage}% (threshold: #{threshold}%)" if config.verbose?
assert_meets_threshold
assert_matches_threshold
end
Expand All @@ -65,7 +67,7 @@ def verify_measurements
#
# @api private
def total_coverage
measurements = Yardstick.measure(@config)
measurements = Yardstick.measure(config)
Yardstick.round_percentage(measurements.coverage * 100)
end

Expand All @@ -77,10 +79,10 @@ def total_coverage
#
# @api private
def define
modifier = @config.require_exact_threshold? ? 'exactly' : 'at least'
modifier = config.require_exact_threshold? ? 'exactly' : 'at least'

desc "Verify that yardstick coverage is #{modifier} #{@threshold}%"
task(@name) { verify_measurements }
desc "Verify that yardstick coverage is #{modifier} #{threshold}%"
task(name) { verify_measurements }
end

# Raise an exception if threshold is not set
Expand All @@ -92,7 +94,7 @@ def define
#
# @api private
def assert_threshold
return if @threshold
return if threshold
fail 'threshold must be set'
end

Expand All @@ -106,7 +108,7 @@ def assert_threshold
# @api private
def assert_meets_threshold
return unless lower_coverage?
fail "YARD-Coverage must be at least #{@threshold}% but was #{total_coverage}%"
fail "YARD-Coverage must be at least #{threshold}% but was #{total_coverage}%"
end

# Raise an exception if the threshold is not equal to the coverage
Expand All @@ -118,8 +120,8 @@ def assert_meets_threshold
#
# @api private
def assert_matches_threshold
return unless @config.require_exact_threshold? && higher_coverage?
fail "YARD-Coverage has increased above the threshold of #{@threshold}% to #{total_coverage}%. You should update your threshold value."
return unless config.require_exact_threshold? && higher_coverage?
fail "YARD-Coverage has increased above the threshold of #{threshold}% to #{total_coverage}%. You should update your threshold value."
end

# Checks if total coverage is lower than the threshold
Expand All @@ -129,7 +131,7 @@ def assert_matches_threshold
#
# @api private
def lower_coverage?
total_coverage < @threshold
total_coverage < threshold
end

# Checks if total coverage is higher than the threshold
Expand All @@ -139,7 +141,7 @@ def lower_coverage?
#
# @api private
def higher_coverage?
total_coverage > @threshold
total_coverage > threshold
end
end # class Verify
end # module Rake
Expand Down

0 comments on commit 1312e7d

Please sign in to comment.