-
-
Save jschoolcraft/93407 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This assumes you have the metric_fu and kablame plugins installed. | |
# For kablame I like to modify it to include your stories or features dir as well as the specs. | |
# Set the artifacts dir for development | |
ENV['CC_BUILD_ARTIFACTS'] ||= File.expand_path("#{RAILS_ROOT}/metrics") | |
rspec_base = File.expand_path("#{RAILS_ROOT}/vendor/plugins/rspec/lib") | |
$LOAD_PATH.unshift(rspec_base) if File.exist?(rspec_base) | |
require 'spec/rake/spectask' | |
require 'spec/rake/verify_rcov' | |
CRUISE_TASKS = %w( cruise:setup_test_env db:drop db:create db:migrate metrics:flog metrics:cyclomatic_complexity metrics:stats cruise:coverage features:cruise cruise:verify_rcov cruise:kablame ) | |
RCOV_THRESHOLD = 90 | |
task :default => :cruise | |
desc "Task for cruise Control" | |
task :cruise do | |
CRUISE_TASKS.each do |t| | |
CruiseControl::invoke_rake_task t | |
end | |
end | |
namespace :cruise do | |
desc "Run specs and rcov" | |
Spec::Rake::SpecTask.new(:coverage) do |t| | |
t.spec_opts = ["--format html:#{ENV['CC_BUILD_ARTIFACTS']}/rspec_code_examples.html --format profile:#{ENV['CC_BUILD_ARTIFACTS']}/examples_profile.log --format failing_examples:#{ENV['CC_BUILD_ARTIFACTS']}/failing_examples.txt"] | |
t.spec_files = FileList['spec/**/*_spec.rb'] | |
t.rcov = true | |
t.rcov_dir = ENV['CC_BUILD_ARTIFACTS']+"/specs_rcov" | |
t.rcov_opts = lambda do | |
IO.readlines("#{RAILS_ROOT}/spec/rcov.opts").map {|l| l.chomp.split " "}.flatten | |
end | |
end | |
RCov::VerifyTask.new(:verify_rcov) do |t| | |
t.threshold = RCOV_THRESHOLD | |
t.index_html = ENV['CC_BUILD_ARTIFACTS']+"/specs_rcov/index.html" if ENV['CC_BUILD_ARTIFACTS'] | |
t.require_exact_threshold = false | |
end | |
task :setup_test_env do | |
RAILS_ENV = ENV['RAILS_ENV'] = 'test' # Without this, it will drop your production (or development) database. | |
end | |
desc "Run all cruise tasks" | |
task :dev do | |
FileUtils.mkdir_p("#{ENV['CC_BUILD_ARTIFACTS']}") | |
CRUISE_TASKS.each do |t| | |
begin | |
Rake::Task[t].invoke | |
rescue | |
end | |
end | |
good_to_go = true | |
File.open("#{ENV['CC_BUILD_ARTIFACTS']}/index.html", 'w') do |file| | |
file.puts <<-HTML | |
<html> | |
<head> | |
<title>Cruise Output</title> | |
<style> | |
* {font-family: Arial;} | |
.passed {background-color:green;} | |
.failed {background-color:red;} | |
</style> | |
</head> | |
<body> | |
HTML | |
puts "\n\n" | |
# Specs | |
specs_output = File.read("#{ENV['CC_BUILD_ARTIFACTS']}/specs_profile.log") | |
if specs_output.match(/(?:\d+) examples, (\d+) failures(?:, (?:\d+) pending)?$/) | |
num_failures = $1.to_i | |
else | |
num_failures = 1 | |
end | |
if num_failures != 0 | |
good_to_go = false | |
css_class = 'failed' | |
else | |
css_class = 'passed' | |
end | |
puts "Specs: #{css_class}" | |
file.puts %Q{<div class="#{css_class}"><a href="specs.html">Specs</a></div>} | |
# Features | |
# 12 steps passed | |
# 2 steps failed | |
# 5 steps skipped | |
# 1 steps pending | |
if File.read("#{ENV['CC_BUILD_ARTIFACTS']}/features.txt") =~ /steps failed/ | |
good_to_go = false | |
css_class = 'failed' | |
else | |
css_class = 'passed' | |
end | |
puts "Features: #{css_class}" | |
file.puts %Q{<div class="#{css_class}"><a href="features.html">Features</a></div>} | |
file.puts %Q{<div class="passed"><a href="features_rcov/index.html">Features Coverage</a></div>} | |
# Coverage | |
rcov_output = File.read("#{ENV['CC_BUILD_ARTIFACTS']}/specs_rcov/index.html") | |
if rcov_output.match(%r{<tt class='coverage_code'>([\d\.]+)%</tt>}) | |
percentage = $1.to_f | |
else | |
percentage = 0.0 | |
end | |
if percentage <= RCOV_THRESHOLD | |
good_to_go = false | |
css_class = 'failed' | |
else | |
css_class = 'passed' | |
end | |
puts "Specs Coverage: #{css_class}" | |
file.puts %Q{<div class="#{css_class}"><a href="specs_rcov/index.html">Specs Coverage</a></div>} | |
# Flog & Complexity, etc | |
file.puts %Q{<div class=""><a href="flog/index.html">Flog Stats</a></div>} | |
file.puts %Q{<div class=""><a href="cyclomatic_complexity/index.html">Cyclomatic Complexity</a></div>} | |
file.puts %Q{<div class=""><a href="hall_of_shame.txt">Hall of Shame</a></div>} | |
# End | |
file.puts "</body></html>" | |
end | |
sh "open #{ENV['CC_BUILD_ARTIFACTS']}/index.html" unless good_to_go | |
end | |
desc "Cruise Kablame" | |
task :kablame do | |
sh "rake kablame:git:specs > #{ENV['CC_BUILD_ARTIFACTS']}/hall_of_shame.txt" | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
desc "Run all features" | |
task :features => "features:all" | |
task :features => 'db:test:prepare' | |
namespace :features do | |
Cucumber::Rake::Task.new(:all) do |t| | |
t.cucumber_opts = "--format pretty" | |
end | |
Cucumber::Rake::Task.new(:cruise) do |t| | |
t.cucumber_opts = "--format pretty --out=#{ENV['CC_BUILD_ARTIFACTS']}/features.txt --format html --out=#{ENV['CC_BUILD_ARTIFACTS']}/features.html" | |
t.rcov = true | |
t.rcov_opts = %w{--rails --exclude osx\/objc,gems\/,spec\/} | |
t.rcov_opts << %[-o "#{ENV['CC_BUILD_ARTIFACTS']}/features_rcov"] | |
end | |
Cucumber::Rake::Task.new(:rcov) do |t| | |
t.rcov = true | |
t.rcov_opts = %w{--rails --exclude osx\/objc,gems\/,spec\/} | |
t.rcov_opts << %[-o "features_rcov"] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment