CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/spec/support/shared/contexts/msf/string_io.rb
Views: 11788
1
require 'stringio'
2
3
RSpec.shared_context 'Msf::StringIO' do
4
5
#
6
# lets
7
#
8
9
let(:msf_io) do
10
s = StringIO.new('', 'w+b')
11
class << s
12
attr_accessor :msf_data
13
end
14
15
s.msf_data = ''
16
s.binmode
17
18
s
19
end
20
21
#
22
# Callbacks
23
#
24
25
before(:example) do
26
def msf_io.get_once
27
read
28
end
29
30
def msf_io.has_read_data?(_timeout)
31
!eof?
32
end
33
34
def msf_io.put(_data)
35
seek(0)
36
37
if msf_data.nil? || msf_data.empty?
38
length = write(_data)
39
else
40
length = write(msf_data)
41
end
42
43
seek(0)
44
45
length
46
end
47
end
48
end
49
50