About metric_fu 1.1.1
Metric_fu is a set of rake tasks that make it easy to generate metrics reports. It uses
Saikuro,
Flog,
Flay,
Rcov,
Reek,
Roodi,
Subversion,
Git, and
Rails
built-in stats task to create a series of reports. It's designed to integrate easily with
CruiseControl.rb
by placing files in the Custom Build Artifacts folder.
New in metric_fu 1.1.0 is integration of the 'Awesome' template and graphs -- which graph your metric performance over time! Big thanks go to Nick Quaranto and Edouard Brière for their work on this feature. If you're used to the non-awesome reports then this will be quite a treat.
New in metric_fu 1.0.0 is yaml serialization of the metrics. Running metric_fu now generates, in addition to html reports, a report.yml file. You can consume this file to mash up metrics, track them, or whatever you desire. Many thanks go to Grant McInnes for his work on this feature.
Installation:
If you haven't added github to your gem sources do this:
sudo gem sources -a http://gems.github.com
Now install the gem:
sudo gem install jscruggs-metric_fu
Then in your Rakefile:
require 'metric_fu'
If you like to vendor gems, you can unpack metric_fu into vendor/gems and require it like so:
require(File.join(RAILS_ROOT, 'vendor', 'gems', 'jscruggs-metric_fu-1.1.1', 'lib', 'metric_fu'))
Then you don't have to install it on every box you run it on.
Later versions of Rails like to manage your gems for you, so you can put this in your test.rb file:
config.gem 'jscruggs-metric_fu', :version => '1.1.1', :lib => 'metric_fu', :source => 'http://gems.github.com'
And then issue this command:
$ rake gems:unpack RAILS_ENV=test
That way Rails won't yell at you every time you run a Rake task:
config.gem: Unpacked gem jscruggs-metric_fu-1.1.1 in vendor/gems has no specification file. Run 'rake gems:refresh_specs' to fix this.
I hate being yelled at.
Usage:
Out of the box metric_fu provides this tasks:- rake metrics:all # Generate coverage, cyclomatic complexity, flog, flay, reek, roodi, stats...
I recommend using CruiseControl.rb to set up a metrics build. See the CruiseControl.rb online docs for more info on how to set up cc.rb and, once you've got that figured out, change the cruise_config.rb file inside your project to have these lines:
project.rake_task = 'metrics:all'
project.scheduler.polling_interval = 24.hours
Which will check for updates every 24 hours and run all the metric_fu rake tasks (migrating your test db first). The output will be visible from an individual build's detail page.
Configuration:
Metric_fu can be customized to your liking by altering the defaults in your Rakefile:
MetricFu::Configuration.run do |config|
#define which metrics you want to use
config.metrics = [:churn, :saikuro, :stats, :flog, :flay, :reek, :roodi, :rcov]
config.graphs = [:flog, :flay, :reek, :roodi, :rcov]
config.flay = { :dirs_to_flay => ['app', 'lib'] }
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', 'lib'],
:cyclo => "",
:filter_cyclo => "0",
:warn_cyclo => "5",
:error_cyclo => "7",
:formater => "text"} #this needs to be set to "text"
config.churn = { :start_date => "1 year ago", :minimum_churn_count => 10}
config.rcov = { :test_files => ['test/**/*_test.rb',
'spec/**/*_spec.rb'],
:rcov_opts => ["--sort coverage",
"--no-html",
"--text-coverage",
"--no-color",
"--profile",
"--rails",
"--exclude /gems/,/Library/,spec"]}
end
Note: if you don't want one of the metrics to run (like rcov), make sure you don't try to graph it (which will explode). Set config.graphs to exactly the graphs you want.
Notes on metrics:coverage
When creating a coverage report, metric_fu runs all the tests in the test folder and specs in spec folder using Rcov.
Notes on metrics:saikuro
Saikuro is bundled with metric_fu so you don't have to install it. Look at the SAIKURO_README (or the internet) for more documentation on Saikuro.
Notes on metrics:flay
Flay analyzes ruby code for structural similarities. You can configure which directories need to be flayed. The defaults are 'lib' for non Rails projects and ['app', 'lib'] for Rails projects.
Notes on metrics:flog
Flog is another way of measuring complexity (or tortured code as the Flog authors like to put it). You should check out the awesome, and a little scary, Flog website for more info.
Notes on metrics:reek
Reek detects common code smells in ruby code. You can configure which directories need to be checked. The defaults are 'lib' for non Rails projects and ['app', 'lib'] for Rails projects.
Notes on metrics:roodi
Roodi parses your Ruby code and warns you about design issues you have based on the checks that is has configured. You can configure which directories need to be checked. The defaults are 'lib' for non Rails projects and ['app', 'lib'] for Rails projects.
Notes on metrics:stats
This is just 'rake stats' put into a file. On my projects I like to be able to look at CruiseControl and get stats about the app at different points in time.
Notes on metrics:churn
Files that change a lot in your project may be bad a sign. This task uses svn or git's log to identify those files and put them in a report.Metric_fu began its life as a plugin for Rails that generated code metrics reports. As of version 0.7.0, metric_fu is a gem (owing to the excellent work done by Sean Soper) and is hosted on GitHub at http://github.com/jscruggs/metric_fu.
Questions?
Use the Google Group: http://groups.google.com/group/metric_fu