Running One RSpec Example in RubyMine with Bundler Context
Forgetting bundle exec or the wrong line number breaks RSpec. RubyMine runs a single spec with the correct Bundler and Rails context automatically.
02 May 2026, 10:45 UTC

The Problem: A Missed bundle exec Breaks the Spec
You open a terminal and type rspec spec/models/user_spec.rb:42. Rails fails to load because the gems in your Gemfile are not on the load path. Adding bundle exec fixes it, but it is easy to forget, and the wrong line number runs the wrong example. In a large Rails application, this trial and error slows down feedback.
The useful takeaway is that RubyMine's RSpec run configuration launches the spec with Bundler already activated, so you can target a single line without managing the shell environment yourself.
Run the Same Command Safely in the Terminal
From the project root, run:
bundle exec rspec spec/models/user_spec.rb:42Run this as a normal user, not with sudo. The placeholder spec/models/user_spec.rb:42 is your spec path and line number. Expected check: Rails loads and only the example on line 42 executes. Risk: omitting bundle exec loads system gems and can produce LoadError or NameError.
Configure RubyMine to Run One Example
Open spec/models/user_spec.rb in the editor. Click the green gutter arrow beside the example, or open the Run menu and choose Edit Configurations. Add an RSpec configuration. Set the spec path to spec/models/user_spec.rb, set the line number to 42, and choose the project Ruby SDK. RubyMine adds the Bundler wrapper automatically.
Worked Example: Validate a Model Method
Given this model:
class User < ApplicationRecord
def display_name
[first_name, last_name].compact.join(" ")
end
endTo test it:
- Open
spec/models/user_spec.rband locate the example fordisplay_name. - Click the gutter run icon next to that example, or select the RSpec configuration you created.
- Click Run.
If the configuration is correct, the Run tool window opens and executes only that example. Look for the example name and a pass or fail result. Do not assume the exact output; verify that the example count is one.
Limitation: Spring Preloader Memory
RubyMine may use Spring to keep the Rails application loaded between runs. Repeated tests are faster, but the preloader consumes memory. On a machine with limited RAM, disable Spring in the RSpec configuration or run bundle exec rspec externally and accept the slower startup.
Actionable Check
Open a Rails project in RubyMine. Open any spec file and click the gutter run icon beside an example. Confirm the Run tool window opens and runs only that example. Then open Preferences, choose Ruby SDK and Gems, and confirm the selected SDK can see the Bundler gem.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.