RubyMine 2016.3 Help

Shoulda

RubyMine helps you write Shoulda tests on attaching the shoulda gem.

RubyMine provides Shoulda-specific code completion, if one of the following conditions is observed:

  • The Bundler is used.
  • For Rails 2.*, Shoulda is specified in environment.rb
  • For the Ruby projects, require 'shoulda' is mandatory.

Refer to Shoulda installation page to learn about using Shoulda in Rails applications.

Having enabled Shoulda support in your project, you can:

  • Use Shoulda-aware code completion for the contexts and should blocks:
    /help/img/idea/2016.3/ruby_shouldaCodeCompletion.png
  • Run and debug Shoulda tests using the Test::Unit run/debug configuration, or a user-defined Rake task. In both cases, RubyMine will run tests in the test runner UI. So doing, you can launch test cases, should blocks, or all test cases in a directory.
  • View Shoulda tests in the File Structure view:
    /help/img/idea/2016.3/ruby_shouldaFileStructureView.png
  • In the Rails applications, view Shoulda tests in the Test::Unit/Shoulda node of the Rails view:

    /help/img/idea/2016.3/ruby_shouldaRailsView.png

To enable Shoulda support, follow these general steps

  1. Install shoulda gem to your project.
  2. Mark as test roots the directories with the Shoulda tests.

Example

Consider creating a Shoulda test in a Ruby project. Create a Test::Unit test template. Note that you can also create a plain Ruby script. In this case, make sure that its name ends with _test.rb.

In an empty Ruby project, add the following statements to the Test::Unit test cases with Shoulda tests:

require "test/unit" require "rubygems" gem "shoulda" require "shoulda"

See Also

Last modified: 22 March 2017