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/support/shared/contexts/msf/ui_driver.rb
Views: 1904
1
RSpec.shared_context 'Msf::UIDriver' do
2
let(:driver) do
3
instance = double('Driver', framework: framework)
4
allow(instance).to receive(:on_command_proc=).with(kind_of(Proc))
5
capture_logging(instance)
6
instance
7
end
8
9
let(:driver_input) do
10
double(Rex::Ui::Text::Input)
11
end
12
13
let(:driver_output) do
14
instance = double(
15
Rex::Ui::Text::Output,
16
prompting?: false,
17
prompting: false
18
)
19
20
capture_logging(instance)
21
instance
22
end
23
24
def reset_logging!
25
@output = []
26
@error = []
27
@combined_output = []
28
end
29
30
def capture_logging(target)
31
append_output = proc do |string = ''|
32
lines = string.split("\n")
33
@output ||= []
34
@output.concat(lines)
35
@combined_output ||= []
36
@combined_output.concat(lines)
37
end
38
append_error = proc do |string = ''|
39
lines = string.split("\n")
40
@error ||= []
41
@error.concat(lines)
42
@combined_output ||= []
43
@combined_output.concat(lines)
44
end
45
46
allow(target).to receive(:print, &append_output)
47
allow(target).to receive(:print_line, &append_output)
48
allow(target).to receive(:print_status, &append_output)
49
allow(target).to receive(:print_good, &append_output)
50
51
allow(target).to receive(:print_warning, &append_error)
52
allow(target).to receive(:print_error, &append_error)
53
allow(target).to receive(:print_bad, &append_error)
54
end
55
end
56
57