Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running RSpec in debug mode

Tags:

ruby

rspec

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?

like image 418
Hakan Ensari Avatar asked Apr 14 '10 11:04

Hakan Ensari


People also ask

How do I debug a spec file in Ruby?

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.

How do I run an RSpec in Rubymine?

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.

How do you run a Byebug?

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.


1 Answers

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
like image 104
Hakan Ensari Avatar answered Nov 09 '22 00:11

Hakan Ensari