Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/spec/tools/dev/rubocop_runner_spec.rb
Views: 11780
require 'spec_helper'12require Metasploit::Framework.root.join('tools/dev/msftidy.rb').to_path34RSpec.describe RuboCopRunner do5# Metasploit globally sets `::Encoding.default_internal`, which6# breaks reading Rubocop's ability to load its default config file7# as UTF-8.8#9# Note that this is a test only issue, as msftidy runs in its own10# Ruby process and doesn't load Metasploit which causes this issue11def patch_io_read_encoding12original_read = IO.method(:read)13allow(IO).to receive(:read) do |absolute_path, **kwargs|14original_read.call(absolute_path, **kwargs.merge(encoding: ::Encoding.default_internal))15end16end1718before(:each) do19patch_io_read_encoding20end2122context 'with a tidy module' do23let(:file) { File.expand_path('modules/auxiliary/auxiliary_rubocopped.rb', FILE_FIXTURES_PATH) }2425before(:each) do26allow(subject).to receive(:requires_rubocop?).and_return(true)27@stdout = get_stdout do28@status = subject.run(file)29end30end3132it 'returns zero (no warnings or errors)' do33expect(@status).to be_zero34end3536it 'contains no warnings' do37expect(@stdout).to match 'no offenses detected'38end39end4041context 'with an untidy tidy module' do42let(:file) { File.expand_path('modules/exploits/existing_auto_target.rb', FILE_FIXTURES_PATH) }4344before(:each) do45allow(subject).to receive(:requires_rubocop?).and_return(true)46@stdout = get_stdout do47@status = subject.run(file)48end49end5051it 'returns zero (no warnings or errors)' do52expect(@status).to_not be_zero53end5455it 'contains no warnings' do56expect(@stdout).to match 'Rubocop failed'57end58end5960context 'with an untidy module that is marked as too old for requiring linting' do61let(:file) { File.expand_path('modules/exploits/existing_auto_target.rb', FILE_FIXTURES_PATH) }6263before(:each) do64allow(subject).to receive(:requires_rubocop?).and_return(false)65@stdout = get_stdout do66@status = subject.run(file)67end68end6970it 'returns zero (no warnings or errors)' do71expect(@status).to be_zero72end7374it 'contains a status message' do75expect(@stdout).to match /Rubocop not required for older modules skipping/76end77end78end798081