Validate partial mocks (#1417)

Switch to using explicit references to objects to be partially mocked
and remove the need to resolve the string constants as this will catch
more instances of calls to invalid or missing methods.

Rework how the vm is added to the machine for one of the tests as it is
not a method and instead is provided via internal state being exposed
with a helper.
This commit is contained in:
Darragh Bailey 2021-12-03 11:28:21 +00:00 committed by GitHub
parent 5914f0cffd
commit 27a541bba9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 9 additions and 11 deletions

View File

@ -44,10 +44,6 @@ RSpec.configure do |config|
end
config.mock_with :rspec do |mocks|
# This option should be set when all dependencies are being loaded
# before a spec run, as is the case in a typical spec helper. It will
# cause any verifying double instantiation for a class that does not
# exist to raise, protecting against incorrectly spelt names.
mocks.verify_doubled_constant_names = true
mocks.verify_partial_doubles = true
end
end

View File

@ -10,9 +10,9 @@ shared_context 'libvirt' do
let(:libvirt_context) { true }
let(:id) { 'dummy-vagrant_dummy' }
let(:connection) { double('connection') }
let(:domain) { instance_double('::Fog::Libvirt::Compute::Server') }
let(:libvirt_client) { instance_double('::Libvirt::Connect') }
let(:libvirt_domain) { instance_double('::Libvirt::Domain') }
let(:domain) { instance_double(::Fog::Libvirt::Compute::Server) }
let(:libvirt_client) { instance_double(::Libvirt::Connect) }
let(:libvirt_domain) { instance_double(::Libvirt::Domain) }
let(:logger) { double('logger') }
def connection_result(options = {})

View File

@ -155,7 +155,7 @@ describe VagrantPlugins::ProviderLibvirt::Action::DestroyDomain do
end
context 'with box metadata' do
let(:box) { instance_double('::Vagrant::Box') }
let(:box) { instance_double(::Vagrant::Box) }
before do
allow(env[:machine]).to receive(:box).and_return(box)
allow(box).to receive(:metadata).and_return(Hash[

View File

@ -607,7 +607,9 @@ describe VagrantPlugins::ProviderLibvirt::Config do
context 'with mac defined' do
let (:vm) { double('vm') }
before { expect(machine.config).to receive(:vm).and_return(vm) }
before do
machine.config.instance_variable_get("@keys")[:vm] = vm
end
it 'is valid with valid mac' do
expect(vm).to receive(:networks).and_return([[:public, { mac: 'aa:bb:cc:dd:ee:ff' }]])

View File

@ -177,7 +177,7 @@ describe VagrantPlugins::ProviderLibvirt::Driver do
end
context 'when qemu_use_session is enabled' do
let(:networks) { [instance_double('::Fog::Libvirt::Compute::Real')] }
let(:networks) { [instance_double(::Fog::Libvirt::Compute::Real)] }
let(:dhcp_leases) {
{
"iface" =>"virbr0",