RSpec

Library providing tools for writing and running RSpec tests.

Module: RSpec::SleepingKingStudios::Concerns::SharedExampleGroup

Parent Namespace
RSpec::SleepingKingStudios::Concerns
Defined In
lib/rspec/sleeping_king_studios/concerns/shared_example_group.rb

Table Of Contents

Overview

Methods for creating reusable shared example groups and shared contexts in a module that can be mixed into multiple RSpec example groups.

Examples

module MySharedExamples
  extend RSpec::SleepingKingStudios::Concerns::SharedExampleGroup

  shared_examples 'my examples' do
    # Define shared examples here.
  end # shared_examples
end # module

RSpec.describe MyObject do
  include MySharedExamples

  include_examples 'my examples'
end # describe

Back To Top

Instance Methods

#alias_shared_examples new_name, old_name => Object

Also known as: alias_shared_context

Aliases a defined shared example group, allowing it to be accessed using a new name. The example group must be defined in the current context using shared_examples. The aliases must be defined before including the module into an example group, or they will not be available in the example group.

Parameters

Raises

#included other => Object

Hook to merge defined example groups when included in another module.

#shared_examples(name, &block) => Object
#shared_examples(name, metadata, &block) => Object

Also known as: shared_context

Defines a shared example group within the context of the current module. Unlike a top-level example group defined using RSpec#shared_examples, these examples are not globally available, and must be mixed into an example group by including the module. The shared examples must be defined before including the module, or they will not be available in the example group.

Overloads

#shared_examples(name, &block) => Object
Parameters
  • name (String) — Identifer to use when looking up this shared group.
  • block — Used to create the shared example group definition.
#shared_examples(name, metadata, &block) => Object
Parameters
  • name (String) — Identifer to use when looking up this shared group.
  • metadata (Array<Symbol>, Hash) — Metadata to attach to this group; any example group with matching metadata will automatically include this shared example group.
  • block — Used to create the shared example group definition.

Back To Top


Back to Documentation | Versions | 2.8 | Reference | RSpec | RSpec::SleepingKingStudios | RSpec::SleepingKingStudios::Concerns