Skip to content
This repository has been archived by the owner on Jul 31, 2023. It is now read-only.

4. Running gem scripts

Tom Weir edited this page Jun 5, 2016 · 2 revisions

Debugging scripts from Ruby GEMS

You can debug any Ruby gems with executables the same way as your own scripts. The only trouble is finding the executable Ruby script to use for your launch settings. The scenarios below may help you to locate them/it on your system. For demonstration purposes, assume we want to run a rails server. If you're intending to debug something else, replace rails with the command you want to debug.

Linux or Mac OSX

Using bundler

Install the bin stubs (the executable ruby scripts) for the gems you have told bundler about (in your Gemfile) in the workspace bin folder with bundler install --binstubs. Then use ${workspaceRoot}/bin/rails as the process path.

If you don't want the bin stubs installed, you'll have to look at the other scenarios below.

With a single ruby version installed - or using rvm

In a terminal, type:

less `which rails`

If the file has ruby code in it, then that's the file you want. Type which rails to get the process path. If it doesn't, it should have a line with something like /usr/bin/ruby /path/to/rails/script/rails. You'll need the last path in that line as your process path.

Using rbenv

In a terminal, type rbenv which rails to get the process path.

Using rvm

The default rvm will be used to run the debugger, which can lead to unexpected results if your default differs from the ruby version configured for your repo. The workaround is to change rvm's default ruby version to match the repo's expected version. In a terminal, type rvm use <ruby-version> --default to get things working. Once this is done, specifying the bundler & rdebug-ide paths is no longer required, and things load properly.

Windows

Your gem executable scripts will be in the same path as your ruby executable. Which, if you've used the RailsInstaller, will give you something like C:\RailsInstaller\Ruby2.2.0\bin\rails for your process path.

Note: don't use the .bat file, that's a wrapper so you the rails script can be run for the command line.

Setting up your launch

Open your VS Code launch.json file (Click the gear icon on the debug sidebar) and set the "program" string to the process path you identified above. e.g. "program": "/Users/Hooky/.rbenv/versions/2.2.0/bin/rails".

Set the "args" object to an array of argument string you need to pass to the process you are debugging. For our example we would use: "args": ["server"].

Using the "attach" option

You can use the same settings for the attach configuration for standard debugging, just use the process path above as your script file to run with rdebug-ide.