/metric_fu

A fist full of code metrics

Primary LanguageRubyMIT LicenseMIT

MetricFu Gem Version Build Status

Code Climate Dependency Status

Rdoc

Metrics

Installation

gem install metric_fu

If you have trouble installing the gem, try adding metric_fu to your Gemfile. You may also want to file a ticket on the issues page.

See documentation on the rubyforge page for how to customize your metrics. Otherwise, all current information is either in this repo or on the wiki.

Usage

By default, you can run all metrics from the root of an app with the command metric_fu

See metric_fu --help for more options

Compatibility

  • It is currently testing on MRI (1.9.3 and 2.0.0), JRuby (19 mode), and Rubinius (19 mode). Ruby 1.8 is no longer supported due to the cane library.

  • For 1.8.7 support, see version 3.0.0 for partial support, or 2.1.3.7.18.1 (where Semantic Versioning goes to die)

  • The metric_fu-Saikuro fork and metric_fu-roodi fork are a part of an attempt to get metric_fu working in a modern Ruby environment, specifically compatibility with Ruby 1.9 and Bundler.

  • metric_fu no longer runs rcov itself. You may still use rcov metrics as documented below

  • The Cane, Flog, and Rails Best Practices metrics are disabled when Ripper is not available

Documentation

*See wiki

Formatters

Built-in Formatters

By default, metric_fu will use the built-in html formatter to generate HTML reports for each metric with pretty graphs.

These reports are generated in metric_fu's output directory (tmp/metric_fu/output) by default. You can customize the output directory by specifying an out directory at the command line using a relative path:

metric_fu --out custom_directory  	# outputs to tmp/metric_fu/custom_directory

or a full path:

metric_fu --out /home/metrics	  	# outputs to /home/metrics

You can specify a different formatter at the command line by referencing a built-in formatter or providing the fully-qualified name of a custom formatter.

metric_fu --format yaml --out custom_report.yml

or

metric_fu --format MyCustomFormatter

Custom Formatters

You can customize metric_fu's output format with a custom formatter.

To create a custom formatter, you simply need to create a class that takes an options hash and responds to one or more notifications:

 class MyCustomFormatter
   def initialize(opts={}); end  	# metric_fu will pass in an output param if provided.

   # Should include one or more of...
   def start; end 					# Sent before metric_fu starts metric measurements.
   def start_metric(metric); end 	# Sent before individual metric is measured.
   def finish_metric(metric); end 	# Sent after individual metric measurement is complete.
   def finish; end 					# Sent after metric_fu has completed all measurements.
   def display_results; end 		# Used to open results in browser, etc.
 end

See lib/metric_fu/formatter/ for examples.

metric_fu will attempt to require a custom formatter by fully qualified name based on ruby search path. So if you include a custom formatter as a gem in your Gemfile, you should be able to use it out of the box. But you may find in certain cases that you need to add a require to your .metrics configuration file.

For instance, to require a formatter in your app's lib directory:

require './lib/my_custom_formatter.rb'

Configuration

see the .metrics file

Using Coverage Metrics

in your .metrics file add the below to run pre-generated metrics

MetricFu::Configuration.run do |config|
  config.configure_metric(:rcov) do |rcov|
    rcov.enabled = true
    coverage_file = File.expand_path("coverage/rcov/rcov.txt", Dir.pwd)
    rcov.external = coverage_file
  end
end

If you want metric_fu to actually run rcov itself (1.8 only), don't specify an external file to read from

Rcov metrics with Ruby 1.8

To generate the same metrics metric_fu has been generating run from the root of your project before running metric_fu

RAILS_ENV=test rcov $(ruby -e "puts Dir['{spec,test}/**/*_{spec,test}.rb'].join(' ')") --sort coverage --no-html --text-coverage --no-color --profile --exclude-only '.*' --include-file "\Aapp,\Alib" -Ispec >> coverage/rcov/rcov.txt

Simplecov metrics with Ruby 1.9 and 2.0

Add to your Gemfile or otherwise install

gem 'simplecov'
# https://github.com/kina/simplecov-rcov-text
gem 'simplecov-rcov-text'

Modify your spec_helper as per the SimpleCov docs and run your tests before running metric_fu

#in your spec_helper
require 'simplecov'
require 'simplecov-rcov-text'
SimpleCov.formatter = SimpleCov::Formatter::RcovTextFormatter
SimpleCov.start
# SimpleCov.start 'rails'

Historical

There is some useful-but-out-of-date documentation about configuring metric_fu at http://metric-fu.rubyforge.org/ and a change log in the the HISTORY file.

Contributions

See the TODO for some ideas

See CONTRIBUTING for how to contribute

Resources:

This is the official repository for metric_fu. The original repository by Jake Scruggs at https://github.com/jscruggs/metric_fu has been deprecated.

Original Resources: