Class RSpec::Core::Example
In: lib/rspec/core/example.rb
Parent: Object

Wrapper for an instance of a subclass of {ExampleGroup}. An instance of `Example` is returned by the {ExampleGroup#example example} method exposed to examples, {Hooks#before before} and {Hooks#after after} hooks, and yielded to {Hooks#around around} hooks.

Useful for configuring logging and/or taking some action based on the state of an example‘s metadata.

@example

    RSpec.configure do |config|
      config.before do
        log example.description
      end

      config.after do
        log example.description
      end

      config.around do |ex|
        log example.description
        ex.run
      end
    end

    shared_examples "auditable" do
      it "does something" do
        log "#{example.full_description}: #{auditable.inspect}"
        auditable.should do_something
      end
    end

@see ExampleGroup

Methods

Classes and Modules

Module RSpec::Core::Example::NotPendingExampleFixed
Module RSpec::Core::Example::Procsy

External Aliases

pending -> pending?

Attributes

example_group_instance  [R]  @attr_reader @private

Returns the example_group_instance that provides the context for running this example.

exception  [R]  @attr_reader

Returns the first exception raised in the context of running this example (nil if no exception is raised)

metadata  [R]  @attr_reader

Returns the metadata object associated with this example.

Public Class methods

@private

Used to define methods that delegate to this example‘s metadata

Creates a new instance of Example. @param example_group_class the subclass of ExampleGroup in which this Example is declared @param description the String passed to the `it` method (or alias) @param metadata additional args passed to `it` to be used as metadata @param example_block the block of code that represents the example

@api private

Wraps the example block in a Proc so it can invoked using `run` or `call` in [around](../Hooks#around-instance_method) hooks.

Public Instance methods

Returns the string submitted to `example` or its aliases (e.g. `specify`, `it`, etc). If no string is submitted (e.g. `it { should do_something }`) it returns the message generated by the matcher if there is one, otherwise returns a message including the location of the example.

Returns the example group class that provides the context for running this example.

@private

Used internally to set an exception and fail without actually executing the example when an exception is raised in before(:all).

@deprecated access options via metadata instead

@api private instance_evals the block passed to the constructor in the context of the instance of {ExampleGroup}. @param example_group_instance the instance of an ExampleGroup subclass

@private

Used internally to set an exception in an after hook, which captures the exception but doesn‘t raise it.

[Validate]