Class: RSpec::Core::ExampleGroup

Inherits:
Object
  • Object
show all
Extended by:
Hooks, MemoizedHelpers::ClassMethods, SharedExampleGroup
Includes:
MemoizedHelpers, Pending
Defined in:
lib/rspec/core/example_group.rb

Overview

rubocop:disable Metrics/ClassLength 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.

Example group bodies (e.g. describe or context blocks) are evaluated in the context of a new subclass of ExampleGroup. Individual examples are evaluated in the context of an instance of the specific ExampleGroup subclass to which they belong.

Besides the class methods defined here, there are other interesting macros defined in Hooks, MemoizedHelpers::ClassMethods and SharedExampleGroup. There are additional instance methods available to your examples defined in MemoizedHelpers and Pending.

Constant Summary

WrongScopeError =

Raised when an RSpec API is called in the wrong scope, such as before being called from within an example rather than from within an example group block.

Class.new(NoMethodError)

Metadata (collapse)

Defining Examples (collapse)

Defining Example Groups (collapse)

Including Shared Example Groups (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods included from SharedExampleGroup

shared_examples

Methods included from MemoizedHelpers::ClassMethods

let, let!, subject, subject!

Methods included from Hooks

after, append_after, around, before, prepend_before

Methods included from Pending

#pending, #skip

Methods included from MemoizedHelpers

#is_expected, #should, #should_not, #subject

Constructor Details

- (ExampleGroup) initialize(inspect_output = nil)

Returns a new instance of ExampleGroup

687
688
689
690
# File 'lib/rspec/core/example_group.rb', line 687
def initialize(inspect_output=nil)
  @__inspect_output = inspect_output || '(no description provided)'
  super() # no args get passed
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

- (void) method_missing(name, *args) (private)

738
739
740
741
742
743
744
745
746
747
748
# File 'lib/rspec/core/example_group.rb', line 738
def method_missing(name, *args)
  if self.class.respond_to?(name)
    raise WrongScopeError,
          "`#{name}` is not available from within an example (e.g. an " \
          "`it` block) or from constructs that run in the scope of an " \
          "example (e.g. `before`, `let`, etc). It is only available " \
          "on an example group (e.g. a `describe` or `context` block)."
  end
  super
end

Class Method Details

+ (void) add_example(example)

Adds an example to the example group

354
355
356
357
# File 'lib/rspec/core/example_group.rb', line 354
def self.add_example(example)
  reset_memoized
  examples << example
end

+ (void) context + (void) context(&example_group_definition) + (void) context(doc_string, *metadata_keys, metadata = {}, &example_implementation)

An alias of example_group. Generally used when grouping examples contextually (e.g. "with xyz", "when xyz" or "if xyz"). Generates a subclass of this example group which inherits everything except the examples themselves.

Examples:


RSpec.describe "something" do # << This describe method is defined in
                              # << RSpec::Core::DSL, included in the
                              # << global namespace (optional)
  before do
    do_something_before
  end
  let(:thing) { Thing.new }
  context "attribute (of something)" do
    # examples in the group get the before hook
    # declared above, and can access `thing`
  end
end

Overloads:

  • + (void) context(&example_group_definition)

    Parameters:

    • example_group_definition (Block)

      The definition of the example group.

  • + (void) context(doc_string, *metadata_keys, metadata = {}, &example_implementation)

    Parameters:

    • doc_string (String)

      The group's doc string.

    • metadata (Hash) (defaults to: {})

      Metadata for the group.

    • metadata_keys (Array<Symbol>)

      Metadata tags for the group. Will be transformed into hash entries with true values.

    • example_group_definition (Block)

      The definition of the example group.

See Also:

277
# File 'lib/rspec/core/example_group.rb', line 277
define_example_group_method :context

+ (Boolean) currently_executing_a_context_hook?

Returns true if a before(:context) or after(:context) hook is currently executing.

Returns:

  • (Boolean)
525
526
527
# File 'lib/rspec/core/example_group.rb', line 525
def self.currently_executing_a_context_hook?
  @currently_executing_a_context_hook
end

+ (void) describe + (void) describe(&example_group_definition) + (void) describe(doc_string, *metadata_keys, metadata = {}, &example_implementation)

An alias of example_group. Generally used when grouping examples by a thing you are describing (e.g. an object, class or method). Generates a subclass of this example group which inherits everything except the examples themselves.

Examples:


RSpec.describe "something" do # << This describe method is defined in
                              # << RSpec::Core::DSL, included in the
                              # << global namespace (optional)
  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

Overloads:

  • + (void) describe(&example_group_definition)

    Parameters:

    • example_group_definition (Block)

      The definition of the example group.

  • + (void) describe(doc_string, *metadata_keys, metadata = {}, &example_implementation)

    Parameters:

    • doc_string (String)

      The group's doc string.

    • metadata (Hash) (defaults to: {})

      Metadata for the group.

    • metadata_keys (Array<Symbol>)

      Metadata tags for the group. Will be transformed into hash entries with true values.

    • example_group_definition (Block)

      The definition of the example group.

See Also:

272
# File 'lib/rspec/core/example_group.rb', line 272
define_example_group_method :describe

+ (String) description

Returns the current example group description

Returns:

  • (String)

    the current example group description

84
85
86
87
# File 'lib/rspec/core/example_group.rb', line 84
def self.description
  description = [:description]
  RSpec.configuration.format_docstrings_block.call(description)
end

+ (void) example + (void) example(&example_implementation) + (void) example(doc_string, *metadata_keys, metadata = {}) + (void) example(doc_string, *metadata_keys, metadata = {}, &example_implementation)

Defines an example within a group.

Examples:

example do
end
example "does something" do
end
example "does something", :slow, :uses_js do
end
example "does something", :with => 'additional metadata' do
end
example "does something" do |ex|
  # ex is the Example object that contains metadata about the example
end

Overloads:

  • + (void) example(&example_implementation)

    Parameters:

    • example_implementation (Block)

      The implementation of the example.

  • + (void) example(doc_string, *metadata_keys, metadata = {})

    Parameters:

    • doc_string (String)

      The example's doc string.

    • metadata (Hash) (defaults to: {})

      Metadata for the example.

    • metadata_keys (Array<Symbol>)

      Metadata tags for the example. Will be transformed into hash entries with true values.

  • + (void) example(doc_string, *metadata_keys, metadata = {}, &example_implementation)

    Parameters:

    • doc_string (String)

      The example's doc string.

    • metadata (Hash) (defaults to: {})

      Metadata for the example.

    • metadata_keys (Array<Symbol>)

      Metadata tags for the example. Will be transformed into hash entries with true values.

    • example_implementation (Block)

      The implementation of the example.

Yields:

153
# File 'lib/rspec/core/example_group.rb', line 153
define_example_method :example

+ (void) example_group + (void) example_group(&example_group_definition) + (void) example_group(doc_string, *metadata_keys, metadata = {}, &example_implementation)

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

Examples:


RSpec.describe "something" do # << This describe method is defined in
                              # << RSpec::Core::DSL, included in the
                              # << global namespace (optional)
  before do
    do_something_before
  end
  let(:thing) { Thing.new }
  example_group "attribute (of something)" do
    # examples in the group get the before hook
    # declared above, and can access `thing`
  end
end

Overloads:

  • + (void) example_group(&example_group_definition)

    Parameters:

    • example_group_definition (Block)

      The definition of the example group.

  • + (void) example_group(doc_string, *metadata_keys, metadata = {}, &example_implementation)

    Parameters:

    • doc_string (String)

      The group's doc string.

    • metadata (Hash) (defaults to: {})

      Metadata for the group.

    • metadata_keys (Array<Symbol>)

      Metadata tags for the group. Will be transformed into hash entries with true values.

    • example_group_definition (Block)

      The definition of the example group.

267
# File 'lib/rspec/core/example_group.rb', line 267
define_example_group_method :example_group

+ (void) fcontext + (void) fcontext(&example_group_definition) + (void) fcontext(doc_string, *metadata_keys, metadata = {}, &example_implementation)

Shortcut to define an example group with :focus => true. Generates a subclass of this example group which inherits everything except the examples themselves.

Examples:


RSpec.describe "something" do # << This describe method is defined in
                              # << RSpec::Core::DSL, included in the
                              # << global namespace (optional)
  before do
    do_something_before
  end
  let(:thing) { Thing.new }
  fcontext "attribute (of something)" do
    # examples in the group get the before hook
    # declared above, and can access `thing`
  end
end

Overloads:

  • + (void) fcontext(&example_group_definition)

    Parameters:

    • example_group_definition (Block)

      The definition of the example group.

  • + (void) fcontext(doc_string, *metadata_keys, metadata = {}, &example_implementation)

    Parameters:

    • doc_string (String)

      The group's doc string.

    • metadata (Hash) (defaults to: {})

      Metadata for the group.

    • metadata_keys (Array<Symbol>)

      Metadata tags for the group. Will be transformed into hash entries with true values.

    • example_group_definition (Block)

      The definition of the example group.

See Also:

293
# File 'lib/rspec/core/example_group.rb', line 293
define_example_group_method :fcontext,  :focus => true

+ (void) fdescribe + (void) fdescribe(&example_group_definition) + (void) fdescribe(doc_string, *metadata_keys, metadata = {}, &example_implementation)

Shortcut to define an example group with :focus => true. Generates a subclass of this example group which inherits everything except the examples themselves.

Examples:


RSpec.describe "something" do # << This describe method is defined in
                              # << RSpec::Core::DSL, included in the
                              # << global namespace (optional)
  before do
    do_something_before
  end
  let(:thing) { Thing.new }
  fdescribe "attribute (of something)" do
    # examples in the group get the before hook
    # declared above, and can access `thing`
  end
end

Overloads:

  • + (void) fdescribe(&example_group_definition)

    Parameters:

    • example_group_definition (Block)

      The definition of the example group.

  • + (void) fdescribe(doc_string, *metadata_keys, metadata = {}, &example_implementation)

    Parameters:

    • doc_string (String)

      The group's doc string.

    • metadata (Hash) (defaults to: {})

      Metadata for the group.

    • metadata_keys (Array<Symbol>)

      Metadata tags for the group. Will be transformed into hash entries with true values.

    • example_group_definition (Block)

      The definition of the example group.

See Also:

289
# File 'lib/rspec/core/example_group.rb', line 289
define_example_group_method :fdescribe, :focus => true

+ (void) fexample + (void) fexample(&example_implementation) + (void) fexample(doc_string, *metadata_keys, metadata = {}) + (void) fexample(doc_string, *metadata_keys, metadata = {}, &example_implementation)

Shortcut to define an example with :focus => true.

Examples:

fexample do
end
fexample "does something" do
end
fexample "does something", :slow, :uses_js do
end
fexample "does something", :with => 'additional metadata' do
end
fexample "does something" do |ex|
  # ex is the Example object that contains metadata about the example
end

Overloads:

  • + (void) fexample(&example_implementation)

    Parameters:

    • example_implementation (Block)

      The implementation of the example.

  • + (void) fexample(doc_string, *metadata_keys, metadata = {})

    Parameters:

    • doc_string (String)

      The example's doc string.

    • metadata (Hash) (defaults to: {})

      Metadata for the example.

    • metadata_keys (Array<Symbol>)

      Metadata tags for the example. Will be transformed into hash entries with true values.

  • + (void) fexample(doc_string, *metadata_keys, metadata = {}, &example_implementation)

    Parameters:

    • doc_string (String)

      The example's doc string.

    • metadata (Hash) (defaults to: {})

      Metadata for the example.

    • metadata_keys (Array<Symbol>)

      Metadata tags for the example. Will be transformed into hash entries with true values.

    • example_implementation (Block)

      The implementation of the example.

Yields:

See Also:

172
# File 'lib/rspec/core/example_group.rb', line 172
define_example_method :fexample, :focus => true

+ (void) fit + (void) fit(&example_implementation) + (void) fit(doc_string, *metadata_keys, metadata = {}) + (void) fit(doc_string, *metadata_keys, metadata = {}, &example_implementation)

Shortcut to define an example with :focus => true.

Examples:

fit do
end
fit "does something" do
end
fit "does something", :slow, :uses_js do
end
fit "does something", :with => 'additional metadata' do
end
fit "does something" do |ex|
  # ex is the Example object that contains metadata about the example
end

Overloads:

  • + (void) fit(&example_implementation)

    Parameters:

    • example_implementation (Block)

      The implementation of the example.

  • + (void) fit(doc_string, *metadata_keys, metadata = {})

    Parameters:

    • doc_string (String)

      The example's doc string.

    • metadata (Hash) (defaults to: {})

      Metadata for the example.

    • metadata_keys (Array<Symbol>)

      Metadata tags for the example. Will be transformed into hash entries with true values.

  • + (void) fit(doc_string, *metadata_keys, metadata = {}, &example_implementation)

    Parameters:

    • doc_string (String)

      The example's doc string.

    • metadata (Hash) (defaults to: {})

      Metadata for the example.

    • metadata_keys (Array<Symbol>)

      Metadata tags for the example. Will be transformed into hash entries with true values.

    • example_implementation (Block)

      The implementation of the example.

Yields:

See Also:

175
# File 'lib/rspec/core/example_group.rb', line 175
define_example_method :fit,      :focus => true

+ (void) focus + (void) focus(&example_implementation) + (void) focus(doc_string, *metadata_keys, metadata = {}) + (void) focus(doc_string, *metadata_keys, metadata = {}, &example_implementation)

Shortcut to define an example with :focus => true.

Examples:

focus do
end
focus "does something" do
end
focus "does something", :slow, :uses_js do
end
focus "does something", :with => 'additional metadata' do
end
focus "does something" do |ex|
  # ex is the Example object that contains metadata about the example
end

Overloads:

  • + (void) focus(&example_implementation)

    Parameters:

    • example_implementation (Block)

      The implementation of the example.

  • + (void) focus(doc_string, *metadata_keys, metadata = {})

    Parameters:

    • doc_string (String)

      The example's doc string.

    • metadata (Hash) (defaults to: {})

      Metadata for the example.

    • metadata_keys (Array<Symbol>)

      Metadata tags for the example. Will be transformed into hash entries with true values.

  • + (void) focus(doc_string, *metadata_keys, metadata = {}, &example_implementation)

    Parameters:

    • doc_string (String)

      The example's doc string.

    • metadata (Hash) (defaults to: {})

      Metadata for the example.

    • metadata_keys (Array<Symbol>)

      Metadata tags for the example. Will be transformed into hash entries with true values.

    • example_implementation (Block)

      The implementation of the example.

Yields:

See Also:

169
# File 'lib/rspec/core/example_group.rb', line 169
define_example_method :focus,    :focus => true

+ (void) fspecify + (void) fspecify(&example_implementation) + (void) fspecify(doc_string, *metadata_keys, metadata = {}) + (void) fspecify(doc_string, *metadata_keys, metadata = {}, &example_implementation)

Shortcut to define an example with :focus => true.

Examples:

fspecify do
end
fspecify "does something" do
end
fspecify "does something", :slow, :uses_js do
end
fspecify "does something", :with => 'additional metadata' do
end
fspecify "does something" do |ex|
  # ex is the Example object that contains metadata about the example
end

Overloads:

  • + (void) fspecify(&example_implementation)

    Parameters:

    • example_implementation (Block)

      The implementation of the example.

  • + (void) fspecify(doc_string, *metadata_keys, metadata = {})

    Parameters:

    • doc_string (String)

      The example's doc string.

    • metadata (Hash) (defaults to: {})

      Metadata for the example.

    • metadata_keys (Array<Symbol>)

      Metadata tags for the example. Will be transformed into hash entries with true values.

  • + (void) fspecify(doc_string, *metadata_keys, metadata = {}, &example_implementation)

    Parameters:

    • doc_string (String)

      The example's doc string.

    • metadata (Hash) (defaults to: {})

      Metadata for the example.

    • metadata_keys (Array<Symbol>)

      Metadata tags for the example. Will be transformed into hash entries with true values.

    • example_implementation (Block)

      The implementation of the example.

Yields:

See Also:

178
# File 'lib/rspec/core/example_group.rb', line 178
define_example_method :fspecify, :focus => true

+ (String) id

Returns the unique id of this example group. Pass this at the command line to re-run this exact example group.

Returns:

  • (String)

    the unique id of this example group. Pass this at the command line to re-run this exact example group.

656
657
658
# File 'lib/rspec/core/example_group.rb', line 656
def self.id
  Metadata.id_from()
end

+ (void) include_context(name, *args, &block)

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 Also:

330
331
332
# File 'lib/rspec/core/example_group.rb', line 330
def self.include_context(name, *args, &block)
  find_and_eval_shared("context", name, caller.first, *args, &block)
end

+ (void) include_examples(name, *args, &block)

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 Also:

340
341
342
# File 'lib/rspec/core/example_group.rb', line 340
def self.include_examples(name, *args, &block)
  find_and_eval_shared("examples", name, caller.first, *args, &block)
end

+ (void) it + (void) it(&example_implementation) + (void) it(doc_string, *metadata_keys, metadata = {}) + (void) it(doc_string, *metadata_keys, metadata = {}, &example_implementation)

Defines an example within a group. This is the primary API to define a code example.

Examples:

it do
end
it "does something" do
end
it "does something", :slow, :uses_js do
end
it "does something", :with => 'additional metadata' do
end
it "does something" do |ex|
  # ex is the Example object that contains metadata about the example
end

Overloads:

  • + (void) it(&example_implementation)

    Parameters:

    • example_implementation (Block)

      The implementation of the example.

  • + (void) it(doc_string, *metadata_keys, metadata = {})

    Parameters:

    • doc_string (String)

      The example's doc string.

    • metadata (Hash) (defaults to: {})

      Metadata for the example.

    • metadata_keys (Array<Symbol>)

      Metadata tags for the example. Will be transformed into hash entries with true values.

  • + (void) it(doc_string, *metadata_keys, metadata = {}, &example_implementation)

    Parameters:

    • doc_string (String)

      The example's doc string.

    • metadata (Hash) (defaults to: {})

      Metadata for the example.

    • metadata_keys (Array<Symbol>)

      Metadata tags for the example. Will be transformed into hash entries with true values.

    • example_implementation (Block)

      The implementation of the example.

Yields:

156
# File 'lib/rspec/core/example_group.rb', line 156
define_example_method :it

+ (void) it_behaves_like

Generates a nested example group and includes the shared content mapped to name in the nested group.

See Also:

319
# File 'lib/rspec/core/example_group.rb', line 319
define_nested_shared_group_method :it_behaves_like, "behaves like"

+ (void) it_should_behave_like

Generates a nested example group and includes the shared content mapped to name in the nested group.

See Also:

322
# File 'lib/rspec/core/example_group.rb', line 322
define_nested_shared_group_method :it_should_behave_like

+ (void) metadata

The Metadata object associated with this group.

See Also:

50
51
52
# File 'lib/rspec/core/example_group.rb', line 50
def self.
  @metadata ||= nil
end

+ (void) pending + (void) pending(&example_implementation) + (void) pending(doc_string, *metadata_keys, metadata = {}) + (void) pending(doc_string, *metadata_keys, metadata = {}, &example_implementation)

Shortcut to define an example with :pending => true

Examples:

pending do
end
pending "does something" do
end
pending "does something", :slow, :uses_js do
end
pending "does something", :with => 'additional metadata' do
end
pending "does something" do |ex|
  # ex is the Example object that contains metadata about the example
end

Overloads:

  • + (void) pending(&example_implementation)

    Parameters:

    • example_implementation (Block)

      The implementation of the example.

  • + (void) pending(doc_string, *metadata_keys, metadata = {})

    Parameters:

    • doc_string (String)

      The example's doc string.

    • metadata (Hash) (defaults to: {})

      Metadata for the example.

    • metadata_keys (Array<Symbol>)

      Metadata tags for the example. Will be transformed into hash entries with true values.

  • + (void) pending(doc_string, *metadata_keys, metadata = {}, &example_implementation)

    Parameters:

    • doc_string (String)

      The example's doc string.

    • metadata (Hash) (defaults to: {})

      Metadata for the example.

    • metadata_keys (Array<Symbol>)

      Metadata tags for the example. Will be transformed into hash entries with true values.

    • example_implementation (Block)

      The implementation of the example.

Yields:

See Also:

193
# File 'lib/rspec/core/example_group.rb', line 193
define_example_method :pending,  :pending => true

+ (void) remove_example(example)

Removes an example from the example group

360
361
362
363
# File 'lib/rspec/core/example_group.rb', line 360
def self.remove_example(example)
  reset_memoized
  examples.delete example
end

+ (void) run(reporter = RSpec::Core::NullReporter)

Runs all the examples in this group.

582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
# File 'lib/rspec/core/example_group.rb', line 582
def self.run(reporter=RSpec::Core::NullReporter)
  return if RSpec.world.wants_to_quit
  reporter.example_group_started(self)
  should_run_context_hooks = descendant_filtered_examples.any?
  begin
    run_before_context_hooks(new('before(:context) hook')) if should_run_context_hooks
    result_for_this_group = run_examples(reporter)
    results_for_descendants = ordering_strategy.order(children).map { |child| child.run(reporter) }.all?
    result_for_this_group && results_for_descendants
  rescue Pending::SkipDeclaredInExample => ex
    for_filtered_examples(reporter) { |example| example.skip_with_exception(reporter, ex) }
    true
  rescue Support::AllExceptionsExceptOnesWeMustNotRescue => ex
    for_filtered_examples(reporter) { |example| example.fail_with_exception(reporter, ex) }
    RSpec.world.wants_to_quit = true if reporter.fail_fast_limit_met?
    false
  ensure
    run_after_context_hooks(new('after(:context) hook')) if should_run_context_hooks
    reporter.example_group_finished(self)
  end
end

+ (void) skip + (void) skip(&example_implementation) + (void) skip(doc_string, *metadata_keys, metadata = {}) + (void) skip(doc_string, *metadata_keys, metadata = {}, &example_implementation)

Shortcut to define an example with :skip => true

Examples:

skip do
end
skip "does something" do
end
skip "does something", :slow, :uses_js do
end
skip "does something", :with => 'additional metadata' do
end
skip "does something" do |ex|
  # ex is the Example object that contains metadata about the example
end

Overloads:

  • + (void) skip(&example_implementation)

    Parameters:

    • example_implementation (Block)

      The implementation of the example.

  • + (void) skip(doc_string, *metadata_keys, metadata = {})

    Parameters:

    • doc_string (String)

      The example's doc string.

    • metadata (Hash) (defaults to: {})

      Metadata for the example.

    • metadata_keys (Array<Symbol>)

      Metadata tags for the example. Will be transformed into hash entries with true values.

  • + (void) skip(doc_string, *metadata_keys, metadata = {}, &example_implementation)

    Parameters:

    • doc_string (String)

      The example's doc string.

    • metadata (Hash) (defaults to: {})

      Metadata for the example.

    • metadata_keys (Array<Symbol>)

      Metadata tags for the example. Will be transformed into hash entries with true values.

    • example_implementation (Block)

      The implementation of the example.

Yields:

See Also:

190
# File 'lib/rspec/core/example_group.rb', line 190
define_example_method :skip,     :skip => true

+ (void) specify + (void) specify(&example_implementation) + (void) specify(doc_string, *metadata_keys, metadata = {}) + (void) specify(doc_string, *metadata_keys, metadata = {}, &example_implementation)

Defines an example within a group. Useful for when your docstring does not read well off of it.

Examples:

RSpec.describe MyClass do
  specify "#do_something is deprecated" do
    # ...
  end
end
specify do
end
specify "does something" do
end
specify "does something", :slow, :uses_js do
end
specify "does something", :with => 'additional metadata' do
end
specify "does something" do |ex|
  # ex is the Example object that contains metadata about the example
end

Overloads:

  • + (void) specify(&example_implementation)

    Parameters:

    • example_implementation (Block)

      The implementation of the example.

  • + (void) specify(doc_string, *metadata_keys, metadata = {})

    Parameters:

    • doc_string (String)

      The example's doc string.

    • metadata (Hash) (defaults to: {})

      Metadata for the example.

    • metadata_keys (Array<Symbol>)

      Metadata tags for the example. Will be transformed into hash entries with true values.

  • + (void) specify(doc_string, *metadata_keys, metadata = {}, &example_implementation)

    Parameters:

    • doc_string (String)

      The example's doc string.

    • metadata (Hash) (defaults to: {})

      Metadata for the example.

    • metadata_keys (Array<Symbol>)

      Metadata tags for the example. Will be transformed into hash entries with true values.

    • example_implementation (Block)

      The implementation of the example.

Yields:

165
# File 'lib/rspec/core/example_group.rb', line 165
define_example_method :specify

+ (void) xcontext + (void) xcontext(&example_group_definition) + (void) xcontext(doc_string, *metadata_keys, metadata = {}, &example_implementation)

Shortcut to temporarily make an example group skipped. Generates a subclass of this example group which inherits everything except the examples themselves.

Examples:


RSpec.describe "something" do # << This describe method is defined in
                              # << RSpec::Core::DSL, included in the
                              # << global namespace (optional)
  before do
    do_something_before
  end
  let(:thing) { Thing.new }
  xcontext "attribute (of something)" do
    # examples in the group get the before hook
    # declared above, and can access `thing`
  end
end

Overloads:

  • + (void) xcontext(&example_group_definition)

    Parameters:

    • example_group_definition (Block)

      The definition of the example group.

  • + (void) xcontext(doc_string, *metadata_keys, metadata = {}, &example_implementation)

    Parameters:

    • doc_string (String)

      The group's doc string.

    • metadata (Hash) (defaults to: {})

      Metadata for the group.

    • metadata_keys (Array<Symbol>)

      Metadata tags for the group. Will be transformed into hash entries with true values.

    • example_group_definition (Block)

      The definition of the example group.

See Also:

285
# File 'lib/rspec/core/example_group.rb', line 285
define_example_group_method :xcontext,  :skip => "Temporarily skipped with xcontext"

+ (void) xdescribe + (void) xdescribe(&example_group_definition) + (void) xdescribe(doc_string, *metadata_keys, metadata = {}, &example_implementation)

Shortcut to temporarily make an example group skipped. Generates a subclass of this example group which inherits everything except the examples themselves.

Examples:


RSpec.describe "something" do # << This describe method is defined in
                              # << RSpec::Core::DSL, included in the
                              # << global namespace (optional)
  before do
    do_something_before
  end
  let(:thing) { Thing.new }
  xdescribe "attribute (of something)" do
    # examples in the group get the before hook
    # declared above, and can access `thing`
  end
end

Overloads:

  • + (void) xdescribe(&example_group_definition)

    Parameters:

    • example_group_definition (Block)

      The definition of the example group.

  • + (void) xdescribe(doc_string, *metadata_keys, metadata = {}, &example_implementation)

    Parameters:

    • doc_string (String)

      The group's doc string.

    • metadata (Hash) (defaults to: {})

      Metadata for the group.

    • metadata_keys (Array<Symbol>)

      Metadata tags for the group. Will be transformed into hash entries with true values.

    • example_group_definition (Block)

      The definition of the example group.

See Also:

281
# File 'lib/rspec/core/example_group.rb', line 281
define_example_group_method :xdescribe, :skip => "Temporarily skipped with xdescribe"

+ (void) xexample + (void) xexample(&example_implementation) + (void) xexample(doc_string, *metadata_keys, metadata = {}) + (void) xexample(doc_string, *metadata_keys, metadata = {}, &example_implementation)

Shortcut to define an example with :skip => 'Temporarily skipped with xexample'.

Examples:

xexample do
end
xexample "does something" do
end
xexample "does something", :slow, :uses_js do
end
xexample "does something", :with => 'additional metadata' do
end
xexample "does something" do |ex|
  # ex is the Example object that contains metadata about the example
end

Overloads:

  • + (void) xexample(&example_implementation)

    Parameters:

    • example_implementation (Block)

      The implementation of the example.

  • + (void) xexample(doc_string, *metadata_keys, metadata = {})

    Parameters:

    • doc_string (String)

      The example's doc string.

    • metadata (Hash) (defaults to: {})

      Metadata for the example.

    • metadata_keys (Array<Symbol>)

      Metadata tags for the example. Will be transformed into hash entries with true values.

  • + (void) xexample(doc_string, *metadata_keys, metadata = {}, &example_implementation)

    Parameters:

    • doc_string (String)

      The example's doc string.

    • metadata (Hash) (defaults to: {})

      Metadata for the example.

    • metadata_keys (Array<Symbol>)

      Metadata tags for the example. Will be transformed into hash entries with true values.

    • example_implementation (Block)

      The implementation of the example.

Yields:

See Also:

181
# File 'lib/rspec/core/example_group.rb', line 181
define_example_method :xexample, :skip => 'Temporarily skipped with xexample'

+ (void) xit + (void) xit(&example_implementation) + (void) xit(doc_string, *metadata_keys, metadata = {}) + (void) xit(doc_string, *metadata_keys, metadata = {}, &example_implementation)

Shortcut to define an example with :skip => 'Temporarily skipped with xit'.

Examples:

xit do
end
xit "does something" do
end
xit "does something", :slow, :uses_js do
end
xit "does something", :with => 'additional metadata' do
end
xit "does something" do |ex|
  # ex is the Example object that contains metadata about the example
end

Overloads:

  • + (void) xit(&example_implementation)

    Parameters:

    • example_implementation (Block)

      The implementation of the example.

  • + (void) xit(doc_string, *metadata_keys, metadata = {})

    Parameters:

    • doc_string (String)

      The example's doc string.

    • metadata (Hash) (defaults to: {})

      Metadata for the example.

    • metadata_keys (Array<Symbol>)

      Metadata tags for the example. Will be transformed into hash entries with true values.

  • + (void) xit(doc_string, *metadata_keys, metadata = {}, &example_implementation)

    Parameters:

    • doc_string (String)

      The example's doc string.

    • metadata (Hash) (defaults to: {})

      Metadata for the example.

    • metadata_keys (Array<Symbol>)

      Metadata tags for the example. Will be transformed into hash entries with true values.

    • example_implementation (Block)

      The implementation of the example.

Yields:

See Also:

184
# File 'lib/rspec/core/example_group.rb', line 184
define_example_method :xit,      :skip => 'Temporarily skipped with xit'

+ (void) xspecify + (void) xspecify(&example_implementation) + (void) xspecify(doc_string, *metadata_keys, metadata = {}) + (void) xspecify(doc_string, *metadata_keys, metadata = {}, &example_implementation)

Shortcut to define an example with :skip => 'Temporarily skipped with xspecify'.

Examples:

xspecify do
end
xspecify "does something" do
end
xspecify "does something", :slow, :uses_js do
end
xspecify "does something", :with => 'additional metadata' do
end
xspecify "does something" do |ex|
  # ex is the Example object that contains metadata about the example
end

Overloads:

  • + (void) xspecify(&example_implementation)

    Parameters:

    • example_implementation (Block)

      The implementation of the example.

  • + (void) xspecify(doc_string, *metadata_keys, metadata = {})

    Parameters:

    • doc_string (String)

      The example's doc string.

    • metadata (Hash) (defaults to: {})

      Metadata for the example.

    • metadata_keys (Array<Symbol>)

      Metadata tags for the example. Will be transformed into hash entries with true values.

  • + (void) xspecify(doc_string, *metadata_keys, metadata = {}, &example_implementation)

    Parameters:

    • doc_string (String)

      The example's doc string.

    • metadata (Hash) (defaults to: {})

      Metadata for the example.

    • metadata_keys (Array<Symbol>)

      Metadata tags for the example. Will be transformed into hash entries with true values.

    • example_implementation (Block)

      The implementation of the example.

Yields:

See Also:

187
# File 'lib/rspec/core/example_group.rb', line 187
define_example_method :xspecify, :skip => 'Temporarily skipped with xspecify'

Instance Method Details

- (void) described_class

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

Examples:

describe Thing do
  it "does something" do
    described_class == Thing
  end
end
98
99
100
# File 'lib/rspec/core/example_group.rb', line 98
def described_class
  self.class.described_class
end