How to always choose the correct test?


I crossposted this to SuperUser in case you'd prefer to answer it there:

In RubyMine (and other JetBrains products like IntelliJ or PyCharm), a common task is to switch between a file containing a class and the corresponding file containing tests for that class, using `shift` `command/ctrl` `T`.

However, my RubyMine installation seems unable to identify the correct test file, even though the test contains a direct reference to the class I have open, and even though the test file is in a `project/spec/` directory symmetrical to the class file in `project/app/` and has the same name as the file with `_spec` appended.


File I have open in RubyMine:

# in project/app/models/event_source.rb
class EventSource < ApplicationRecord
# ...

Test file I would like to switch to:

# in project/spec/models/event_source_spec.rb

RSpec.describe EventSource, type: :model do
# ...

When I have `event_source.rb` open and use the shortcut to open the test file, RubyMine always presents me with a window titled "Choose Test for *event_source.rb* (7 found)" that offers:

- `spec/helpers/event_sources_helper_spec.rb`
- `spec/views/event_sources/edit.html.erb_spec.rb`
- (other view specs)
- `spec/models/event_sources_spec.rb` (the correct test file)
- `spec/controllers/event_sources_controller_spec.rb`

How can I configure or fix RubyMine to correctly guess the corresponding test file, rather than showing the wrong test files that happen to contain an element of the same name?

I assume other JetBrains products offer similar functionality and that users of PyCharm, IntelliJ, or PHPStorm might know a solution.

1 comment
Comment actions Permalink


have you tried the steps proposed in the SO thread? Did they help?


Please sign in to leave a comment.