-
Notifications
You must be signed in to change notification settings - Fork 286
4. Running gem scripts
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.
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.
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.
In a terminal, type rbenv which rails
to get the process path.
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.
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.
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"]
.
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
.
Setup
- Debugger Installation
- Launch from VS Code
- Attach to a debugger
- Running Gem scripts
- Example configuration
How to contribute