Skip to content

Commit c115ad3

Browse files
committed
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.
1 parent 7cb0954 commit c115ad3

File tree

1 file changed

+6
-29
lines changed

1 file changed

+6
-29
lines changed

spec/support/shared/examples/all_modules_with_module_type_can_be_instantiated.rb

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,13 @@
66
modules_path = modules_pathname.to_path
77
type_directory = options.fetch(:type_directory)
88

9-
include_context 'Msf::Simple::Framework'
9+
include_context 'Msf::Simple::Framework#modules loading'
1010

1111
#
1212
# lets
1313
#
1414

15-
let(:loader) {
16-
loader = framework.modules.send(:loaders).find { |loader|
17-
loader.loadable?(modules_path)
18-
}
19-
20-
# Override load_error so that rspec will print it instead of going to framework log
21-
def loader.load_error(module_path, error)
22-
raise error
23-
end
24-
25-
loader
26-
}
27-
2815
context module_type do
29-
let(:module_set) {
30-
framework.modules.module_set(module_type)
31-
}
32-
3316
type_pathname = modules_pathname.join(type_directory)
3417
module_extension = ".rb"
3518
module_extension_regexp = /#{Regexp.escape(module_extension)}$/
@@ -41,17 +24,11 @@ def loader.load_error(module_path, error)
4124

4225
context module_reference_name do
4326
it 'can be instantiated' do
44-
loaded = loader.load_module(modules_path, module_type, module_reference_name)
45-
46-
expect(loaded).to eq(true), "#{module_reference_name} failed to load from #{modules_path}"
47-
48-
module_instance = nil
49-
50-
expect {
51-
module_instance = module_set.create(module_reference_name)
52-
}.not_to raise_error
53-
54-
expect(module_instance).not_to be_nil, "Could not instantiate #{module_type}/#{module_reference_name}"
27+
load_and_create_module(
28+
module_type: module_type,
29+
modules_path: modules_path,
30+
reference_name: module_reference_name
31+
)
5532
end
5633
end
5734
end

0 commit comments

Comments
 (0)