Configuring RSpec Run and Debugging in RubyMine
Learn how to configure RubyMine's RSpec runner to move from terminal-based testing to integrated debugging, including Gemfile requirements and common pitfalls like Spring stale state.
14 Feb 2026, 08:21 UTC

The Problem: Manual Test Execution vs. IDE Integration
Running RSpec tests from a terminal is standard, but it separates the test results from the source code. When a test fails, you must manually find the line number in the backtrace and navigate to the file. RubyMine solves this by integrating RSpec directly into the IDE, allowing you to launch specific specs, click through failures to the exact line of code, and pause execution at breakpoints without manually inserting binding.pry or byebug calls.
Setting Up the RSpec Run Configuration
RubyMine uses Run/Debug Configurations to map how the IDE invokes the rspec command. To move from terminal-based testing to IDE-integrated testing, you need to define the scope of the test run.
Step-by-Step Configuration
- Navigate to Run > Edit Configurations... from the top menu.
- Click the + (Add New Configuration) button and select RSpec.
- Configure the following fields:
- Name: Give it a descriptive name (e.g.,
User Model Specs). - Test kind: Select
Fileto run a single spec, orDirectoryto run a whole suite. - Spec file/directory: Provide the path to your file (e.g.,
spec/models/user_spec.rb). - Custom arguments: Enter
--require spec_helperto ensure the environment loads correctly.
- Name: Give it a descriptive name (e.g.,
Worked Example: Testing a User Model
Assume you have a simple Rails model test in spec/models/user_spec.rb. To run this with the debugger, your Gemfile must include the compatible debugger gem for RubyMine:
# Gemfile
gem 'rspec-rails'
gem 'ruby-debug-ide', '~> 0.7'
After running bundle install, you can launch the test in two ways:
- Run: Click the green Play icon. RubyMine executes
rspecand parses the output into the Run tool window. Passing tests show a green check; failures provide a clickable link to the failing line. - Debug: Click the Bug icon. This attaches the IDE debugger. If you have set a breakpoint (by clicking the gutter next to a line number), RubyMine will pause execution there, allowing you to inspect the current state of local variables in the Variables pane.
Limitations and Common Pitfalls
The Debugger Attachment Failure
The most common issue is the debugger failing to attach, resulting in the test running as a normal process without stopping at breakpoints. This almost always happens because ruby-debug-ide is missing from the Gemfile or is the wrong version. Verify that the gem is installed in the same Ruby environment (RVM, rbenv, or asdf) that RubyMine is configured to use in Settings > Languages & Frameworks > Ruby SDK and Gems.
Stale State and Spring
Spring is a Rails pre-loader that speeds up test execution but can lead to "stale state," where changes to your code aren't reflected in the test run. While RubyMine typically attempts to disable Spring for its internal test runs, custom Spring configurations can override this. If you notice that code changes aren't taking effect, check your spring.rb configuration or manually stop Spring using bin/spring stop.
Formatter Incompatibility
RubyMine parses the standard RSpec output to create its visual test tree. If you add custom RSpec formatters (like --format documentation) in the Custom arguments field, the IDE may fail to parse the results, and you will lose the ability to click through to failures. Stick to the default formatter for IDE runs.
Verification and Results
To verify your configuration is working correctly:
- Run the spec and check the Run window. You should see a structured tree of tests rather than just raw text.
- Hover over the green checkmark or check the console output to see the exact command RubyMine executed. It should look similar to:
bundle exec rspec spec/models/user_spec.rb --require spec_helper. - Set a breakpoint in the method being tested and launch via Debug. The IDE should shift focus to the code line and highlight the current execution point.
Rollback
To remove these configurations, go back to Run > Edit Configurations..., select the RSpec configuration, and click the - (Remove) button. This does not affect your code or Gemfile.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.