Class RSpec::Core::ExampleGroup
In: lib/rspec/core/example_group.rb
Parent: Object

ExampleGroup and {Example} are the main structural elements of rspec-core. Consider this example:

    describe Thing do
      it "does something" do
      end
    end

The object returned by `describe Thing` is a subclass of ExampleGroup. The object returned by `it "does something"` is an instance of Example, which serves as a wrapper for an instance of the ExampleGroup in which it is declared.

Methods

Included Modules

Extensions::InstanceEvalWithArgs Subject::ExampleMethods Pending Let

External Aliases

description -> display_name
described_class -> describes
  @private
describe -> context

Attributes

example  [RW]  @attr_reader Returns the {Example} object that wraps this instance of `ExampleGroup`

Public Class methods

Works like `alias_method :name, :example` with the added benefit of assigning default metadata to the generated example.

@note Use with caution. This extends the language used in your

  specs, but does not add any additional documentation.  We use this
  in rspec to define methods like `focus` and `xit`, but we also add
  docs for those methods.

Works like `alias_method :name, :it_behaves_like` with the added benefit of assigning default metadata to the generated example.

@note Use with caution. This extends the language used in your

  specs, but does not add any additional documentation.  We use this
  in rspec to define `it_should_behave_like` (for backward
  compatibility), but we also add docs for that method.

@private

@private

@private @macro [attach] define_example_method

  @param [String] name
  @param [Hash] extra_options
  @param [Block] implementation

Generates a subclass of this example group which inherits everything except the examples themselves.

## Examples

    describe "something" do # << This describe method is defined in
                            # << RSpec::Core::DSL, included in the
                            # << global namespace
      before do
        do_something_before
      end

      let(:thing) { Thing.new }

      describe "attribute (of something)" do
        # examples in the group get the before hook
        # declared above, and can access `thing`
      end
    end

@see DSL#describe

@private

Includes shared content mapped to `name` directly in the group in which it is declared, as opposed to `it_behaves_like`, which creates a nested group. If given a block, that block is also eval‘d in the current context.

@see SharedExampleGroup

Includes shared content mapped to `name` directly in the group in which it is declared, as opposed to `it_behaves_like`, which creates a nested group. If given a block, that block is also eval‘d in the current context.

@see SharedExampleGroup

The [Metadata](Metadata) object associated with this group. @see Metadata

@private

Runs all the examples in this group

@private @return [Metadata] belonging to the parent of a nested {ExampleGroup}

@private

Public Instance methods

Returns the class or module passed to the `describe` method (or alias). Returns nil if the subject is not a class or module. @example

    describe Thing do
      it "does something" do
        described_class == Thing
      end
    end

@private instance_evals the block, capturing and reporting an exception if raised

@deprecated use {ExampleGroup#example}

[Validate]