Module: RSpec::SleepingKingStudios::Concerns::WrapExamples

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

Overview

Methods for encapsulating shared example groups to include contexts or examples without affecting the surrounding context.

Instance Method Summary collapse

Instance Method Details

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

Includes the specified shared example group and wraps it inside a focused `fdescribe` block. If a block is provided, it is evaluated in the context of the fdescribe block after the example group has been included.

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:

  • Additional code to run in the context of the wrapping `fdescribe` block, such as additional examples or memoized values.


46
47
48
49
50
51
52
53
54
55
56
# File 'lib/rspec/sleeping_king_studios/concerns/wrap_examples.rb', line 46

def fwrap_examples name, *args, **kwargs, &block
  fdescribe name do
    if kwargs.empty?
      include_examples name, *args
    else
      include_examples name, *args, **kwargs
    end # if-else

    instance_eval(&block) if block_given?
  end # describe
end

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

Includes the specified shared example group and wraps it inside a `describe` block. If a block is provided, it is evaluated in the context of the describe block after the example group has been included.

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:

  • Additional code to run in the context of the wrapping `describe` block, such as additional examples or memoized values.


21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rspec/sleeping_king_studios/concerns/wrap_examples.rb', line 21

def wrap_examples name, *args, **kwargs, &block
  describe name do
    if kwargs.empty?
      include_examples name, *args
    else
      include_examples name, *args, **kwargs
    end # if-else

    instance_eval(&block) if block_given?
  end # describe
end

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

Includes the specified shared example group and wraps it inside a skipped `xdescribe` block. If a block is provided, it is evaluated in the context of the xdescribe block after the example group has been included. Mostly used to temporarily disable a wrapped example group while updating or debugging a spec.

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:

  • Additional code to run in the context of the wrapping `fdescribe` block, such as additional examples or memoized values.


73
74
75
76
77
78
79
80
81
82
83
# File 'lib/rspec/sleeping_king_studios/concerns/wrap_examples.rb', line 73

def xwrap_examples name, *args, **kwargs, &block
  xdescribe name do
    if kwargs.empty?
      include_examples name, *args
    else
      include_examples name, *args, **kwargs
    end # if-else

    instance_eval(&block) if block_given?
  end # describe
end