Breakpoint not working on VScode for Rspec Rails

1.3k Views Asked by At

Not sure what's wrong with my setup. I've been stuck on this issue for a day now and still hasn't resolved this. I've setup my VScode so I can debug my specs (for Ruby on Rails) faster. I followed this guide on Github, originally stumbled upon this Stackoverflow thread here.

I've added ruby-debug-ide & debase under the development and test group in my gem file & execute $ bundle install. They seem to be working ok (I think) based on what I can see on my debug console.

Gemfile:

group :development, :test do
  gem 'ruby-debug-ide'
  gem 'debase'
end

Debug console:

This is how it looks like after pressing F5 or clicking the "Run" button under the Run & Debug tab on VSCode.

enter image description here

Looking at this part of the debug console I know that my spec file is being executed properly:

enter image description here

Launch.json file:

{
  "configurations": [
    {
      "name": "Debug RSpec - open spec file",
      "type": "Ruby",
      "request": "launch",
      "cwd": "${workspaceRoot}",
      "useBundler": true,
      "pathToBundler": "/Users/<my computer name>/.rbenv/shims/bundle",
      "pathToRDebugIDE": "/Users/<my computer name>/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/ruby-debug-ide-0.7.3",
      "debuggerPort": "1235",
      "program": "${workspaceRoot}/bin/rspec",
      "args": [
        "${file}"
      ],
      "showDebuggerOutput": true
    },
  ]
}

I've added a breakpoint on my spec file (even tried adding multiple breakpoints) but it's debugger isn't hitting any of it. Made sure it's turned on (See screenshot below).

enter image description here

Other info about my setup that might help, tell me if you need more info:

  • Machine is MBP 2021 Intel
  • OS: Mac OS Monterey 12.0.1
  • Latest version of VSCode installed
  • Ruby version: ruby 2.6.6p146 (2020-03-31 revision 67876) [x86_64-darwin20
  • Rails version: Rails 5.2.3
  • Version manager: RBenv
1

There are 1 best solutions below

0
On

This configuration where working for me:

{
  "name": "Start rails server",
  "type": "Ruby",
  "request": "launch",
  "cwd": "${workspaceFolder}",
  "program": "${workspaceFolder}/bin/rails",
  "useBundler": true,
  "pathToBundler": "${workspaceFolder}/bin/bundle",
  "showDebuggerOutput": true,
  "pathToRDebugIDE": "/${workspaceFolder}/bin/rdebug-ide",
  "args": ["s"]
},
{
  "name": "Run tests",
  "type": "Ruby",
  "request": "launch",
  "cwd": "${workspaceFolder}",
  "program": "${workspaceFolder}/bin/rspec",
  "useBundler": true,
  "pathToBundler": "${workspaceFolder}/bin/bundle",
  "showDebuggerOutput": true,
  "pathToRDebugIDE": "/${workspaceFolder}/bin/rdebug-ide",
  "args": []
},
{
  "name": "Run single test file",
  "type": "Ruby",
  "request": "launch",
  "cwd": "${workspaceFolder}",
  "program": "${workspaceFolder}/bin/rspec",
  "useBundler": true,
  "pathToBundler": "${workspaceFolder}/bin/bundle",
  "showDebuggerOutput": true,
  "pathToRDebugIDE": "/${workspaceFolder}/bin/rdebug-ide",
  "args": [
    "-I",
    "${workspaceRoot}",
    "${file}"
  ]
},

It made them work based on this blog post

But I've also realized that You don't need:

  gem 'ruby-debug-ide'
  gem 'debase'

and new implementation for debugger is working