Fixup tests for Ruby 3.0

This is a pass through test failures and deprecation warnings:

 * Make all ambiguous `.with(..., key: val)` use explicit hashes to
   prevent test failures for argument mismatch in Ruby 3.0
 * Scope down all unbounded `raise_error` to address warnings (remove
   one test that was revealed to be referencing a nonexistent variable
   once the raise_error was scoped.)
 * Update all `any_instance` usage to new syntax to address warnings
 * Allow the service cache to be cleared and do so between some tests
 * Fix a small bug in with_plugin's plugin not found code path (revealed
   by a scoped and_raise)
This commit is contained in:
Paul Hinze 2022-02-23 11:55:23 -06:00
parent a684350a7b
commit 06ad1b4565
No known key found for this signature in database
GPG Key ID: B69DEDF2D55501C0
7 changed files with 24 additions and 18 deletions

View File

@ -10,6 +10,10 @@ module VagrantPlugins
@registry = {}
end
def clear
@registry = {}
end
# Check if the given key is currently registered
#
# @param key [Object] Generally String or Symbol

View File

@ -59,7 +59,7 @@ module VagrantPlugins
send(plugins)[info.plugin_name]
).first
if !plugin
raise NameError, "Failed to locate plugin '#{plugin_name}' within #{plugins} plugins"
raise NameError, "Failed to locate plugin '#{info.plugin_name}' within #{plugins} plugins"
end
yield plugin, info if block_given?
end

View File

@ -64,7 +64,7 @@ describe VagrantPlugins::CommandPackage::Command do
it "packages default machine inside specified folder" do
expect(package_command).to receive(:package_vm).with(
a_machine_named('default'), :output => "package-output-folder/default"
a_machine_named('default'), {:output => "package-output-folder/default"}
)
package_command.execute
end
@ -96,7 +96,7 @@ describe VagrantPlugins::CommandPackage::Command do
let(:argv){ ['--base', 'machine-id'] }
it "packages vm defined within virtualbox" do
expect(package_command).to receive(:package_base).with(:base => 'machine-id')
expect(package_command).to receive(:package_base).with({:base => 'machine-id'})
package_command.execute
end

View File

@ -61,7 +61,7 @@ describe VagrantPlugins::CommandServe::Service::GuestService do
it "raises an error for unknown plugins" do
ctx = DummyContext.new("idontexisthahaha")
expect { subject.parent("", ctx) }.to raise_error
expect { subject.parent("", ctx) }.to raise_error(/Failed to locate guest plugin/)
end
it "requests parent from plugins" do
@ -84,7 +84,11 @@ describe VagrantPlugins::CommandServe::Service::GuestService do
p.guest(:test_false) { test_false_guest }
end
VagrantPlugins::CommandServe::Mappers.any_instance.stub(:funcspec_map).and_return(machine)
allow_any_instance_of(VagrantPlugins::CommandServe::Mappers).to receive(:funcspec_map).and_return(machine)
end
after do
VagrantPlugins::CommandServe::Service.cache.clear
end
it "generates a spec" do
@ -94,7 +98,7 @@ describe VagrantPlugins::CommandServe::Service::GuestService do
it "raises an error for unknown plugins" do
ctx = DummyContext.new("idontexisthahaha")
expect { subject.detect("", ctx) }.to raise_error
expect { subject.detect("", ctx) }.to raise_error(/Failed to locate plugin/)
end
it "detects true plugins" do
@ -153,11 +157,6 @@ describe VagrantPlugins::CommandServe::Service::GuestService do
expect(spec).not_to be_nil
end
it "raises an error for unknown plugins" do
ctx = DummyContext.new("idontexisthahaha")
expect { subject.has_capability(test_cap_name, ctx) }.to raise_error
end
it "returns true for plugin with capability" do
ctx = DummyContext.new("cap_guest")
d = subject.has_capability(named_cap_request, ctx)

View File

@ -88,10 +88,13 @@ describe VagrantPlugins::CommandServe::Service::HostService do
p.host(:test_false) { test_false_host }
end
VagrantPlugins::CommandServe::Client::Target.any_instance.stub(:project).and_return("")
VagrantPlugins::CommandServe::Client::Target.any_instance.stub(:name).and_return("dummy")
VagrantPlugins::CommandServe::Client::Target.any_instance.stub(:provider_name).and_return("virtualbox")
# Vagrant::Environment.any_instance.stub(:machine).and_return(machine)
allow_any_instance_of(VagrantPlugins::CommandServe::Client::Target).to receive(:project).and_return("")
allow_any_instance_of(VagrantPlugins::CommandServe::Client::Target).to receive(:name).and_return("dummy")
allow_any_instance_of(VagrantPlugins::CommandServe::Client::Target).to receive(:provider_name).and_return("virtualbox")
end
after do
VagrantPlugins::CommandServe::Service.cache.clear
end
it "generates a spec" do

View File

@ -31,7 +31,7 @@ describe VagrantPlugins::HyperV::Action::ReadGuestIP do
end
it "should set the host information into the env" do
expect(env).to receive(:[]=).with(:machine_ssh_info, host: "ADDRESS")
expect(env).to receive(:[]=).with(:machine_ssh_info, {host: "ADDRESS"})
expect(driver).to receive(:read_guest_ip).and_return("ip" => "ADDRESS")
subject.call(env)
end

View File

@ -379,12 +379,12 @@ describe Vagrant::UI::Prefixed do
describe "#machine" do
it "sets the target option" do
expect(ui).to receive(:machine).with(:foo, target: prefix)
expect(ui).to receive(:machine).with(:foo, {target: prefix})
subject.machine(:foo)
end
it "preserves existing options" do
expect(ui).to receive(:machine).with(:foo, :bar, foo: :bar, target: prefix)
expect(ui).to receive(:machine).with(:foo, :bar, {foo: :bar, target: prefix})
subject.machine(:foo, :bar, foo: :bar)
end
end