Module: RSpec::Core::SharedExampleGroup

Overview

Shared example groups let you define common context and/or common
examples that you wish to use in multiple example groups.

When defined, the shared group block is stored for later evaluation.
It can later be included in an example group either explicitly
(using include_examples, include_context or it_behaves_like)
or implicitly (via matching metadata).

Named shared example groups are scoped based on where they are
defined. Shared groups defined in an example group are available
for inclusion in that example group or any child example groups,
but not in any parent or sibling example groups. Shared example
groups defined at the top level can be included from any example group.

Instance Method Details

Stores the block for later use. The block will be evaluated
in the context of an example group via include_examples,
include_context, or it_behaves_like.

Examples:

shared_examples"auditable"doit"stores an audit record on save!"doexpect{auditable.save!}.tochange(Audit,:count).by(1)endenddescribeAccountdoit_behaves_like"auditable"dolet(:auditable){Account.new}endend

Overloads:

#shared_examples(name, &block) ⇒ void

Parameters:

name(String, Symbol, Module)
—

identifer to use when looking up
this shared group

block
—

The block to be eval'd

#shared_examples(name, metadata, &block) ⇒ void

Parameters:

name(String, Symbol, Module)
—

identifer to use when looking up
this shared group

metadata(Array<Symbol>, Hash)
—

metadata to attach to this
group; any example group or example with matching metadata will
automatically include this shared example group.