This is a short question: I am looking for a way to run specs in debug mode, with the -u
switch, so that RSpec would drop to console whenever it failed, without having to add a debugger
line into the code. Any pointers?
Install the ruby-debug gem if you haven't already. But problably you do not need it. Then start rspec with -d parameter to allow debugging and in your code, just add debugger at the point you want to set the breakpoint. That's it.
Create a test configuration from the editorSelect Create 'RSpec: <test name>' or Create 'Minitest: <test name>' and press Enter . In the dialog that opens, specify the run/debug configuration parameters (RSpec or Minitest), apply changes and close the dialog.
Starting Byebug If you're running Byebug on a Rails application in development mode, you no longer need to start the server with --debugger – the debugger is on by default. To get going, simply type byebug (or debugger ) into your source file at the line you're interested in and run the program.
Will answer my own question.
Following this tutorial, I created a custom formatter, as in:
require "spec/runner/formatter/specdoc_formatter"
class DebuggerFormatter < Spec::Runner::Formatter::SpecdocFormatter
def example_failed(example, counter, failure)
super
debugger if Kernel.respond_to?(:debugger)
end
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With