Code coverage
Add the simplecov gem to your Gemfile and install it to your project SDK.
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.
note
RubyMine supports running tests with coverage for projects that use SSH, Vagrant, or local Ruby interpreters.
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:
Automatically after performing tests
After creating a run configuration for tests, you can configure coverage options in the following way:
Press CtrlShift0A and start typing edit configurations. Select Edit Configurations and press Enter.
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.
Option | Description |
---|---|
Define the scope of code coverage analysis. In the Add Pattern dialog that opens, type the comma-delimited list of Ruby regular expressions. Select one of the pattern types defining whether the matching files should be included in or excluded from code coverage analysis. Examples: | |
Click this button to delete the selected pattern from the list. | |
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. |
Enable branch coverage (SimpleCov >= 0.18) | Use this option to enable branch coverage. With this option enabled, you can see partially covered conditions in the editor when viewing results. |
Enable coverage for forked processes (SimpleCov >= 0.19) | Enable this option to measure coverage for forked processes. |
Press CtrlAlt0S to open settings and then select Build, Execution, Deployment | Coverage.
Define how the collected coverage data will be processed:
Show options before applying coverage to the editor: show the Code Coverage dialog every time you run a new run configuration with code coverage.
Do not apply collected coverage: discard the new code coverage results.
Replace active suites with the new one: discard the active suites and use the new one every time you launch a new run configuration with code coverage.
Add to the active suites: add new code coverage suites to the active suites every time you launch a new run configuration with code coverage.
Select the Activate Coverage View checkbox to open the Coverage tool window automatically.
Press CtrlAlt0S to open settings and then select Editor | Color Scheme | General.
Alternatively, click
in the popup that opens on clicking the coverage indication line in the gutter.
In the list of components, expand the Line Coverage node and select a type of coverage: for example, Full, Partial or Uncovered.
Click the Foreground field to open the Select Color dialog.
Select a color, apply the changes, and close the dialog.

RubyMine allows you to run tests with coverage in the following ways:
To run the tests with coverage using the already created run configuration, do one of the following:
Press AltShiftF10, select the required configuration, press the right arrow key, select Cover, and press Enter.
To run tests with coverage from the main toolbar:
Select the required run configuration from the list on the main toolbar.
Click the
button on the right.
To run a test or multiple tests with coverage from the Project view, do the following:
Right-click a specific test file or a directory containing the required tests (for example, test, spec, or features).
From the context menu, select the corresponding run command, for example, Run 'All tests in: <directory name>' with Coverage.
After running tests with coverage, RubyMine displays results in the following ways:
In the Project view.
Here you can navigate through a project and examine the percentage of covered files and lines.
In the Cover tool window.
You can enable the
option to open a selected file in the editor automatically. The
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.
To find out how many times a line has been hit, click the corresponding color indicator.
In the opened popup, you can click
to configure code coverage colors or hide coverage results by clicking the Hide coverage link. For more information about displaying hidden coverage results, refer to Manage coverage results.
tip
Learn how to create missing tests from the Create tests topic.
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.
In the main menu, go to Run | Show Coverage Data CtrlAltF6.
In the Choose Coverage Suite to Display dialog, select or deselect the desired suites, and click Show selected.
RubyMine opens coverage results for the selected test suites.
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.
In the main menu, go to Run | Show Coverage Data CtrlAltF6.
Click
and select the necessary .json file in the dialog that opens.
RubyMine allows you to generate an HTML report for the collected coverage results.

In the main menu, go to Run | Generate Coverage Report, or click
in the Coverage tool window.
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.
Thanks for your feedback!