Module: RSpec::SleepingKingStudios::Deferred::Dsl::ExampleConstants

Included in:
RSpec::SleepingKingStudios::Deferred::Dsl
Defined in:
lib/rspec/sleeping_king_studios/deferred/dsl/example_constants.rb

Overview

Domain-specific language for defining deferred example constants.

Instance Method Summary collapse

Instance Method Details

#example_class(class_name, base_class = nil) {|klass| ... } ⇒ Object

Defines a deferred temporary class scoped to the current example.

Parameters:

  • class_name (String)

    the qualified name of the class.

  • base_class (Class, String) (defaults to: nil)

    the base class or name of the base class. This can be the name of another example class, as long as the base class is defined earlier in the example group or in a parent example group.

Yields:

  • definitions for the temporary class. This block is evaluated in the context of the example, meaning that methods or memoized helpers can be referenced.

Yield Parameters:

  • klass (Class)

    the temporary class.



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/rspec/sleeping_king_studios/deferred/dsl/example_constants.rb', line 23

def example_class(class_name, base_class = nil, &)
  deferred_calls <<
    RSpec::SleepingKingStudios::Deferred::Call.new(
      :example_class,
      class_name,
      base_class,
      &
    )

  nil
end

#example_constant(constant_name, constant_value) ⇒ Object #example_constant(constant_name) { ... } ⇒ Object

Deprecated.

2.8.0 with force: true parameter.

Overloads:

  • #example_constant(constant_name, constant_value) ⇒ Object

    Defines a deferred temporary constant scoped to the current example.

    Parameters:

    • constant_name (String)

      the qualified name of the constant.

    • constant_value (Object)

      the value of the constant.

  • #example_constant(constant_name) { ... } ⇒ Object

    Defines a deferred temporary constant scoped to the current example.

    Parameters:

    • constant_name (String)

      the qualified name of the constant.

    Yields:

    • generates the constant value. This block is evaluated in the context of the example, meaning that methods or memoized helpers can be referenced.

    Yield Returns:

    • the value of the constant.



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/rspec/sleeping_king_studios/deferred/dsl/example_constants.rb', line 52

def example_constant(
  qualified_name,
  constant_value = nil,
  force: false,
  &block
)
  deferred_calls <<
    RSpec::SleepingKingStudios::Deferred::Call.new(
      :example_constant,
      qualified_name,
      *(constant_value.nil? ? [] : [constant_value]),
      force:,
      &block
    )

  nil
end