Module: Metasploit::Model::Spec
- Extended by:
- TemporaryPathname, RSpec::Core::SharedExampleGroup::TopLevelDSL
- Defined in:
- lib/metasploit/model/spec.rb,
lib/metasploit/model/spec/error.rb,
lib/metasploit/model/spec/pathname_collision.rb,
lib/metasploit/model/spec/temporary_pathname.rb
Overview
Helper methods for running specs for metasploit-model.
Defined Under Namespace
Modules: TemporaryPathname Classes: Error, I18nExceptionHandler, PathnameCollision, Template
Class Method Summary collapse
-
.shared_examples_for(relative_name) { ... } ⇒ void
Defines a shared examples for a
Module
under the Metasploit::Model namespace.
Methods included from TemporaryPathname
remove_temporary_pathname, temporary_pathname, temporary_pathname=
Class Method Details
.shared_examples_for(relative_name) { ... } ⇒ void
This method returns an undefined value.
Defines a shared examples for a Module
under the Metasploit::Model namespace. This Module
is assumed to
be a mixin that can be mixed into an ActiveModel in metasploit-framework or an ActiveRecord in
metasploit_data_models. Shared examples declared using this method get access to boiler plate methods used
for all the Metasploit::Model mixin Modules
:
_class _factory - factory_namespace
- relative_variable_name
- #
_class - #
_factory
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/metasploit/model/spec.rb', line 57 def self.shared_examples_for(relative_name, &block) fully_qualified_name = "Metasploit::Model::#{relative_name}" relative_variable_name = relative_name.underscore.gsub('/', '_') class_method_name = "#{relative_variable_name}_class" factory_method_name = "#{relative_variable_name}_factory" # capture block to pass to super so that source_location can be overridden to be block's source_location so that # errors are reported correctly from RSpec. wrapper = ->(={}) { .assert_valid_keys(:namespace_name) namespace_name = .fetch(:namespace_name) class_name = "#{namespace_name}::#{relative_name}" # # Singleton methods to emulate local variable used to define examples and lets # define_singleton_method(class_method_name) do class_name.constantize end define_singleton_method(factory_method_name) do "#{factory_namespace}_#{relative_variable_name}" end define_singleton_method(:factory_namespace) do namespace_name.underscore.gsub('/', '_') end define_singleton_method(:namespace_name) do namespace_name end define_singleton_method(:relative_variable_name) do relative_variable_name end # # Defines to emulate local variable used inside lets # define_method(class_method_name) do self.class.send(class_method_name) end define_method(factory_method_name) do self.class.send(factory_method_name) end # # Default subject uses factory # subject(relative_variable_name) do FactoryGirl.build(send(factory_method_name)) end # # lets # let(:base_class) do self.class.send(class_method_name) end it_should_behave_like 'Metasploit::Model::Translation', metasploit_model_ancestor: fully_qualified_name.constantize module_eval(&block) } # Delegate source_location so that RSpec will report block's source_location as the declaration location of # the shared location instead of this method. wrapper.define_singleton_method(:source_location) do block.source_location end super(fully_qualified_name, &wrapper) end |