Use `load_and_create_module` in modules_spec

MSP-11130

Reuse 'Msf::Simple::Framework#modules loading' context in 'all modules
with module type can be instantiated' instead of using the similar code.
bug/bundler_fix
Luke Imhoff 2014-11-04 12:59:59 -06:00
parent 7cb0954a6e
commit c115ad3c36
No known key found for this signature in database
GPG Key ID: 5B1FB01FB33356F8
1 changed files with 6 additions and 29 deletions

View File

@ -6,30 +6,13 @@ shared_examples_for 'all modules with module type can be instantiated' do |optio
modules_path = modules_pathname.to_path
type_directory = options.fetch(:type_directory)
include_context 'Msf::Simple::Framework'
include_context 'Msf::Simple::Framework#modules loading'
#
# lets
#
let(:loader) {
loader = framework.modules.send(:loaders).find { |loader|
loader.loadable?(modules_path)
}
# Override load_error so that rspec will print it instead of going to framework log
def loader.load_error(module_path, error)
raise error
end
loader
}
context module_type do
let(:module_set) {
framework.modules.module_set(module_type)
}
type_pathname = modules_pathname.join(type_directory)
module_extension = ".rb"
module_extension_regexp = /#{Regexp.escape(module_extension)}$/
@ -41,17 +24,11 @@ shared_examples_for 'all modules with module type can be instantiated' do |optio
context module_reference_name do
it 'can be instantiated' do
loaded = loader.load_module(modules_path, module_type, module_reference_name)
expect(loaded).to eq(true), "#{module_reference_name} failed to load from #{modules_path}"
module_instance = nil
expect {
module_instance = module_set.create(module_reference_name)
}.not_to raise_error
expect(module_instance).not_to be_nil, "Could not instantiate #{module_type}/#{module_reference_name}"
load_and_create_module(
module_type: module_type,
modules_path: modules_path,
reference_name: module_reference_name
)
end
end
end