RubyMine 2019.3 Help

Code coverage

With RubyMine, you can measure how much of your code is covered with tests using the SimpleCov analysis tool. You can run tests with coverage for any supported testing framework, analyze the percentage of covered files and lines in a separate tool window and editor, generate HTML reports, and so on.

Prerequisites

Before using code coverage in RubyMine, make sure that the simplecov gem is added to the Gemfile and installed to the project's SDK. Learn how to install gems using RubyMine from the Using Bundler to install gems topic.

Configure coverage run options

RubyMine allows you to run tests with coverage using specific run options. For example, you can exclude particular folders from coverage measurement. To provide specific coverage options, you need to have a run configuration for tests. A run configuration can be created in two ways:

After creating a run configuration for tests, you can configure coverage options in the following way:

  1. Press Ctrl+Shift+A and start typing edit configurations. Select Edit Configurations and press Enter.

    Find Action
  2. In the opened Run/Debug Configurations dialog, select the required configuration (for example, Rake, Test::Unit/Shoulda/Minitest, or RSpec), go to the Code Coverage tab and specify the desired settings.

    Run/Debug Configurations

    The following settings are available:

    Option

    Description

    the Add button

    Click this button to define the scope of code coverage analysis. In the Add Pattern dialog that opens, type the comma-delimited list of Ruby regular expressions, and specify whether the matching files should be included into or excluded from code coverage analysis.

    Examples: /config/, /bin/,/config/

    the Add button

    Click this button to delete the selected pattern from the list.

    the Edit button

    Click this button to change the selected code coverage pattern.

    Enable coverage in test folders.

    Enable this option to include test folders (for example, test or spec) in code coverage analysis.

Run tests with coverage

RubyMine allows you to run tests with coverage in the following ways:

Run tests with coverage using a predefined configuration

To run the tests with coverage using the already created run configuration, do one of the following:

  • Press Shift+Alt+F10, select the required configuration, press the right arrow key, select Cover, and press Enter.

  • To run tests with coverage from the main toolbar:

    1. Select the required run configuration from the list on the main toolbar.

    2. Click the Run with Coverage button on the right.

      Run with Coverage

Run tests with coverage from the Project view

To run a test or multiple tests with coverage from the Project view, do the following:

  1. Right-click a specific test file or a directory containing the required tests (for example, test, spec, or features).

  2. From the context menu, select the corresponding run command, for example, Run 'All tests in: <directory name>' with Coverage.

Run tests with coverage from the editor

To run tests from the editor, perform the following steps:

  1. Click the Run button on the left gutter next to the required test or test class.

    Run a specific test

  2. From the context menu, select the required run command, for example, Run '<test name>' with Coverage.

RubyMine will run tests and display results in the Run tool window. Coverage results will be displayed in several places: the Coverage tool window, editor, and Project view. Learn more at View coverage results.

View coverage results

After running tests with coverage, RubyMine displays results in the following ways:

  • In the Project view.

    Coverage results in the Project view

    Here you can navigate through a project and examine the percentage of covered files and lines.

  • In the Coverage tool window.

    Coverage results in a dedicated tool window

    You can enable the Navigate with Single Click option to open a selected file in the editor automatically. The Generate Coverage Report button allows you to generate an HTML report based on coverage results.

  • In the editor.

    Use the color indicators in the gutter to detect the uncovered lines of code.

    Coverage results in the editor

    To find out how many times a line has been hit, click the corresponding color indicator.

    Coverage settings in the editor

    In the opened popup, you can click Edit Coverage Colors button to configure code coverage colors or hide coverage results by clicking the Hide coverage link. To learn how to display hidden coverage results, see Manage coverage results.

Manage coverage results

After you run tests with coverage, RubyMine saves the results in a coverage suite. Coverage suites allow you to display or hide specific coverage results, merge several reports, and remove unnecessary results.

View coverage results from specific suites

  1. From the main menu, select Tools | Show Code Coverage Data Ctrl+Alt+F6.

  2. In the Choose Coverage Suite to Display dialog, select or deselect the desired suites, and click Show selected.

    Choose Coverage Suite to Display

    RubyMine opens coverage results for the selected test suites.

Add the coverage suite from a file

Consider a situation when a file that contains code coverage information has been obtained from another computer. You can load this file from disk and review coverage results.

  1. From the main menu, select Tools | Show Coverage Data Ctrl+Alt+F6.

  2. Click the Add button and select the necessary .rcov file in the dialog that opens.

Generate HTML report

RubyMine allows you to generate an HTML report for the collected coverage results.

Coverage results in browser

To do this, follow the steps below:

  1. From the main menu, select Tools | Generate Coverage Report, or click the Generate Coverage Report button in the Coverage tool window.

  2. In the Generate Coverage Report dialog, specify the directory where the generated report will be stored. Optionally, select Open generated HTML in browser. Click Save.

Last modified: 5 December 2019