include(*modules_and_options) public

Declares modules to be included in multiple example groups (describe blocks). With no :type, the modules listed will be included in all example groups.

Use :type to restrict the inclusion to a subset of example groups. The value assigned to :type should be a key that maps to a class that is either a subclass of Spec::Example::ExampleGroup or extends Spec::Example::ExampleGroupMethods and includes Spec::Example::ExampleMethods.

For example, the rspec-rails gem/plugin extends Test::Unit::TestCase with Spec::Example::ExampleGroupMethods and includes Spec::Example::ExampleMethods in it. So if you have a module of helper methods for controller examples, you could do this:

  config.include(ControllerExampleHelpers, :type => :controller)

Only example groups that have that type will get the modules included:

  describe Account, :type => :model do
    # Will *not* include ControllerExampleHelpers

  describe AccountsController, :type => :controller do
    # *Will* include ControllerExampleHelpers
Show source
Register or log in to add new notes.