Home

Awesome

Build Status Code Climate endorse

rubydeps

A tool to create class dependency graphs from test suites.

I think this is more useful than static analysis of the code base because of the high dynamic aspects of the language.

Sample output

This is the result of running rubydeps on the Rake tests after setting up its test helper with Rubydeps.start:

rubydeps --class_name_filter='^Rake'

Rake dependencies

Usage

Rubydeps will run your test suite to record the call graph of your project and use it to create a Graphviz dot graph.

  1. Add Rubydeps to your Gemfile and bundle install:

     gem 'rubydeps', :group => :test
    
  2. Launch Rubydeps by inserting this line in your test/test_helper.rb (or spec_helper.rb, cucumber env.rb, or whatever your preferred test framework uses):

     Rubydeps.start
    

    Notice that this will slow down your tests so consider adding a conditional bound to some ENV variable or just remove the line when you are done.

  3. Run your tests, a file named rubydeps.dump will be created in the project root.

  4. The next step is reading the dump file to generate the Graphviz dot graph rubydeps.dot with any filter you specify.

    rubydeps --path_filter='app/models'
    
  5. Now you are in Graphviz realm. You can convert the dot file to any image format with your prefered orientations and layouts with the dot utility that comes with the Graphviz installation e.g.:

    dot -Tsvg rubydeps.dot > rubydeps.svg
    

    Keep in mind that sometimes you may have missing dependencies as we graph the dependencies exercised by your tests so you can use it as a quick bird's eye view of your project test coverage.

Command line options

Library usage

Just require rubydeps and pass a block to analyze to the analyze method.

require 'rubydeps'

Rubydeps.analyze(:path_filter => path_filter_regexp, :class_name_filter => class_name_filter_regexp, :to_file => "rubydeps.dump") do
    # your code goes here
end

Installation

gem install rubydeps

Rubydeps now only supports ruby >= 1.9.2. If you need 1.8.x support then:

gem install rubydeps -v0.2.0

Notice that in 0.2.0 you should use dot_for instead of analyze and the dump functionality is missing.

Dependencies

Note on Patches/Pull Requests

Copyright

Copyright (c) 2012 Daniel Cadenas. See LICENSE for details.

Development sponsored by Neo