How to run arbitrary method from debugger?

Inside a rails app, I would like to debug a method... one that isn't invoked by a web call + controller. (I.e., something that would be launched by script/runner for example).

How can this be done in RubyMine such that the debugger is running?

11 comments
Comment actions Permalink

Hi Chez,

If you are talking about the ability to evaluate some expression with breakpoint inside (i.e.)
Screenshot.png
Consider this tiny program, we want to debug fooo method, but it cannot be reached during program normal execution. It is essential to stop on breakpoint at line 6, and try to evaluate fooo.

Unfortunally at the moment this is impossible due to ruby-debug limitations. IMHO the easiest way to reach this is insert some hooks inside your code, which will call your particular method. Of course you can make it staying at breakpoint using evaluate action.

Also we have some plans on adding debug capabilities to embedded rails console: http://youtrack.jetbrains.net/issue/RUBY-4982
Feel free to vote, comment and track progress.

Regards,
Oleg

0
Comment actions Permalink

module Foo
  class Bar
    def Bar.have_fun
      a = 5
      b = a + 2
      print b
    end
  end
end


No, what I have is some code that I want to exercise, in the debugger (as per example). But there is no controller pointing to this routine. The only way I know of to exercse that code in the RubyMine debugger, is
  * create a controller and route
  * have the controller call Foo::Bar.have_fun
  * point browser to the route

Instead, I would like to be able to create a Debug configuration (menu Run:Debug...:Edit Configurations...) and specify that it launch Foo::Bar.have_fun, in the context of a Rails app (w/ access to the database).



Attachment(s):
debug_me.jpg
0
Comment actions Permalink

Hi Chez,

Have you looked at the issue I'd attached to my previous post?
Once we make debugger work with rails console, exactly the described functionality will be available.

Regards,
Oleg

0
Comment actions Permalink

I did look at it, thanks.

So there's no way to make a run configuration to do this?

0
Comment actions Permalink

Hi Chez,

I did look at it, thanks.

So there's no way to make a run configuration to do this?

Unfortunally no way. Sorry.

Regards,
Oleg

0
Comment actions Permalink

You might be able to create a run/debug config that points to "script runner" as a ruby program, and pass it the string to execute

0
Comment actions Permalink

It seems like this case Rails environment won't be loaded.

0
Comment actions Permalink

./script/runner is a ruby script which loads the rails environment, then evals the ruby snippet passed in on the command line.  If you debug this script with a call to the method you want to inspect, then you can breakpoint and step through it, etc.

0
Comment actions Permalink

Matt,

That sounds like a good idea... but how do you set it up?

After going to the Run menu in RubyMine, then selecting Edit Configurations..., then Add Configuration..
then what? What kind of configuration to add? Rails? Rake? What settings?

0
Comment actions Permalink

Add a ruby configuration, point ruby script to script/runner, make working directory rails root, and arguments should be the method (or ruby snippet) you want to call.  Not sure how rubymine handles spaces in arguments, you might need to surround with quotes or something if its more than a single method call.

0

Please sign in to leave a comment.