Module: RSpec::SleepingKingStudios::Deferred::Provider::ClassMethods

Defined in:
lib/rspec/sleeping_king_studios/deferred/provider.rb

Overview

Class methods for registering deferred examples.

Instance Method Summary collapse

Instance Method Details

#deferred_examples(description) {|*arguments, **keywords, &block| ... } ⇒ Object Also known as: deferred_context

Defines deferred examples in the current context.

Examples:

Defining Deferred Examples

deferred_examples 'should be a Rocket' do
  it { expect(subject).to be_a Rocket }
end

Defining Parameterized Examples

deferred_examples 'should be a Vehicle' do |expected_type:|
  it { expect(subject).to be_a Vehicle }

  it { expect(subject.tyoe).to be == expected_type }
end

Parameters:

  • description (String)

    the name of the deferred examples.

Yields:

  • (*arguments, **keywords, &block)

    the definition for the deferred examples. Supports the same DSL as an RSpec::Core::ExampleGroup. If the block takes parameters, these can be used to customize the behavior of the deferred examples when they are included in an example group.

Yield Parameters:

  • arguments (Array)

    arguments passed to the deferred examples.

  • keywords (Hash)

    keywords passed to the deferred examples.

  • block (Block)

    a block passed to the deferred examples.

Raises:

  • (ArgumentError)


42
43
44
45
46
47
48
49
50
# File 'lib/rspec/sleeping_king_studios/deferred/provider.rb', line 42

def deferred_examples(description, &block)
  raise ArgumentError, 'block is required' unless block_given?

  tools.assertions.validate_name(description, as: 'description')

  defined_deferred_examples[description.to_s] = block

  nil
end

#defined_deferred_examplesObject



54
55
56
# File 'lib/rspec/sleeping_king_studios/deferred/provider.rb', line 54

def defined_deferred_examples
  @defined_deferred_examples ||= {}
end

#defined_deferred_examples?(description) ⇒ true, false Also known as: defined_deferred_context?

Checks if the given deferred example group is defined.

Parameters:

  • description (String)

    the name of the deferred examples.

Returns:

  • (true, false)

    true if a deferred example group with the given description is defined in the current context; otherwise false.



64
65
66
67
68
69
70
71
# File 'lib/rspec/sleeping_king_studios/deferred/provider.rb', line 64

def defined_deferred_examples?(description)
  ancestors.any? do |ancestor|
    next false unless ancestor.respond_to?(:defined_deferred_examples)

    ancestor.deferred_definition_exists?(description) ||
      ancestor.deferred_module_exists?(description)
  end
end

#find_deferred_examples(description) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/rspec/sleeping_king_studios/deferred/provider.rb', line 75

def find_deferred_examples(description)
  tools.assertions.validate_name(description, as: 'description')

  deferred = find_deferred_by_description(description.to_s)

  return deferred if deferred

  message =
    'deferred examples not found with description ' \
    "#{description.to_s.inspect}"

  raise DeferredExamplesNotFoundError, message
end