module Inspec::TestDslLazyLoader

This module exists to intercept the method_missing instance method on RSpec::Core::ExampleGroup and is part of support for DSL plugintypes

Public Instance Methods

method_missing(method_name, *arguments, &block) click to toggle source

Support for test DSL plugins

Calls superclass method
# File lib/inspec/rspec_extensions.rb, line 50
def method_missing(method_name, *arguments, &block)
  # see if it is a resource first
  begin
    backend = inspec if respond_to?(:inspec) # backend not available??
    resource = Inspec::DSL.method_missing_resource(backend, method_name, *arguments)
    return resource if resource
  rescue LoadError
    # pass through
  end

  # Check to see if there is a test_dsl plugin activator hook with the method name
  registry = Inspec::Plugin::V2::Registry.instance
  hook = registry.find_activators(plugin_type: :test_dsl, activator_name: method_name).first

  if hook
    # OK, load the hook if it hasn't been already.  We'll then know a module,
    # which we can then inject into the context
    hook.activate

    # Inject the module's methods into the example group contexts.
    # implementation_class is the field name, but this is actually a module.
    # RSpec works by having these helper methods defined as instance methods.
    # So, we use include to inject the new DSL methods.
    RSpec::Core::ExampleGroup.include(hook.implementation_class)

    # We still haven't called the method we were looking for, so do so now.
    send(method_name, *arguments, &block)
  else
    super
  end
end