Running and Debugging RSpec Tests in RubyMine with Custom Run/Debug Configurations
Learn how to create an RSpec Run/Debug configuration in RubyMine, pass custom flags, and debug specs reliably while avoiding common SDK and preloader pitfalls.
01 Oct 2025, 11:31 UTC

Running RSpec specs from RubyMine
To execute RSpec tests inside the IDE, create an RSpec Run/Debug configuration. This configuration wraps the rspec command, adds the project’s load path, respects Bundler, and shows results in the built‑in test runner.
Create a basic RSpec configuration
- Open
Run → Edit Configurations…. - Click the
+button and chooseRSpec. - Set
Nameto something likeSpec: User. - In
Test kindselectFileand browse tospec/models/user_spec.rb. - Leave
Ruby SDKat the project SDK and ensure theBundlercheckbox is ticked. - Click
OK.
Passing custom RSpec options
To run only examples tagged with :focus, add the flag in the Arguments field:
--tag focus
You can combine multiple flags, for example --tag focus --profile.
Debugging with Spring disabled
If your project uses Spring, breakpoints may not be hit because the process is reused. Disable Spring in the configuration:
- Open the same configuration dialog and click
Environment variables. - Add
DISABLE_SPRING=true. - Alternatively, uncheck the
Use Springbox.
Now set a breakpoint inside a spec, click the debug icon, and execution will suspend at the breakpoint.
How the configuration works under the hood
RubyMine builds a command similar to:
bundle exec rspec --tag focus spec/models/user_spec.rb
It adds the project’s load path, uses the selected Ruby SDK, and respects the Bundler setting. The output is captured and shown in the Run tool window, where each example receives a pass/fail icon matching the command‑line result.
Limits and common mistakes
Ruby SDK and gemset mismatch
If the SDK pointed to by the configuration does not have the rspec gem installed (or a different version is used by Bundler), the run fails with a LoadError: cannot load such file -- rspec message. Verify that which rspec from the configured SDK points to the same binary that bundle exec rspec would use.
Bundler not enabled
When the Bundler checkbox is cleared, RubyMine invokes rspec directly. This can bypass gems installed only in the Gemfile, leading to missing‑dependency errors. Keep the checkbox ticked unless you deliberately want to run without Bundler.
Preloaders interfering with debugging
Spring, Zeus, or similar preloaders keep the Ruby process alive between runs. Breakpoints set after the first load may not be hit because the code is already loaded in the preloader fork. Disabling Spring (via the checkbox or DISABLE_SPRING=true) forces a fresh Ruby process for each debug session.
Working directory issues
If you set a custom Working directory that is not the project root, relative paths in spec_helper.rb or rails_helper.rb may resolve incorrectly, causing No such file or directory errors. Leave it blank (default to $ProjectFileDir$) unless you have a specific reason to change it.
Verification steps
- Run the configuration you just created. The Run tool window should list each example with a green check (passed) or red cross (failed), matching the output of
bundle exec rspec spec/models/user_spec.rb --tag focus. - Click the gutter next to a line inside a spec to add a breakpoint, then start the debugger. Execution should pause at the breakpoint, and the Variables view should show the values of local variables and instance variables at that point.
- Modify the
Argumentsfield to--tag focus --profileand run again. Only examples tagged with:focusshould appear, and the profiler summary should be displayed at the end of the run.
Summary
RubyMine’s built‑in RSpec Run/Debug configuration lets you execute specs with the same environment as the command line, while giving you a graphical way to add flags, set environment variables, and debug. The main pitfalls are SDK/Bundler mismatches and active preloaders; addressing those ensures reliable runs and breakpoints.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.