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. To learn how to enable Spring for running tests, see 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:
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.
In the navigation bar, expand the list of run/debug configurations and select Edit Configurations.
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.
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:
From the main menu, select
Control+Shift+A.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:
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: