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/tools/dev/rubocop_runner_spec.rb
Views: 11780
1
require 'spec_helper'
2
3
require Metasploit::Framework.root.join('tools/dev/msftidy.rb').to_path
4
5
RSpec.describe RuboCopRunner do
6
# Metasploit globally sets `::Encoding.default_internal`, which
7
# breaks reading Rubocop's ability to load its default config file
8
# as UTF-8.
9
#
10
# Note that this is a test only issue, as msftidy runs in its own
11
# Ruby process and doesn't load Metasploit which causes this issue
12
def patch_io_read_encoding
13
original_read = IO.method(:read)
14
allow(IO).to receive(:read) do |absolute_path, **kwargs|
15
original_read.call(absolute_path, **kwargs.merge(encoding: ::Encoding.default_internal))
16
end
17
end
18
19
before(:each) do
20
patch_io_read_encoding
21
end
22
23
context 'with a tidy module' do
24
let(:file) { File.expand_path('modules/auxiliary/auxiliary_rubocopped.rb', FILE_FIXTURES_PATH) }
25
26
before(:each) do
27
allow(subject).to receive(:requires_rubocop?).and_return(true)
28
@stdout = get_stdout do
29
@status = subject.run(file)
30
end
31
end
32
33
it 'returns zero (no warnings or errors)' do
34
expect(@status).to be_zero
35
end
36
37
it 'contains no warnings' do
38
expect(@stdout).to match 'no offenses detected'
39
end
40
end
41
42
context 'with an untidy tidy module' do
43
let(:file) { File.expand_path('modules/exploits/existing_auto_target.rb', FILE_FIXTURES_PATH) }
44
45
before(:each) do
46
allow(subject).to receive(:requires_rubocop?).and_return(true)
47
@stdout = get_stdout do
48
@status = subject.run(file)
49
end
50
end
51
52
it 'returns zero (no warnings or errors)' do
53
expect(@status).to_not be_zero
54
end
55
56
it 'contains no warnings' do
57
expect(@stdout).to match 'Rubocop failed'
58
end
59
end
60
61
context 'with an untidy module that is marked as too old for requiring linting' do
62
let(:file) { File.expand_path('modules/exploits/existing_auto_target.rb', FILE_FIXTURES_PATH) }
63
64
before(:each) do
65
allow(subject).to receive(:requires_rubocop?).and_return(false)
66
@stdout = get_stdout do
67
@status = subject.run(file)
68
end
69
end
70
71
it 'returns zero (no warnings or errors)' do
72
expect(@status).to be_zero
73
end
74
75
it 'contains a status message' do
76
expect(@stdout).to match /Rubocop not required for older modules skipping/
77
end
78
end
79
end
80
81