RubyMine 2021.2 Help

Tutorial: Docker as a remote interpreter

Docker is a tool for building, sharing, and running containerized applications. RubyMine provides integration with Docker and allows you to perform all the required actions in your project - from building images to executing commands inside running containers. Moreover, RubyMine enables you to use the running Docker container as a remote interpreter. This means that you can run, debug, and test your application in an isolated environment right from the IDE.

This tutorial describes how you can use Docker as a remote interpreter for running and testing a sample Rails application.

In this tutorial, we’re using macOS, with RubyMine installed. Before you begin, make sure to configure Docker integration.

Build a Docker image

First of all, we need to build a Docker image for our application.

  1. Open the Dockerfile. Press Ctrl+Shift+N, type Dockerfile and press Enter.

  2. Click Run on Docker in the gutter and select New Run Configuration from the menu.

  3. In the Edit Run Configuration dialog, specify the image name in the Image tag field.

    Docker run configuration

    Click Run to start building the image.

  4. RubyMine displays the process of building the image in the Services tool window. Wait until the image is built and displayed in the Images group.

    Docker tool window

Configure Docker as a remote interpreter

Now we can use the built image to configure a remote interpreter for our application because the image has the Ruby interpreter and required gems installed. To configure Docker as a remote interpreter, do the following:

  1. Open the Settings/Preferences dialog Ctrl+Alt+S, go to the Language & Frameworks | Ruby SDK and Gems page.

  2. Click Add and select New remote in the drop-down.

    New remote interpreter
  3. In the invoked dialog, select Docker and specify the following options:

    Configure remote Ruby interpreter: Docker
    • Server: Specify a Docker server used to run a container.

    • Image name: Select the image created in the previous chapter.

    • Ruby or version manager path: Leave the default ruby value to detect a path to the Ruby interpreter automatically.

    Click OK.

  4. Select the added SDK in the Ruby SDK and Gems page and click OK.

    Ruby SDK and Gems: Docker
  5. Wait until RubyMine finishes the indexing process and creates helper Docker images and containers.

    Docker tool window

Run migrations

Before running our Rails application, we will run migrations to prepare the database.

  1. Press Ctrl twice and type db:migrate. Select rake db:migrate in the dropdown and press Enter.

    Run Anything / rake db:migrate
  2. Leave the default settings in the invoked Execute ‘db:migrate’ dialog and click OK.

    Execute db:migrate

    This creates the development.sqlite3 database in the db folder.

  3. Run rake db:migrate one more time as described in the first step. This time, set the Environment option to test in the Execute ‘db:migrate’ dialog and click OK. The created test.sqlite3 database will be used to run tests.

Run tests

Let's run tests for our application. RubyMine enables you to use different testing frameworks for this purpose, including Minitest, RSpec, and Cucumber.

Our project contains Minitest tests in the test folder.

Run all tests

  1. Open the Project view Alt+1.

  2. Right-click the test folder and select Run 'All tests in test' from the context menu.

    Run all tests in a directory

    RubyMine will run and display test results in the Run tool window.

    Test results

Now let's try running a specific test.

Run a specific test

  1. Open the users_controller_test.rb file and scroll down to the should redirect index when not logged in test.

  2. Click Icons run configurations test state green2 in the gutter and select Run ‘Minitest: test_should_redirect_index...’ in the invoked menu.

    Run a specific test

    RubyMine will display the result for this test.

    Test result

Run the application

Now we can run our application using the configured remote interpreter.

  1. Select the Development configuration on the toolbar and click Run Shift+F10.

    Run selected configuration
  2. Open a browser, enter the address, and press Enter to see our working application.

    Rails application in a browser
  3. To stop the application, click the Stop button Ctrl+F2 on the toolbar.

Last modified: 02 August 2021