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.
This is the result of running rubydeps on the Rake tests after setting up its test helper with
Rubydeps will run your test suite to record the call graph of your project and use it to create a Graphviz dot graph.
Add Rubydeps to your
gem 'rubydeps', :group => :test
Launch Rubydeps by inserting this line in your
env.rb, or whatever your preferred test framework uses):
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.
Run your tests, a file named
rubydeps.dumpwill be created in the project root.
The next step is reading the dump file to generate the Graphviz dot graph
rubydeps.dotwith any filter you specify.
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
--path_filteroption specifies a regexp that matches the path of the files you are interested in analyzing. For example you could have filters like
'project_name/app|project_name/lib'to analyze only code that is located in the
libdirs or as an alternative you could just exclude some directory you are not interested using a negative regexp like
--class_name_filteroption is similar to the
--path_filteroptions except that the regexp is matched against the class names (i.e. graph node names).
--from_fileoption is used to specify the dump file generated after the test (or block) run so you can try different filters without needing to rerun the tests. e.g.:
rubydeps --from_file='rubydeps.dump' --path_filter='app/models' rubydeps --from_file='rubydeps.dump' --path_filter='app/models|app/controllers'
If you didn't rename the file you can skip this option as it will use the default
Just require rubydeps and pass a block to analyze to the
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
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.
- ruby-graphviz gem
- rcov gem (only for version 0.2.0)
Note on Patches/Pull Requests
- Fork the project.
- Make your feature addition or bug fix.
- Add tests for it. This is important so I don't break it in a future version unintentionally.
- Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
- Send me a pull request. Bonus points for topic branches.
Copyright (c) 2012 Daniel Cadenas. See LICENSE for details.
Development sponsored by Neo