IntelliJ IDEA 2017.1 Help

Generating Tests for Rails Applications

In this section:

Introduction

If for some reason you have a Rails entity without a related test, note that IntelliJ IDEA suggests a way to generate tests for the controllers, mailers, models, and helpers in the RSpec and Test::Unit testing frameworks.

Generating tests

To generate a test for a Rails entity, follow these general steps

  1. In the editor, place the caret at the desired Rails entity.
  2. Do one of the following:
    • On the main menu, choose Navigate | Test.
    • On the context menu, choose Go To | Test.
    • Press Ctrl+Shift+T.
  3. If the desired test doesn't yet exist, the pop-up Generate Test appears. In this window, choose the testing framework:

    If the related testing framework is missing, IntelliJ IDEA will suggest to install the missing gem (for example, rspec-rails):

    /help/img/idea/2017.1/rm_missing_gems.png
  4. Click Bundle it to add the gem to the Gemfile, and in the Bundle Install dialog run the bundler:
    /help/img/idea/2017.1/rm_run_bundler.png

The IDE will install the missing gem and generate the test in the specified format in the directory with the Rails entity name (for example, controllers or models) under the spec or test directory, depending on the testing framework selected.

/help/img/idea/2017.1/rm_test_generated.png

You can roll this action back in case something goes wrong.

See Also

Language and Framework-Specific Guidelines:

External Links:

Last modified: 18 July 2017