RubyMine 2023.3 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, testing and debugging a sample Rails application.

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

Prerequisites

In this tutorial, we’ll use Mac with macOS, with RubyMine installed. Moreover, the following prerequisites should be met to complete all steps:

  • Verify that Docker is installed and running.

  • Make sure that the Docker plugin is enabled.

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.

    Dockerfile
  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 dialogCtrl+Alt+S, go to the Language & Frameworks | Ruby SDK and Gems page.

  2. Click Add and select Remote Interpreter or Version Manager 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 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 sample_rails_app configuration on the toolbar and click Run Shift+F10.

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

  3. To stop the application, click the Stop button Ctrl+F2 on the toolbar.

Debug the application

  1. Open the users_controller.rb file and set a breakpoint within the create method next to the line where a new user is created.

    Set a breakpoint
  2. Select the sample_rails_app run/debug configuration and click Debug Shift+F9.

    Debug selected configuration
  3. RubyMine will suggest installing the debugging gems. Click Yes.

    Install the debugging gems
  4. Open your browser and specify the application address 0.0.0.0:3000.

  5. Click the Sign up now! button. On the Sign up page, enter the required user parameters and click Create my account.

    Sign up page
  6. The debugger pauses its session on a breakpoint and enables you to examine the application state.

    Debugging an application

    For instance, you can check user parameters specified on the Sign up page.

Last modified: 04 April 2024