Module: RSpec::SleepingKingStudios::Deferred::Dependencies

Extended by:
SleepingKingStudios::Tools::Toolbox::Mixin
Defined in:
lib/rspec/sleeping_king_studios/deferred/dependencies.rb

Overview

Mixin for declaring dependent methods for deferred example groups.

Each dependent method is expected to have a definition, either as a direct method definition (using the ‘def` keyword or `define_method`), or via a memoized helper (such as `let`).

When the deferred examples are included in an example group and that example group is run, a before(:context) hook will check for all of the declared dependencies of that example group. If any of the expected dependencies are not defined, the hook will raise an exception listing the missing methods, the deferred examples that expect that method, and the description provided.

Examples:

module RocketExamples
  include RSpec::SleepingKingStudios::Deferred::Provider

  deferred_examples 'should launch the rocket' do
    include RSpec::SleepingKingStudios::Deferred::Dependencies

    depends_on :rocket,
      'an instance of Rocket where #launched? returns false'

    describe '#launch' do
      it 'should launch the rocket' do
        expect { rocket.launch }.to change(rocket, :launched?).to be true
      end
    end
  end
end

Defined Under Namespace

Modules: ClassMethods Classes: MissingDependenciesError

Class Method Summary collapse

Class Method Details

.check_dependencies_for(example) ⇒ Object

Checks for missing dependent methods for the given example.

Parameters:

  • example (RSpec::Core::Example)

    the example to check.

Raises:



88
89
90
91
92
93
94
# File 'lib/rspec/sleeping_king_studios/deferred/dependencies.rb', line 88

def check_dependencies_for(example)
  missing = missing_dependencies_for(example)

  return if missing.empty?

  raise MissingDependenciesError, generate_missing_message(missing)
end