RubyMine 2023.3 Help

Rails/Spring support

Spring is a Rails application preloader that speeds up development by keeping your application running in the background. This means you that don’t need to restart a server when you make changes.

In RubyMine, Spring can be used to run Rails generators, tests, and Rake tasks. Make sure that the spring gem is added to the Gemfile and installed to the project’s SDK.

Note that Test::Unit/Shoulda/Minitest tests are run without using Spring by default. For more information about enabling Spring for running tests, refer to Use Spring for running tests.

Use Spring for running tests

RubyMine lets you specify whether to run tests using the Spring preloader for the specified run/debug configuration. In the example below, we’ll demonstrate how to run all Minitest tests from the test directory in the sample_rails_app project. To do this, you can use the following workflow:

  1. Right-click the test directory in the project view and select Run 'All tests in test: ...'. After performing tests, a corresponding run/debug configuration (All tests in test: sample_rails_app) will be created.

    run configuration for tests

  2. In the navigation bar, expand the list of run/debug configurations and select Edit Configurations.

    Edit run configurations
  3. In the invoked dialog, make sure that the All tests in test: sample_rails_app configuration is selected in the list on the left. Then, set the Use pre-load server option to Spring.

    Run/debug configurations dialog

    Click OK. The Spring preloader will be used now to run tests from this run/debug configuration.

Use Spring for debugging

RubyMine allows you to debug Rails applications with Spring. This may require updating a system or project Spring configuration file to load the debugger into every process forked by Spring. When you start debugging, RubyMine might show you the dialog with the following choices:

  • System config (~/.spring.rb)

    Click to update the system Spring config (the ~/.spring.rb file) and start debugging.

  • Project config (config/spring.rb)

    Click to update the project Spring config (the config/spring.rb file) and start debugging.

  • Do not change, disable Spring

    Click to disable Spring for debugging an application.

Disable Spring

If required, you can disable Spring for a current project. To do this:

  1. In the main menu, go to Help | Find Action Control+Shift+A.

  2. Start typing Spring and disable the Spring pre-loader option.

Spring server commands

When you launch Rails generators, tests or Rake tasks in RubyMine, it launches a separate instance of the Spring server with a custom SPRING_TMP_PATH environment variable. The value of this variable is equal to ${TMPDIR}rm<hash><name>. This means that you need to prepend the Spring server commands with SPRING_TMP_PATH=${TMPDIR}rm<hash><name>, where:

  • <hash> is the hash code of the project location represented in the hexadecimal system.

  • <name> is the project name, most likely truncated.

To detect the necessary hash code and name, use the following command in the terminal:

ls -t ${TMPDIR} | grep "^rm"

You will get a list of directories starting with the rm prefix and sorted by the modification time (in descending order).

In the command output, find an entry that contains the first letters of the project root's folder. For example, for a project named sample_rails_app, the corresponding entry can look like this: rm1c3c5678samp. The hash code in this example is 1c3c5678 and the name is samp.

For example, if you encounter some issues with Spring on macOS and need to stop it, run the following command:

SPRING_TMP_PATH=${TMPDIR}rm1c3c5678PROJECT_NAME bin/spring stop
Last modified: 27 December 2023