Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 2.3.8, Ruby 1.8.6: Getting a visual call tree/graph of what methods call what?

I have a medium-complex Rails app. The main controller (the one that does what the app is there to do) has a single action method. (It's not a standard RESTful app; this is acting as an intermediary and there are external constraints on how it can be called.)

However, it does have lots of methods and a number of filters, and an ever-growing test suite. The structure has changed considerably over time, and I no longer have confidence that some of the Mocha expectations that were set up for the tests written earlier are still appropriate.

There are multiple people working on the app, so I'm constructing a cookbook for writing functional tests. 'Use [these] expectations and assertions when you want to ttest with/without [those] side effects' and so on.

A call tree/graph would be extremely useful in composing such a document. Aside from the filters, such could even be statically derived from the sources -- by something that knew about Rails' know-everything-about-everything model, so maybe static isn't such a good idea. :-)

I've tried using RubyProf with my functional tests to get a call tree, but all I get are trees relating to the test methods and parts of the kernel and Rails -- and none of the controller methods. (At least not that I've found; the profiling creates lots of little files instead of one big one.)

The failure to find the controller methods might be related to how the action method is invoked -- via send rather than some more 'normal' mechanism.

Blah, blah, blah.. just FYI on what I've tried so far.

Is there a good tool to build a who-calls-what flow chart/call tree for a Rails 2.3.8 app?

Thanks!

like image 631
RoUS Avatar asked Mar 01 '11 20:03

RoUS


2 Answers

Did you try https://github.com/tmm1/rbtrace? I've not tried it with Rails, so I'm not sure it would work in your case.

like image 73
Florent2 Avatar answered Nov 10 '22 10:11

Florent2


(this answer is less helpful for controller code, or dynamic code in general)

code-explorer's call-graph is a static single file method call graphing tool. For single PORO file it is quite useful to see how each methods call each other. This works with Ruby 2.4.

like image 25
lulalala Avatar answered Nov 10 '22 12:11

lulalala