Module: RSpec::SleepingKingStudios::Concerns::FocusExamples

Defined in:
lib/rspec/sleeping_king_studios/concerns/focus_examples.rb

Overview

Convenience methods for automatically focusing or skipping shared example groups.

Instance Method Summary collapse

Instance Method Details

#finclude_examples(name, *args, **kwargs) { ... } ⇒ Object Also known as: finclude_context

Note:

Do not use this method with example groups that have side effects, e.g. define a memoized #let helper or a #before block that is intended to modify the behavior of sibling examples. Wrapping the example group in a describe block breaks that relationship. Best practice is to use the #wrap_examples method to safely encapsulate example groups with side effects, and the #fwrap_examples method to automatically focus such groups.

Includes the specified shared example group and wraps it inside an fdescribe block named "(focused)". If the spec runner is set to run only focused specs, this will ensure that the wrapped example group is run.

Parameters:

  • name (String)

    The name of the shared example group to be wrapped.

  • args (Array)

    Optional array of arguments that are passed on to the shared example group.

  • kwargs (Hash)

    Optional hash of keyword arguments that are passed on to the shared example group.

Yields:

  • Optional block that is passed on to the shared example group.



28
29
30
31
32
33
34
35
36
# File 'lib/rspec/sleeping_king_studios/concerns/focus_examples.rb', line 28

def finclude_examples name, *args, **kwargs, &block
  fdescribe '(focused)' do
    if kwargs.empty?
      include_examples name, *args, &block
    else
      include_examples name, *args, **kwargs, &block
    end # if-else
  end # describe
end

#xinclude_examples(name, *args, **kwargs) { ... } ⇒ Object Also known as: xinclude_context

Note:

Do not use this method with example groups that have side effects, e.g. define a memoized #let helper or a #before block that is intended to modify the behavior of sibling examples. Wrapping the example group in a describe block breaks that relationship. Best practice is to use the #wrap_examples method to safely encapsulate example groups with side effects, and the #xwrap_examples method to automatically skip such groups.

Includes the specified shared example group and wraps it inside an xdescribe block named "(skipped)". This will ensure that the wrapped example group is not run.

groups.

Parameters:

  • name (String)

    The name of the shared example group to be wrapped.

  • args (Array)

    Optional array of arguments that are passed on to the shared example group.

  • kwargs (Hash)

    Optional hash of keyword arguments that are passed on to the shared example group.

Yields:

  • Optional block that is passed on to the shared example group.



59
60
61
62
63
64
65
66
67
# File 'lib/rspec/sleeping_king_studios/concerns/focus_examples.rb', line 59

def xinclude_examples name, *args, **kwargs, &block
  xdescribe '(skipped)' do
    if kwargs.empty?
      include_examples name, *args, &block
    else
      include_examples name, *args, **kwargs, &block
    end # if-else
  end # describe
end