Land #18172, Tidy up capture plugin specs

This commit is contained in:
adfoster-r7 2023-07-07 17:12:21 +01:00 committed by GitHub
commit b04ff3c579
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 22 deletions

View File

@ -2,29 +2,26 @@ require 'spec_helper'
require Metasploit::Framework.root.join('plugins/capture.rb').to_path
RSpec.describe Msf::Plugin::Capture::ConsoleCommandDispatcher do
describe '#cmd_captureg' do
let(:driver) do
double(Object).as_null_object.tap do |dbl|
allow(dbl).to receive(:print_line) do |args|
args
end
end
end
include_context 'Msf::UIDriver'
let(:framework) { instance_double(Msf::Framework) }
describe '#cmd_captureg' do
subject { described_class.new(driver) }
context 'without args' do
context 'when called without args' do
it 'returns generic help text' do
expect(subject.cmd_captureg).to eql subject.help
end
end
context 'single arg matching the HELP regex' do
context 'when there is a single arg matching the HELP regex' do
it 'returns generic help text' do
expect(subject.cmd_captureg('--help')).to eql subject.help
end
end
context 'two args, first one matches HELP regex' do
context 'when there are two args with first one matching the HELP regex' do
it 'calls `help` with second arg' do
expect(subject.cmd_captureg('--help', 'start')).to eql subject.help('start')
end
@ -33,18 +30,17 @@ RSpec.describe Msf::Plugin::Capture::ConsoleCommandDispatcher do
end
RSpec.describe Msf::Plugin::Capture::ConsoleCommandDispatcher::CaptureJobListener do
let(:dispatcher) do
instance_double(
Msf::Plugin::Capture::ConsoleCommandDispatcher,
print_error: nil,
print_good: nil
)
end
include_context 'Msf::UIDriver'
let(:dispatcher) { instance_double(Msf::Plugin::Capture::ConsoleCommandDispatcher) }
let(:done_event) { instance_double(Rex::Sync::Event, set: nil) }
let(:name) { 'my-little-module' }
subject { described_class.new(name, done_event, dispatcher) }
before(:each) do
capture_logging(dispatcher)
end
describe '#waiting' do
it 'sets the `succeeded` flag' do
subject.waiting('ignored')
@ -53,9 +49,9 @@ RSpec.describe Msf::Plugin::Capture::ConsoleCommandDispatcher::CaptureJobListene
end
it 'outputs a message via the dispatcher' do
expect(dispatcher).to receive(:print_good).with("#{name} started")
subject.waiting('ignored')
expect(@output).to include("#{name} started")
end
it 'sets the done event' do
@ -67,9 +63,9 @@ RSpec.describe Msf::Plugin::Capture::ConsoleCommandDispatcher::CaptureJobListene
describe '#failed' do
it 'outputs a message via the dispatcher' do
expect(dispatcher).to receive(:print_error).with("#{name} failed to start")
subject.failed('ignored', 'ignored', 'ignored')
expect(@error).to include("#{name} failed to start")
end
it 'sets the done event' do