CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/spec/msf/core/exception_spec.rb
Views: 1904
1
require 'rspec'
2
3
RSpec.describe 'Metasploit Exceptions' do
4
describe Msf::OptionValidateError do
5
describe '#new' do
6
it 'supports no options being provided' do
7
subject = described_class.new
8
expect(subject.options).to eq([])
9
expect(subject.reasons).to eq({})
10
end
11
12
it 'supports a custom message' do
13
subject = described_class.new(message: 'custom message')
14
expect(subject.options).to eq([])
15
expect(subject.reasons).to eq({})
16
expect(subject.message).to eq 'custom message'
17
end
18
19
it 'supports a default message' do
20
subject = described_class.new(['OptionName'])
21
expect(subject.options).to eq(['OptionName'])
22
expect(subject.reasons).to eq({})
23
expect(subject.message).to eq 'The following options failed to validate: OptionName.'
24
end
25
26
it 'supports only options being provided' do
27
subject = described_class.new(['RHOSTS'])
28
expect(subject.options).to eq(['RHOSTS'])
29
expect(subject.reasons).to eq({})
30
end
31
32
it 'supports a hash of options being provided, with associated string error reasons' do
33
subject = described_class.new(
34
{
35
'RHOSTS' => 'Human readable description'
36
}
37
)
38
expect(subject.options).to eq(['RHOSTS'])
39
expect(subject.reasons).to eq(
40
{
41
'RHOSTS' => ['Human readable description']
42
}
43
)
44
end
45
46
it 'supports a hash of options being provided, with an array of string error reasons' do
47
subject = described_class.new(
48
{
49
'RHOSTS' => [
50
'Human readable description 1',
51
'Human readable description 2',
52
]
53
}
54
)
55
expect(subject.options).to eq(['RHOSTS'])
56
expect(subject.reasons).to eq(
57
{
58
'RHOSTS' => [
59
'Human readable description 1',
60
'Human readable description 2',
61
]
62
}
63
)
64
end
65
66
it 'supports both options and error reasons being provided' do
67
subject = described_class.new(
68
[
69
'RHOSTS',
70
'RPORT'
71
],
72
reasons: {
73
'RHOSTS' => 'Human readable description'
74
}
75
)
76
expect(subject.options).to eq(['RHOSTS', 'RPORT'])
77
expect(subject.reasons).to eq(
78
{
79
'RHOSTS' => ['Human readable description']
80
}
81
)
82
end
83
end
84
end
85
end
86
87