Module: Inspec::TestDslLazyLoader
- Included in:
- RSpec::Core::ExampleGroup
- Defined in:
- lib/inspec/rspec_extensions.rb
Overview
This module exists to intercept the method_missing instance method on RSpec::Core::ExampleGroup and is part of support for DSL plugintypes
Instance Method Summary collapse
-
#method_missing(method_name, *arguments, &block) ⇒ Object
Support for test DSL plugins.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *arguments, &block) ⇒ Object
Support for test DSL plugins
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# 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 |