Skip to content

Instantly share code, notes, and snippets.

@nicolasrouanne
Last active January 28, 2022 22:43
Show Gist options
  • Save nicolasrouanne/33c310673544ce4907d79bb52154dbce to your computer and use it in GitHub Desktop.
Save nicolasrouanne/33c310673544ce4907d79bb52154dbce to your computer and use it in GitHub Desktop.
VS Code configuration: settings & debugger config (Ruby, React)
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug in Exponent",
"cwd": "${workspaceFolder}",
"type": "reactnative",
"request": "launch",
"platform": "exponent"
},
{
"type": "node",
"name": "Run all tests",
"request": "launch",
"program": "${workspaceFolder}/node_modules/jest/bin/jest",
"args": ["--runInBand"],
"cwd": "${workspaceFolder}",
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
},
{
"type": "node",
"name": "Run test - one file",
"request": "launch",
"program": "${workspaceFolder}/node_modules/jest/bin/jest",
"args": ["--runInBand", "${file}"],
"cwd": "${workspaceFolder}",
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
}
]
}
{
"version": "0.2.0",
"configurations": [
{
"name": "Run app (watch mode)",
"command": "npm run start:dev",
"request": "launch",
"type": "node-terminal"
},
{
"name": "Run tests (watch mode)",
"command": "npm run test:watch",
"request": "launch",
"type": "node-terminal"
},
]
}
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug Rails server",
"type": "Ruby",
"request": "launch",
"cwd": "${workspaceRoot}",
"program": "${workspaceRoot}/bin/rails",
"args": ["server", "-p", "3000"],
"env": {
"PATH": "/Users/nicolasrouanne/.rvm/gems/ruby-2.7.2@cevidentia-api/bin:/Users/nicolasrouanne/.rvm/gems/ruby-2.7.2@global/bin:/Users/nicolasrouanne/.rvm/rubies/ruby-2.7.2/bin:/Users/nicolasrouanne/.rvm/bin:/usr/local/bin/rubocop-daemon-wrapper:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin/rubocop-daemon-wrapper",
"GEM_HOME": "/Users/nicolasrouanne/.rvm/gems/ruby-2.7.2@cevidentia-api",
"GEM_PATH": "/Users/nicolasrouanne/.rvm/gems/ruby-2.7.2@cevidentia-api:/Users/nicolasrouanne/.rvm/gems/ruby-2.7.2@global",
"RUBY_VERSION": "ruby-2.7.2"
}
},
{
"name": "Debug Rails console",
"type": "Ruby",
"request": "launch",
"cwd": "${workspaceRoot}",
"program": "${workspaceRoot}/bin/rails",
"args": ["console"],
"env": {
"PATH": "/Users/nicolasrouanne/.rvm/gems/ruby-2.7.2@cevidentia-api/bin:/Users/nicolasrouanne/.rvm/gems/ruby-2.7.2@global/bin:/Users/nicolasrouanne/.rvm/rubies/ruby-2.7.2/bin:/Users/nicolasrouanne/.rvm/bin:/usr/local/bin/rubocop-daemon-wrapper:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin/rubocop-daemon-wrapper",
"GEM_HOME": "/Users/nicolasrouanne/.rvm/gems/ruby-2.7.2@cevidentia-api",
"GEM_PATH": "/Users/nicolasrouanne/.rvm/gems/ruby-2.7.2@cevidentia-api:/Users/nicolasrouanne/.rvm/gems/ruby-2.7.2@global",
"RUBY_VERSION": "ruby-2.7.2"
}
},
{
"name": "Run RSpec - all",
"type": "Ruby",
"request": "launch",
"cwd": "${workspaceRoot}",
"program": "${workspaceRoot}/bin/rspec",
"env": {
"PATH": "/Users/nicolasrouanne/.rvm/gems/ruby-2.7.2@cevidentia-api/bin:/Users/nicolasrouanne/.rvm/gems/ruby-2.7.2@global/bin:/Users/nicolasrouanne/.rvm/rubies/ruby-2.7.2/bin:/Users/nicolasrouanne/.rvm/bin:/usr/local/bin/rubocop-daemon-wrapper:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin/rubocop-daemon-wrapper",
"GEM_HOME": "/Users/nicolasrouanne/.rvm/gems/ruby-2.7.2@cevidentia-api",
"GEM_PATH": "/Users/nicolasrouanne/.rvm/gems/ruby-2.7.2@cevidentia-api:/Users/nicolasrouanne/.rvm/gems/ruby-2.7.2@global",
"RUBY_VERSION": "ruby-2.7.2"
}
},
{
"name": "Debug RSpec - open spec file",
"type": "Ruby",
"request": "launch",
"cwd": "${workspaceRoot}",
"program": "${workspaceRoot}/bin/rspec",
"args": ["${file}"],
"env": {
"PATH": "/Users/nicolasrouanne/.rvm/gems/ruby-2.7.2@cevidentia-api/bin:/Users/nicolasrouanne/.rvm/gems/ruby-2.7.2@global/bin:/Users/nicolasrouanne/.rvm/rubies/ruby-2.7.2/bin:/Users/nicolasrouanne/.rvm/bin:/usr/local/bin/rubocop-daemon-wrapper:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin/rubocop-daemon-wrapper",
"GEM_HOME": "/Users/nicolasrouanne/.rvm/gems/ruby-2.7.2@cevidentia-api",
"GEM_PATH": "/Users/nicolasrouanne/.rvm/gems/ruby-2.7.2@cevidentia-api:/Users/nicolasrouanne/.rvm/gems/ruby-2.7.2@global",
"RUBY_VERSION": "ruby-2.7.2"
}
},
{
"name": "Debug RSpec - open spec file on a certain line",
"type": "Ruby",
"request": "launch",
"cwd": "${workspaceRoot}",
"program": "${workspaceRoot}/bin/rspec",
"args": ["${file}:${lineNumber}"],
"env": {
"PATH": "/Users/nicolasrouanne/.rvm/gems/ruby-2.7.2@cevidentia-api/bin:/Users/nicolasrouanne/.rvm/gems/ruby-2.7.2@global/bin:/Users/nicolasrouanne/.rvm/rubies/ruby-2.7.2/bin:/Users/nicolasrouanne/.rvm/bin:/usr/local/bin/rubocop-daemon-wrapper:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin/rubocop-daemon-wrapper",
"GEM_HOME": "/Users/nicolasrouanne/.rvm/gems/ruby-2.7.2@cevidentia-api",
"GEM_PATH": "/Users/nicolasrouanne/.rvm/gems/ruby-2.7.2@cevidentia-api:/Users/nicolasrouanne/.rvm/gems/ruby-2.7.2@global",
"RUBY_VERSION": "ruby-2.7.2"
}
}
]
}
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug Rails server",
"type": "Ruby",
"request": "launch",
"cwd": "${workspaceRoot}",
"program": "${workspaceRoot}/bin/rails",
"args": ["server", "-p", "3000"]
},
{
"name": "Run RSpec - all",
"type": "Ruby",
"request": "launch",
"cwd": "${workspaceRoot}",
"program": "${workspaceRoot}/bin/rspec"
},
{
"name": "Debug RSpec - open spec file",
"type": "Ruby",
"request": "launch",
"cwd": "${workspaceRoot}",
"program": "${workspaceRoot}/bin/rspec",
"args": ["${file}"]
},
{
"name": "Debug RSpec - open spec file on a certain line",
"type": "Ruby",
"request": "launch",
"cwd": "${workspaceRoot}",
"program": "${workspaceRoot}/bin/rspec",
"args": ["${file}:${lineNumber}"]
}
]
}
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug Rails server",
"type": "Ruby",
"request": "launch",
"cwd": "${workspaceRoot}",
"program": "${workspaceRoot}/bin/rails",
"args": ["server", "-p", "3000"]
},
{
"name": "Run RSpec - all",
"type": "Ruby",
"request": "launch",
"cwd": "${workspaceRoot}",
"program": "/Users/nicolasrouanne/.rvm/gems/ruby-2.7.0/bin/rspec"
},
{
"name": "Debug RSpec - open spec file",
"type": "Ruby",
"request": "launch",
"cwd": "${workspaceRoot}",
"program": "/Users/nicolasrouanne/.rvm/gems/ruby-2.7.0/bin/rspec",
"args": ["${file}"]
},
{
"name": "Debug RSpec - open spec file on a certain line",
"type": "Ruby",
"request": "launch",
"cwd": "${workspaceRoot}",
"program": "/Users/nicolasrouanne/.rvm/gems/ruby-2.7.0/bin/rspec",
"args": ["${file}:${lineNumber}"]
}
]
}
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"name": "Run all tests",
"request": "launch",
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/react-scripts",
"args": ["test", "--env=jsdom", "--runInBand"],
"cwd": "${workspaceFolder}",
"console": "integratedTerminal",
"protocol": "inspector",
"internalConsoleOptions": "neverOpen"
},
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome",
"url": "http://localhost:3000",
"webRoot": "${workspaceFolder}/src"
}
]
}
{
"version": "0.2.0",
"configurations": [
{
"name": "Rails server",
"type": "Ruby",
"request": "launch",
"program": "${workspaceRoot}/bin/rails",
"args": ["server"],
"env": {
"PATH": "/Users/nicolasrouanne/.rvm/gems/ruby-2.5.0/bin:/Users/nicolasrouanne/.rvm/gems/ruby-2.5.0@global/bin:/Users/nicolasrouanne/.rvm/rubies/ruby-2.5.0/bin:/Users/nicolasrouanne/.rvm/bin:/Users/nicolasrouanne/.local/bin:/Users/nicolasrouanne/.nvm/versions/node/v10.15.1/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/MacGPG2/bin:/Users/nicolasrouanne/.local/bin:/Users/nicolasrouanne/.nvm/versions/node/v10.15.1/bin:/usr/X11/bin:/Users/nicolasrouanne/bin:~/development:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/Users/nicolasrouanne/bin:/usr/local/bin:/Users/nicolasrouanne/development:/Users/nicolasrouanne/development/platform-tools",
"GEM_HOME": "/Users/nicolasrouanne/.rvm/gems/ruby-2.5.0",
"GEM_PATH": "/Users/nicolasrouanne/.rvm/gems/ruby-2.5.0:/Users/nicolasrouanne/.rvm/gems/ruby-2.5.0@global",
"RUBY_VERSION": "ruby-2.5.0"
}
},
{
"name": "Rails test - all",
"type": "Ruby",
"request": "launch",
"program": "${workspaceRoot}/bin/rails",
"args": ["test"],
"env": {
"PATH": "/Users/nicolasrouanne/.rvm/gems/ruby-2.5.0/bin:/Users/nicolasrouanne/.rvm/gems/ruby-2.5.0@global/bin:/Users/nicolasrouanne/.rvm/rubies/ruby-2.5.0/bin:/Users/nicolasrouanne/.rvm/bin:/Users/nicolasrouanne/.local/bin:/Users/nicolasrouanne/.nvm/versions/node/v10.15.1/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/MacGPG2/bin:/Users/nicolasrouanne/.local/bin:/Users/nicolasrouanne/.nvm/versions/node/v10.15.1/bin:/usr/X11/bin:/Users/nicolasrouanne/bin:~/development:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/Users/nicolasrouanne/bin:/usr/local/bin:/Users/nicolasrouanne/development:/Users/nicolasrouanne/development/platform-tools",
"GEM_HOME": "/Users/nicolasrouanne/.rvm/gems/ruby-2.5.0",
"GEM_PATH": "/Users/nicolasrouanne/.rvm/gems/ruby-2.5.0:/Users/nicolasrouanne/.rvm/gems/ruby-2.5.0@global",
"RUBY_VERSION": "ruby-2.5.0"
}
},
{
"name": "Rails test - one file",
"type": "Ruby",
"request": "launch",
"program": "${workspaceRoot}/bin/rails",
"args": ["test", "${file}"],
"env": {
"PATH": "/Users/nicolasrouanne/.rvm/gems/ruby-2.5.0/bin:/Users/nicolasrouanne/.rvm/gems/ruby-2.5.0@global/bin:/Users/nicolasrouanne/.rvm/rubies/ruby-2.5.0/bin:/Users/nicolasrouanne/.rvm/bin:/Users/nicolasrouanne/.local/bin:/Users/nicolasrouanne/.nvm/versions/node/v10.15.1/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/MacGPG2/bin:/Users/nicolasrouanne/.local/bin:/Users/nicolasrouanne/.nvm/versions/node/v10.15.1/bin:/usr/X11/bin:/Users/nicolasrouanne/bin:~/development:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/Users/nicolasrouanne/bin:/usr/local/bin:/Users/nicolasrouanne/development:/Users/nicolasrouanne/development/platform-tools",
"GEM_HOME": "/Users/nicolasrouanne/.rvm/gems/ruby-2.5.0",
"GEM_PATH": "/Users/nicolasrouanne/.rvm/gems/ruby-2.5.0:/Users/nicolasrouanne/.rvm/gems/ruby-2.5.0@global",
"RUBY_VERSION": "ruby-2.5.0"
}
},
{
// You must select exactly the whole test name
"name": "Rails test - single test",
"type": "Ruby",
"request": "launch",
"program": "${workspaceRoot}/bin/rails",
"args": ["test", "${file}", "--name", "test_${selectedText}"],
"env": {
"PATH": "/Users/nicolasrouanne/.rvm/gems/ruby-2.5.0/bin:/Users/nicolasrouanne/.rvm/gems/ruby-2.5.0@global/bin:/Users/nicolasrouanne/.rvm/rubies/ruby-2.5.0/bin:/Users/nicolasrouanne/.rvm/bin:/Users/nicolasrouanne/.local/bin:/Users/nicolasrouanne/.nvm/versions/node/v10.15.1/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/MacGPG2/bin:/Users/nicolasrouanne/.local/bin:/Users/nicolasrouanne/.nvm/versions/node/v10.15.1/bin:/usr/X11/bin:/Users/nicolasrouanne/bin:~/development:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/Users/nicolasrouanne/bin:/usr/local/bin:/Users/nicolasrouanne/development:/Users/nicolasrouanne/development/platform-tools",
"GEM_HOME": "/Users/nicolasrouanne/.rvm/gems/ruby-2.5.0",
"GEM_PATH": "/Users/nicolasrouanne/.rvm/gems/ruby-2.5.0:/Users/nicolasrouanne/.rvm/gems/ruby-2.5.0@global",
"RUBY_VERSION": "ruby-2.5.0"
}
},
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:3000",
"webRoot": "${workspaceFolder}"
}
]
}

VS Code launch.json configurations

VS Code launch.json file serves as a debugging configuration file.

Introduction

Where to put it

It must be stored in PROJET_ROOT/.vscode/launch.json.

Should I commit it?

Though opinions vary, it is not recommended to commit such files in source control. It is specific to every developer, and commiting it would prevent each developer to configure it according to his needs.

An alternative might be to commit it as launch.json.default, although I haven't tested it yet. I resolve for now on storing it on a project by project basis, in gists such as this one, though not ideal.

Useful resources

Rails & RSpec

For rails and rspec multiple configurations are possible, depending on your local environment:

  • low risk, bloated, not portable: follow the vscode-recipe step by step.
    • It just works ☕️
    • but it has a lot of useless options (i.e. configuration key that are not strictly needed) that bloat your configuration, and make it less understandable.
    • it is not portable since it has your absolute paths built-in
  • lighter still not portable:
    • remove all the non necessary configuration keys
    • remove duplicate configurations
    • it is not portable since it has your absolute paths built-in
  • with binstubs
    • generate a binstub for rspec
    • portable since it uses the generated binstub 👨‍💻
  • when using rvm gemsets
    • VS Code can't find the installed gems inside the gemset.
    • You need to specify env variables to give the path to various folders

VS Code recipe

Follow the official VS Code Recipe

Lighter config

See launch-rails-rspec-lighter.json

Removed useless following configuration keys:

  • "args": ["server", "-p", "3000"]: it's the default options
  • pathToBundler and pathToRDebugIDE since it seems to find it without
  • "useBundler": true: seems to be working with bundler even without it
  • "args": ["--pattern", "${workspaceRoot}/spec/**/*_rspec.rb"]: it's the default glob pattern for rspec

    CAUTION: typo s/_rspec/_spec/

binstubs config

First you need to generate the binstub for rspec, which is not generated by rails by default. This will create a wrapper in ./bin/rspec that will run the bundled rspec-rails gem.

$ bundle binstubs rspec-rails

This file should be added to source control. Then you can replace all the absolute paths in your launch.json configuration by "${workspaceRoot}/bin/rspec"

See launch-rails-rspec-binstubs.json

With rvm and gemsets

As a prerequisite, you need to generate binstubs (see previous section). Then specify env variables so VS Code can locate the gems correctly

This can be done by running this shell printf:

printf "\n\"env\": {\n  \"PATH\": \"$PATH\",\n  \"GEM_HOME\": \"$GEM_HOME\",\n  \"GEM_PATH\": \"$GEM_PATH\",\n  \"RUBY_VERSION\": \"$RUBY_VERSION\"\n}\n\n"

It outputs something like this

"env": {
  "PATH": "/Users/nicolasrouanne/.rvm/gems/ruby-2.7.2@cevidentia-api/bin:/Users/nicolasrouanne/.rvm/gems/ruby-2.7.2@global/bin:/Users/nicolasrouanne/.rvm/rubies/ruby-2.7.2/bin:/Users/nicolasrouanne/.rvm/bin:/usr/local/bin/rubocop-daemon-wrapper:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin/rubocop-daemon-wrapper",
  "GEM_HOME": "/Users/nicolasrouanne/.rvm/gems/ruby-2.7.2@cevidentia-api",
  "GEM_PATH": "/Users/nicolasrouanne/.rvm/gems/ruby-2.7.2@cevidentia-api:/Users/nicolasrouanne/.rvm/gems/ruby-2.7.2@global",
  "RUBY_VERSION": "ruby-2.7.2"
}

See launch-rails-rspec-binstubs-gemset.json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment