Skip to content

Instantly share code, notes, and snippets.

@jadehopepunk
Created April 12, 2010 21:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jadehopepunk/364034 to your computer and use it in GitHub Desktop.
Save jadehopepunk/364034 to your computer and use it in GitHub Desktop.
begin
require 'spec/rake/verify_rcov'
require 'metric_fu'
MetricFu::Configuration.run do |config|
config.metrics = [:flay, :flog, :reek, :roodi, :stats]
config.graphs = [:flog, :flay, :reek, :roodi]
config.flay = { :dirs_to_flay => ['spec/models/formats'] }
config.flog = { :dirs_to_flog => ['app', 'lib'] }
config.reek = { :dirs_to_reek => ['app', 'lib'] }
config.roodi = { :dirs_to_roodi => ['app', 'lib'] }
config.saikuro = { :output_directory => 'scratch_directory/saikuro',
:input_directory => ['app'],
:cyclo => "",
:filter_cyclo => "0",
:warn_cyclo => "5",
:error_cyclo => "7",
:formater => "text"} #this needs to be set to "text"
end
desc "Run continuous integration process"
task :ci do
Rake::Task["db:migrate"].invoke
Rake::Task["db:test:clone"].invoke
Rake::Task["quality:rcov"].invoke
Rake::Task["metrics:all"].invoke
Rake::Task["cucumber"].invoke
Rake::Task["quality:verify_thresholds"].invoke
end
def check_threshold_against_result(threshold, result, should_be_under, score_name, action)
success = should_be_under ? result <= threshold : result >= threshold
if success
puts "#{score_name} result is #{result}, which is under the current threshold (#{threshold})."
else
message = "This build has a #{score_name} of #{result}, which fails to meet the threshold of " +
"#{threshold}. If you committed this, it is your responsibility to #{action} and recommit " +
"in order to get the build passing again."
raise RuntimeError, message
end
end
namespace :quality do
THRESHOLDS = {
:rcov => 70.0,
:flay => 1048,
:flog => 59.5,
:reek => 561
}
desc "check all quality thresholds"
task :verify_thresholds => [:verify_rcov_threshold, :verify_metric_fu_thresholds]
desc "check metric_fu quality thresholds"
task :verify_metric_fu_thresholds do
require 'yaml'
report_filename = ENV['CC_BUILD_ARTIFACTS'] ? File.join(ENV['CC_BUILD_ARTIFACTS'], 'report.yml') : "tmp/metric_fu/report.yml"
report = YAML.load(File.read(report_filename))
if report[:flay]
check_threshold_against_result(
THRESHOLDS[:flay],
report[:flay][:total_score].to_i,
true,
"flay score",
"reduce duplication")
end
if report[:flog]
check_threshold_against_result(
THRESHOLDS[:flog],
report[:flog][:average],
true,
"flog score",
"reduce code complexity")
end
# if report[:reek]
# smell_count = report[:reek][:matches].map{|match| match[:code_smells]}.flatten.length
# check_threshold_against_result(
# THRESHOLDS[:reek],
# smell_count,
# true,
# "reek score",
# "reduce number of code smells")
# end
end
require 'spec/rake/spectask'
Spec::Rake::SpecTask.new do |t|
t.name = :rcov
t.rcov = true
t.rcov_opts = ['--exclude', 'lib\/spec,bin\/spec,db,spec,.bundle,dependency_list.rb,config']
t.rcov_dir = (ENV['CC_BUILD_ARTIFACTS'] ? File.join(ENV['CC_BUILD_ARTIFACTS'], 'coverage') : 'coverage')
end
RCov::VerifyTask.new(:verify_rcov_threshold) do |t|
t.threshold = THRESHOLDS[:rcov]
t.require_exact_threshold = false
t.index_html = (ENV['CC_BUILD_ARTIFACTS'] ? File.join(ENV['CC_BUILD_ARTIFACTS'], 'coverage') : 'coverage') + '/index.html'
end
desc "check coverage and threshold"
task :check_rcov => ["quality:rcov", "quality:verify_rcov_threshold"]
end
rescue MissingSourceFile => e
puts "Metric Fu and RCov not loaded"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment