Run and Debug RSpec Tests Directly from RubyMine
Learn how to configure, run, and debug RSpec tests inside RubyMine. From setting up the Ruby SDK to using breakpoints and the Run tool window, this guide gives you a step‑by‑step workflow and practical checks to ensure your tests execute correctly.
18 Feb 2026, 02:22 UTC

Desired Outcome
Execute and debug RSpec tests inside RubyMine, seeing real‑time results, stack traces, and the ability to pause at breakpoints for state inspection.
Prerequisites
- Ruby SDK – RubyMine must be aware of the Ruby interpreter used by the project. Check
File | Project Structure | SDKsand ensure an SDK is listed. - Gemfile – The
rspecgem must be included, typically under thetestgroup:group :test do gem 'rspec' end - Bundler – Run
bundle installso the Gemfile.lock reflects the installed gems. - RSpec configuration – A
spec_helper.rborrails_helper.rbshould exist in thespecdirectory.
Focused Procedure
- Open the Test File
- Navigate to
spec/models/user_spec.rb(or any RSpec file). - The gutter next to the file name shows a green
▶icon if the file contains tests.
- Navigate to
- Create or Use a Run Configuration
- Right‑click the file or a specific
itblock and selectRun ‘RSpec’. - RubyMine will open the
Run/Debug Configurationdialog. The following fields are most important:- Working directory – Usually the project root.
- RSpec path – Leave blank to use the bundled
bundle exec rspeccommand. - Arguments – Add options like
--tag focusto run a subset. - Environment variables – Set
RAILS_ENV=testif needed.
- Click
OKto create the configuration. It will appear under theRundropdown.
- Right‑click the file or a specific
- Set a Breakpoint
- Open the test file and click the gutter left of a line inside an
itblock, e.g.,expect(user.valid?).to be true. - The red dot indicates a breakpoint; it will be hit when the test runs.
- Open the test file and click the gutter left of a line inside an
- Run or Debug
- Click the
Runicon (green triangle) orDebugicon (bug) next to the configuration name. - RubyMine launches the test runner. If debugging, the IDE will pause at the breakpoint, opening the
Debugtool window.
- Click the
- Review Results
- The
Runtool window shows a tree of examples, each colored green (passed) or red (failed). The total count appears at the top. - Click a failed example to see the stack trace and highlighted code.
- The
- Rerun or Debug Again
- In the
Runwindow, theRerunbutton (two arrows) re‑executes the last configuration. - The
Debugbutton (bug) starts a fresh debugging session, useful after code changes.
- In the
Expected Checks
- Breakpoint Hit – When debugging, the IDE should pause at the breakpoint, displaying variable values in the
Variablespane. - Pass/Fail Count – The
Runwindow should show the same number of tests as defined in the file. A mismatch indicates the test file was not loaded correctly. - Stack Trace Accuracy – For a failing test, the stack trace should point to the exact line in your test or production code that caused the failure.
Recovery Options
- Configuration Reset – If tests do not run, open
Run | Edit Configurationsand verify the working directory and arguments. Removing theRSpec pathfield forces RubyMine to usebundle exec rspec. - Environment Variable Fix – Missing
RAILS_ENV=testcan cause tests to run in production mode. Add it in theEnvironment variablesfield. - Gemfile Consistency – If the
rspecgem is missing, runbundle installand restart RubyMine to refresh the project SDK. - Project Sync – Use
File | Synchronizeto reload the file system and ensure RubyMine sees the latest test files.
Concrete Example
Suppose you have the following test:
require 'rails_helper'
RSpec.describe User, type: :model do
it 'is valid with a name' do
user = User.new(name: 'Alice')
expect(user.valid?).to be true
end
end
Set a breakpoint on the expect line. Create a run configuration with no special arguments. Run in debug mode. RubyMine should pause at the breakpoint, letting you inspect user in the Variables pane. After stepping over, the test will finish and the Run window will show a green checkmark.
Limitations
- Run configurations are project‑specific. When sharing the project, export the configuration via
.runfiles or commit the.ideadirectory. - RSpec options such as
--tagmust be entered in the configuration’sArgumentsfield; otherwise they are ignored. - Debugging is limited to the Ruby interpreter configured for the project. Switching SDKs requires restarting RubyMine.
Practical Verification
- Create a new RSpec test file as shown above.
- Set a breakpoint and run in debug mode.
- Confirm the debugger stops at the breakpoint and the
Runwindow reports one passed test. - Delete the
nameattribute to force a failure and rerun. Verify the failure appears in theRunwindow with a red exclamation mark.
Conclusion
RubyMine offers a streamlined path to run and debug RSpec tests, combining visual configuration, real‑time debugging, and comprehensive result reporting. By following the steps above, you can quickly identify flaky tests, inspect state at critical points, and iterate faster on your Ruby or Rails codebase.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.