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

5. Example configurations

Jared Knipp edited this page Jun 12, 2019 · 3 revisions

Example Configurations

These examples are designed to show how to use the debugger setup in common situations. They can be used as a baseline for debugging your own scripts.

Each of these code blocks would be placed inside the configurations array of the launch.json file structured as:

{
	"version": "0.2.0",
	"configurations": []
}

These examples have deliberately varying path structure, so you may have to mix and match to get something that's good for your system.

Rails

This will run the rails server at the workspace root. It assumes that the binstubs have been installed with bundler install --binstubs.

{
	"name": "Rails server",
	"type": "Ruby",
	"request": "launch",
	"cwd": "${workspaceRoot}",
	"program": "${workspaceRoot}/bin/rails",
	"args": ["server"]
}

Rake

This will run the a rake task. It assumes ruby-debug-ide was installed with bundle and runs it with bundler exec. It also assumes bundler is available in your PATH.

{
	"name": "Rake db:migrate",
	"type": "Ruby",
	"request": "launch",
	"cwd": "${workspaceRoot}",
	"program": "${workspaceRoot}/vendor/rake",
	"useBundler": true,
	"args": ["db:migrate"]
}

RSpec

Running all your specs

This will run all of the specs with some extra settings passed.

{
	"name": "RSpec - all",
	"type": "Ruby",
	"request": "launch",
	"cwd": "${workspaceRoot}",
	"program": "/usr/bin/rspec",
	"args": [
		"--require", "spec_helper",
		"--require", "rails_helper",
		"--format", "documentation"
		]
}

Running only the current open spec file

This will run RSpec, but only on the currently open spec file. If the current file isn't a spec file, RSpec will fail with 'no specs found' or some such error.

{
	"name": "RSpec - open spec file",
	"type": "Ruby",
	"request": "launch",
	"cwd": "${workspaceRoot}",
	"program": "${workspaceRoot}/bin/rspec",
	"args": ["${file}"]
}

Cucumber

Run all your cukes.

{
	"name": "Cucumber",
	"type": "Ruby",
	"request": "launch",
	"cwd": "${workspaceRoot}",
	"program": "${workspaceRoot}/bin/cucumber"
}

Test::Unit

Running only the currently open test file

Run Test::Unit only on the currently open test file. Include additional paths in the $LOAD_PATH with the includes config option.

{
    "name": "Test::Unit - open test file",
    "type": "Ruby",
    "request": "launch",
    "cwd": "${workspaceRoot}",           
    "program": "${file}",
    "includes": ["test", "lib"]
}

Running a single test in the currently open file

Run Test::Unit for a single selected test, only on the currently open test file.

{
    "name": "Test::Unit - single selected test",
    "type": "Ruby",
    "request": "launch",
    "cwd": "${workspaceRoot}",           
    "program": "${file}",
    "includes": ["test", "lib"],
    "args": [
        "-n",
        "${selectedText}"
    ]
}