RubyMine 2019.3 Help

Create tests

RubyMine provides the ability to create missing tests in various ways, for example, you can:

Create a test from template

To create a new test from a template, do the following:

  1. Do one of the following:
    • In the Project tool windowAlt+1, select the directory in which you want to create a new file, and then choose File | New on the main menu.

    • Right-click the corresponding directory and select New from the context menu.

    • PressAlt+Insert.

  2. Select Ruby Test from the list and press Enter.

  3. In the New Ruby Test popup, you need to select the testing framework and specify the class name to be tested. For example, do the following to create a new RSpec test:

    • Select RSpec.

    • Specify the described class name (for example, User) and press Enter.

    New Ruby Test popup
  4. RubyMine will create a test file with corresponding initial content and open it in the editor. Here you can add the required code.

    RSpec template editor

    If necessary, you can modify predefined templates in Settings/Preferences Ctrl+Alt+S on the Editor | File and Code Templates page.

Generate tests for Rails applications

RubyMine provides several ways to generate missing tests for Rails elements (controllers, models, and so on).

  1. In the editor, open the required Rails element, for example, the controller or model.

  2. From the main menu, select Navigate | Test or press Ctrl+Shift+T.

  3. If the corresponding test doesn't exist, the Generate Test popup appears. Select the required testing framework and press Enter.

    Generate Test popup
  4. (Optional) If the related testing framework is missing in the project’s SDK, RubyMine will suggest to install the missing gem (for example, 'rspec-rails').

    Missing gem popup

    Click Bundle it and then click Install in the opened Bundle Install dialog.

    Bundle Install dialog

    The IDE will install the missing gem and generate the test under the necessary directory (for example, spec or test depending on the selected testing framework).

Create tests alongside Rails elements

Rails allows you to generate tests alongside other applications elements such as controllers, models, and so on. Learn how to create Rails application elements in RubyMine from Create Rails application elements.

Create RSpec tests using Rails generators

RSpec generators can be run independently to create tests. You can do this as follows:

  1. From the main menu, select Tools | Run Rails Generator (Ctrl+Alt+G).

  2. In the invoked popup, start typing the required generator name. For example, to create an RSpec model test start typing rspec:model and then select rails g rspec:model. Press Enter.

  3. Specify generator argumens. For example, for the User model we pass user as an argument. Click OK.

    Add New RSpec:model
Last modified: 27 December 2019