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

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

RSpec.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 collapse

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

Methods included from Hooks

after, append_after, around, before, prepend_before

Methods included from MemoizedHelpers::ClassMethods

let, let!, subject, subject!

Methods included from SharedExampleGroup

shared_examples

Methods included from Pending

#pending, #skip

Methods included from MemoizedHelpers

#is_expected, #should, #should_not, #subject

Class Method Details

.add_example(example) ⇒ void

Adds an example to the example group


374
375
376
377
# File 'lib/rspec/core/example_group.rb', line 374

def self.add_example(example)
  reset_memoized
  examples << example
end

.contextRSpec::Core::ExampleGroup .context(&example_group_definition) ⇒ RSpec::Core::ExampleGroup .context(doc_string, *metadata, &example_implementation) ⇒ RSpec::Core::ExampleGroup

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

  before(:example, :clean_env) do
    env.clear!
  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

  context "needs additional setup", :clean_env, :implementation => JSON do
    # specifies that hooks with matching metadata
    # should be be run additionally
  end
end

Overloads:

  • .context(&example_group_definition) ⇒ RSpec::Core::ExampleGroup

    Parameters:

    • example_group_definition (Block)

      The definition of the example group.

  • .context(doc_string, *metadata, &example_implementation) ⇒ RSpec::Core::ExampleGroup

    Parameters:

    • doc_string (String)

      The group's doc string.

    • metadata (Array<Symbol>, Hash)

      Metadata for the group. Symbols will be transformed into hash entries with true values.

    • example_group_definition (Block)

      The definition of the example group.

Returns:

See Also:


292
# File 'lib/rspec/core/example_group.rb', line 292

define_example_group_method :context

.currently_executing_a_context_hook?Boolean

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

Returns:

  • (Boolean)

549
550
551
# File 'lib/rspec/core/example_group.rb', line 549

def self.currently_executing_a_context_hook?
  @currently_executing_a_context_hook
end

.describeRSpec::Core::ExampleGroup .describe(&example_group_definition) ⇒ RSpec::Core::ExampleGroup .describe(doc_string, *metadata, &example_implementation) ⇒ RSpec::Core::ExampleGroup

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

  before(:example, :clean_env) do
    env.clear!
  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

  describe "needs additional setup", :clean_env, :implementation => JSON do
    # specifies that hooks with matching metadata
    # should be be run additionally
  end
end

Overloads:

  • .describe(&example_group_definition) ⇒ RSpec::Core::ExampleGroup

    Parameters:

    • example_group_definition (Block)

      The definition of the example group.

  • .describe(doc_string, *metadata, &example_implementation) ⇒ RSpec::Core::ExampleGroup

    Parameters:

    • doc_string (String)

      The group's doc string.

    • metadata (Array<Symbol>, Hash)

      Metadata for the group. Symbols will be transformed into hash entries with true values.

    • example_group_definition (Block)

      The definition of the example group.

Returns:

See Also:


287
# File 'lib/rspec/core/example_group.rb', line 287

define_example_group_method :describe

.descriptionString

Returns the current example group description.

Returns:

  • (String)

    the current example group description


85
86
87
88
# File 'lib/rspec/core/example_group.rb', line 85

def self.description
  description = [:description]
  RSpec.configuration.format_docstrings_block.call(description)
end

.examplevoid .example(&example_implementation) ⇒ void .example(doc_string, *metadata) ⇒ void .example(doc_string, *metadata, &example_implementation) ⇒ void

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:

  • .example(&example_implementation) ⇒ void

    Parameters:

    • example_implementation (Block)

      The implementation of the example.

  • .example(doc_string, *metadata) ⇒ void

    Parameters:

    • doc_string (String)

      The example's doc string.

    • metadata (Array<Symbol>, Hash)

      Metadata for the example. Symbols will be transformed into hash entries with true values.

  • .example(doc_string, *metadata, &example_implementation) ⇒ void

    Parameters:

    • doc_string (String)

      The example's doc string.

    • metadata (Array<Symbol>, Hash)

      Metadata for the example. Symbols will be transformed into hash entries with true values.

    • example_implementation (Block)

      The implementation of the example.

Yields:


158
# File 'lib/rspec/core/example_group.rb', line 158

define_example_method :example

.example_groupRSpec::Core::ExampleGroup .example_group(&example_group_definition) ⇒ RSpec::Core::ExampleGroup .example_group(doc_string, *metadata, &example_implementation) ⇒ RSpec::Core::ExampleGroup

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

  before(:example, :clean_env) do
    env.clear!
  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

  example_group "needs additional setup", :clean_env, :implementation => JSON do
    # specifies that hooks with matching metadata
    # should be be run additionally
  end
end

Overloads:

  • .example_group(&example_group_definition) ⇒ RSpec::Core::ExampleGroup

    Parameters:

    • example_group_definition (Block)

      The definition of the example group.

  • .example_group(doc_string, *metadata, &example_implementation) ⇒ RSpec::Core::ExampleGroup

    Parameters:

    • doc_string (String)

      The group's doc string.

    • metadata (Array<Symbol>, Hash)

      Metadata for the group. Symbols will be transformed into hash entries with true values.

    • example_group_definition (Block)

      The definition of the example group.

Returns:


282
# File 'lib/rspec/core/example_group.rb', line 282

define_example_group_method :example_group

.fcontextRSpec::Core::ExampleGroup .fcontext(&example_group_definition) ⇒ RSpec::Core::ExampleGroup .fcontext(doc_string, *metadata, &example_implementation) ⇒ RSpec::Core::ExampleGroup

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

  before(:example, :clean_env) do
    env.clear!
  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

  fcontext "needs additional setup", :clean_env, :implementation => JSON do
    # specifies that hooks with matching metadata
    # should be be run additionally
  end
end

Overloads:

  • .fcontext(&example_group_definition) ⇒ RSpec::Core::ExampleGroup

    Parameters:

    • example_group_definition (Block)

      The definition of the example group.

  • .fcontext(doc_string, *metadata, &example_implementation) ⇒ RSpec::Core::ExampleGroup

    Parameters:

    • doc_string (String)

      The group's doc string.

    • metadata (Array<Symbol>, Hash)

      Metadata for the group. Symbols will be transformed into hash entries with true values.

    • example_group_definition (Block)

      The definition of the example group.

Returns:

See Also:


308
# File 'lib/rspec/core/example_group.rb', line 308

define_example_group_method :fcontext,  :focus => true

.fdescribeRSpec::Core::ExampleGroup .fdescribe(&example_group_definition) ⇒ RSpec::Core::ExampleGroup .fdescribe(doc_string, *metadata, &example_implementation) ⇒ RSpec::Core::ExampleGroup

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

  before(:example, :clean_env) do
    env.clear!
  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

  fdescribe "needs additional setup", :clean_env, :implementation => JSON do
    # specifies that hooks with matching metadata
    # should be be run additionally
  end
end

Overloads:

  • .fdescribe(&example_group_definition) ⇒ RSpec::Core::ExampleGroup

    Parameters:

    • example_group_definition (Block)

      The definition of the example group.

  • .fdescribe(doc_string, *metadata, &example_implementation) ⇒ RSpec::Core::ExampleGroup

    Parameters:

    • doc_string (String)

      The group's doc string.

    • metadata (Array<Symbol>, Hash)

      Metadata for the group. Symbols will be transformed into hash entries with true values.

    • example_group_definition (Block)

      The definition of the example group.

Returns:

See Also:


304
# File 'lib/rspec/core/example_group.rb', line 304

define_example_group_method :fdescribe, :focus => true

.fexamplevoid .fexample(&example_implementation) ⇒ void .fexample(doc_string, *metadata) ⇒ void .fexample(doc_string, *metadata, &example_implementation) ⇒ void

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:

  • .fexample(&example_implementation) ⇒ void

    Parameters:

    • example_implementation (Block)

      The implementation of the example.

  • .fexample(doc_string, *metadata) ⇒ void

    Parameters:

    • doc_string (String)

      The example's doc string.

    • metadata (Array<Symbol>, Hash)

      Metadata for the example. Symbols will be transformed into hash entries with true values.

  • .fexample(doc_string, *metadata, &example_implementation) ⇒ void

    Parameters:

    • doc_string (String)

      The example's doc string.

    • metadata (Array<Symbol>, Hash)

      Metadata for the example. Symbols will be transformed into hash entries with true values.

    • example_implementation (Block)

      The implementation of the example.

Yields:

See Also:


177
# File 'lib/rspec/core/example_group.rb', line 177

define_example_method :fexample, :focus => true

.fitvoid .fit(&example_implementation) ⇒ void .fit(doc_string, *metadata) ⇒ void .fit(doc_string, *metadata, &example_implementation) ⇒ void

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:

  • .fit(&example_implementation) ⇒ void

    Parameters:

    • example_implementation (Block)

      The implementation of the example.

  • .fit(doc_string, *metadata) ⇒ void

    Parameters:

    • doc_string (String)

      The example's doc string.

    • metadata (Array<Symbol>, Hash)

      Metadata for the example. Symbols will be transformed into hash entries with true values.

  • .fit(doc_string, *metadata, &example_implementation) ⇒ void

    Parameters:

    • doc_string (String)

      The example's doc string.

    • metadata (Array<Symbol>, Hash)

      Metadata for the example. Symbols will be transformed into hash entries with true values.

    • example_implementation (Block)

      The implementation of the example.

Yields:

See Also:


180
# File 'lib/rspec/core/example_group.rb', line 180

define_example_method :fit,      :focus => true

.focusvoid .focus(&example_implementation) ⇒ void .focus(doc_string, *metadata) ⇒ void .focus(doc_string, *metadata, &example_implementation) ⇒ void

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:

  • .focus(&example_implementation) ⇒ void

    Parameters:

    • example_implementation (Block)

      The implementation of the example.

  • .focus(doc_string, *metadata) ⇒ void

    Parameters:

    • doc_string (String)

      The example's doc string.

    • metadata (Array<Symbol>, Hash)

      Metadata for the example. Symbols will be transformed into hash entries with true values.

  • .focus(doc_string, *metadata, &example_implementation) ⇒ void

    Parameters:

    • doc_string (String)

      The example's doc string.

    • metadata (Array<Symbol>, Hash)

      Metadata for the example. Symbols will be transformed into hash entries with true values.

    • example_implementation (Block)

      The implementation of the example.

Yields:

See Also:


174
# File 'lib/rspec/core/example_group.rb', line 174

define_example_method :focus,    :focus => true

.fspecifyvoid .fspecify(&example_implementation) ⇒ void .fspecify(doc_string, *metadata) ⇒ void .fspecify(doc_string, *metadata, &example_implementation) ⇒ void

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:

  • .fspecify(&example_implementation) ⇒ void

    Parameters:

    • example_implementation (Block)

      The implementation of the example.

  • .fspecify(doc_string, *metadata) ⇒ void

    Parameters:

    • doc_string (String)

      The example's doc string.

    • metadata (Array<Symbol>, Hash)

      Metadata for the example. Symbols will be transformed into hash entries with true values.

  • .fspecify(doc_string, *metadata, &example_implementation) ⇒ void

    Parameters:

    • doc_string (String)

      The example's doc string.

    • metadata (Array<Symbol>, Hash)

      Metadata for the example. Symbols will be transformed into hash entries with true values.

    • example_implementation (Block)

      The implementation of the example.

Yields:

See Also:


183
# File 'lib/rspec/core/example_group.rb', line 183

define_example_method :fspecify, :focus => true

.idString

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.


682
683
684
# File 'lib/rspec/core/example_group.rb', line 682

def self.id
  Metadata.id_from()
end

.include_context(name, *args, &block) ⇒ void

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:


350
351
352
# File 'lib/rspec/core/example_group.rb', line 350

def self.include_context(name, *args, &block)
  find_and_eval_shared("context", name, caller.first, *args, &block)
end

.include_examples(name, *args, &block) ⇒ void

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:


360
361
362
# File 'lib/rspec/core/example_group.rb', line 360

def self.include_examples(name, *args, &block)
  find_and_eval_shared("examples", name, caller.first, *args, &block)
end

.itvoid .it(&example_implementation) ⇒ void .it(doc_string, *metadata) ⇒ void .it(doc_string, *metadata, &example_implementation) ⇒ void

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:

  • .it(&example_implementation) ⇒ void

    Parameters:

    • example_implementation (Block)

      The implementation of the example.

  • .it(doc_string, *metadata) ⇒ void

    Parameters:

    • doc_string (String)

      The example's doc string.

    • metadata (Array<Symbol>, Hash)

      Metadata for the example. Symbols will be transformed into hash entries with true values.

  • .it(doc_string, *metadata, &example_implementation) ⇒ void

    Parameters:

    • doc_string (String)

      The example's doc string.

    • metadata (Array<Symbol>, Hash)

      Metadata for the example. Symbols will be transformed into hash entries with true values.

    • example_implementation (Block)

      The implementation of the example.

Yields:


161
# File 'lib/rspec/core/example_group.rb', line 161

define_example_method :it

.it_behaves_like(name, *args, &block) ⇒ RSpec::Core::ExampleGroup

Parameters:

  • name (String, Symbol)

    The name of the shared group to include.

  • args (Array)

    Pass parameters to a shared example group

  • block (Block)

    Additional context to pass to the shared group.

Returns:


339
# File 'lib/rspec/core/example_group.rb', line 339

define_nested_shared_group_method :it_behaves_like, "behaves like"

.it_should_behave_like(name, *args, &block) ⇒ RSpec::Core::ExampleGroup

Parameters:

  • name (String, Symbol)

    The name of the shared group to include.

  • args (Array)

    Pass parameters to a shared example group

  • block (Block)

    Additional context to pass to the shared group.

Returns:


342
# File 'lib/rspec/core/example_group.rb', line 342

define_nested_shared_group_method :it_should_behave_like

.metadatavoid

The Metadata object associated with this group.

See Also:


51
52
53
# File 'lib/rspec/core/example_group.rb', line 51

def self.
  @metadata ||= nil
end

.pendingvoid .pending(&example_implementation) ⇒ void .pending(doc_string, *metadata) ⇒ void .pending(doc_string, *metadata, &example_implementation) ⇒ void

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:

  • .pending(&example_implementation) ⇒ void

    Parameters:

    • example_implementation (Block)

      The implementation of the example.

  • .pending(doc_string, *metadata) ⇒ void

    Parameters:

    • doc_string (String)

      The example's doc string.

    • metadata (Array<Symbol>, Hash)

      Metadata for the example. Symbols will be transformed into hash entries with true values.

  • .pending(doc_string, *metadata, &example_implementation) ⇒ void

    Parameters:

    • doc_string (String)

      The example's doc string.

    • metadata (Array<Symbol>, Hash)

      Metadata for the example. Symbols will be transformed into hash entries with true values.

    • example_implementation (Block)

      The implementation of the example.

Yields:

See Also:


198
# File 'lib/rspec/core/example_group.rb', line 198

define_example_method :pending,  :pending => true

.remove_example(example) ⇒ void

Removes an example from the example group


380
381
382
383
# File 'lib/rspec/core/example_group.rb', line 380

def self.remove_example(example)
  reset_memoized
  examples.delete example
end

.run(reporter = RSpec::Core::NullReporter) ⇒ void

Runs all the examples in this group.


606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
# File 'lib/rspec/core/example_group.rb', line 606

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
    RSpec.current_scope = :before_context_hook
    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
    RSpec.current_scope = :after_context_hook
    run_after_context_hooks(new('after(:context) hook')) if should_run_context_hooks
    reporter.example_group_finished(self)
  end
end

.skipvoid .skip(&example_implementation) ⇒ void .skip(doc_string, *metadata) ⇒ void .skip(doc_string, *metadata, &example_implementation) ⇒ void

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:

  • .skip(&example_implementation) ⇒ void

    Parameters:

    • example_implementation (Block)

      The implementation of the example.

  • .skip(doc_string, *metadata) ⇒ void

    Parameters:

    • doc_string (String)

      The example's doc string.

    • metadata (Array<Symbol>, Hash)

      Metadata for the example. Symbols will be transformed into hash entries with true values.

  • .skip(doc_string, *metadata, &example_implementation) ⇒ void

    Parameters:

    • doc_string (String)

      The example's doc string.

    • metadata (Array<Symbol>, Hash)

      Metadata for the example. Symbols will be transformed into hash entries with true values.

    • example_implementation (Block)

      The implementation of the example.

Yields:

See Also:


195
# File 'lib/rspec/core/example_group.rb', line 195

define_example_method :skip,     :skip => true

.specifyvoid .specify(&example_implementation) ⇒ void .specify(doc_string, *metadata) ⇒ void .specify(doc_string, *metadata, &example_implementation) ⇒ void

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:

  • .specify(&example_implementation) ⇒ void

    Parameters:

    • example_implementation (Block)

      The implementation of the example.

  • .specify(doc_string, *metadata) ⇒ void

    Parameters:

    • doc_string (String)

      The example's doc string.

    • metadata (Array<Symbol>, Hash)

      Metadata for the example. Symbols will be transformed into hash entries with true values.

  • .specify(doc_string, *metadata, &example_implementation) ⇒ void

    Parameters:

    • doc_string (String)

      The example's doc string.

    • metadata (Array<Symbol>, Hash)

      Metadata for the example. Symbols will be transformed into hash entries with true values.

    • example_implementation (Block)

      The implementation of the example.

Yields:


170
# File 'lib/rspec/core/example_group.rb', line 170

define_example_method :specify

.xcontextRSpec::Core::ExampleGroup .xcontext(&example_group_definition) ⇒ RSpec::Core::ExampleGroup .xcontext(doc_string, *metadata, &example_implementation) ⇒ RSpec::Core::ExampleGroup

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

  before(:example, :clean_env) do
    env.clear!
  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

  xcontext "needs additional setup", :clean_env, :implementation => JSON do
    # specifies that hooks with matching metadata
    # should be be run additionally
  end
end

Overloads:

  • .xcontext(&example_group_definition) ⇒ RSpec::Core::ExampleGroup

    Parameters:

    • example_group_definition (Block)

      The definition of the example group.

  • .xcontext(doc_string, *metadata, &example_implementation) ⇒ RSpec::Core::ExampleGroup

    Parameters:

    • doc_string (String)

      The group's doc string.

    • metadata (Array<Symbol>, Hash)

      Metadata for the group. Symbols will be transformed into hash entries with true values.

    • example_group_definition (Block)

      The definition of the example group.

Returns:

See Also:


300
# File 'lib/rspec/core/example_group.rb', line 300

define_example_group_method :xcontext,  :skip => "Temporarily skipped with xcontext"

.xdescribeRSpec::Core::ExampleGroup .xdescribe(&example_group_definition) ⇒ RSpec::Core::ExampleGroup .xdescribe(doc_string, *metadata, &example_implementation) ⇒ RSpec::Core::ExampleGroup

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

  before(:example, :clean_env) do
    env.clear!
  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

  xdescribe "needs additional setup", :clean_env, :implementation => JSON do
    # specifies that hooks with matching metadata
    # should be be run additionally
  end
end

Overloads:

  • .xdescribe(&example_group_definition) ⇒ RSpec::Core::ExampleGroup

    Parameters:

    • example_group_definition (Block)

      The definition of the example group.

  • .xdescribe(doc_string, *metadata, &example_implementation) ⇒ RSpec::Core::ExampleGroup

    Parameters:

    • doc_string (String)

      The group's doc string.

    • metadata (Array<Symbol>, Hash)

      Metadata for the group. Symbols will be transformed into hash entries with true values.

    • example_group_definition (Block)

      The definition of the example group.

Returns:

See Also:


296
# File 'lib/rspec/core/example_group.rb', line 296

define_example_group_method :xdescribe, :skip => "Temporarily skipped with xdescribe"

.xexamplevoid .xexample(&example_implementation) ⇒ void .xexample(doc_string, *metadata) ⇒ void .xexample(doc_string, *metadata, &example_implementation) ⇒ void

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:

  • .xexample(&example_implementation) ⇒ void

    Parameters:

    • example_implementation (Block)

      The implementation of the example.

  • .xexample(doc_string, *metadata) ⇒ void

    Parameters:

    • doc_string (String)

      The example's doc string.

    • metadata (Array<Symbol>, Hash)

      Metadata for the example. Symbols will be transformed into hash entries with true values.

  • .xexample(doc_string, *metadata, &example_implementation) ⇒ void

    Parameters:

    • doc_string (String)

      The example's doc string.

    • metadata (Array<Symbol>, Hash)

      Metadata for the example. Symbols will be transformed into hash entries with true values.

    • example_implementation (Block)

      The implementation of the example.

Yields:

See Also:


186
# File 'lib/rspec/core/example_group.rb', line 186

define_example_method :xexample, :skip => 'Temporarily skipped with xexample'

.xitvoid .xit(&example_implementation) ⇒ void .xit(doc_string, *metadata) ⇒ void .xit(doc_string, *metadata, &example_implementation) ⇒ void

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:

  • .xit(&example_implementation) ⇒ void

    Parameters:

    • example_implementation (Block)

      The implementation of the example.

  • .xit(doc_string, *metadata) ⇒ void

    Parameters:

    • doc_string (String)

      The example's doc string.

    • metadata (Array<Symbol>, Hash)

      Metadata for the example. Symbols will be transformed into hash entries with true values.

  • .xit(doc_string, *metadata, &example_implementation) ⇒ void

    Parameters:

    • doc_string (String)

      The example's doc string.

    • metadata (Array<Symbol>, Hash)

      Metadata for the example. Symbols will be transformed into hash entries with true values.

    • example_implementation (Block)

      The implementation of the example.

Yields:

See Also:


189
# File 'lib/rspec/core/example_group.rb', line 189

define_example_method :xit,      :skip => 'Temporarily skipped with xit'

.xspecifyvoid .xspecify(&example_implementation) ⇒ void .xspecify(doc_string, *metadata) ⇒ void .xspecify(doc_string, *metadata, &example_implementation) ⇒ void

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:

  • .xspecify(&example_implementation) ⇒ void

    Parameters:

    • example_implementation (Block)

      The implementation of the example.

  • .xspecify(doc_string, *metadata) ⇒ void

    Parameters:

    • doc_string (String)

      The example's doc string.

    • metadata (Array<Symbol>, Hash)

      Metadata for the example. Symbols will be transformed into hash entries with true values.

  • .xspecify(doc_string, *metadata, &example_implementation) ⇒ void

    Parameters:

    • doc_string (String)

      The example's doc string.

    • metadata (Array<Symbol>, Hash)

      Metadata for the example. Symbols will be transformed into hash entries with true values.

    • example_implementation (Block)

      The implementation of the example.

Yields:

See Also:


192
# File 'lib/rspec/core/example_group.rb', line 192

define_example_method :xspecify, :skip => 'Temporarily skipped with xspecify'

Instance Method Details

#described_classvoid

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

Examples:

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

99
100
101
# File 'lib/rspec/core/example_group.rb', line 99

def described_class
  self.class.described_class
end