Module: RSpec::SleepingKingStudios::Deferred::Definitions

Included in:
Missing::ClassMethods
Defined in:
lib/rspec/sleeping_king_studios/deferred/definitions.rb

Overview

Class methods for defining a registry of deferred calls.

Instance Method Summary collapse

Instance Method Details

#call(example_group) ⇒ void

This method returns an undefined value.

Invokes the deferred examples on the given example group.

Parameters:

  • example_group (RSpec::Core::ExampleGroup)

    the example group.



13
14
15
16
17
# File 'lib/rspec/sleeping_king_studios/deferred/definitions.rb', line 13

def call(example_group)
  deferred_calls.each do |deferred|
    deferred.call(example_group)
  end
end

#deferred_callsObject



20
21
22
# File 'lib/rspec/sleeping_king_studios/deferred/definitions.rb', line 20

def deferred_calls
  @deferred_calls ||= []
end

#included(other) ⇒ Object

Callback invoked when the module is included in another module or class.

Calls the deferred calls with the other module as the receiver if the module is an RSpec::Core::ExampleGroup.

Parameters:

  • other (Module)

    the other module or class.



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rspec/sleeping_king_studios/deferred/definitions.rb', line 30

def included(other)
  super

  return unless other < RSpec::Core::ExampleGroup

  ancestors.reverse_each do |ancestor|
    next unless ancestor.singleton_class.method_defined?(:deferred_calls)

    ancestor.call(other)
  end
end