|
|
fd25a55 |
From ba7ee11601b5d79278b6ca9ffe61867a21af06b9 Mon Sep 17 00:00:00 2001
|
|
|
fd25a55 |
From: =?UTF-8?q?V=C3=ADt=20Ondruch?= <vondruch@redhat.com>
|
|
|
fd25a55 |
Date: Wed, 20 Jan 2021 18:43:18 +0100
|
|
|
fd25a55 |
Subject: [PATCH] Use test doubles instead of `true`.
|
|
|
fd25a55 |
MIME-Version: 1.0
|
|
|
fd25a55 |
Content-Type: text/plain; charset=UTF-8
|
|
|
fd25a55 |
Content-Transfer-Encoding: 8bit
|
|
|
fd25a55 |
|
|
|
fd25a55 |
This solves possible issues such as:
|
|
|
fd25a55 |
|
|
|
fd25a55 |
~~~
|
|
|
fd25a55 |
1) VagrantPlugins::DockerProvider::Provider#host_vm returns the host machine object
|
|
|
fd25a55 |
Failure/Error: allow(machine.env).to receive(:root_path).and_return("/.vagrant.d")
|
|
|
fd25a55 |
ArgumentError:
|
|
|
fd25a55 |
Cannot proxy frozen objects, rspec-mocks relies on proxies for method stubbing and expectations.
|
|
|
fd25a55 |
# ./test/unit/plugins/providers/docker/provider_test.rb:82:in `block (3 levels) in <top (required)>'
|
|
|
fd25a55 |
~~~
|
|
|
fd25a55 |
|
|
|
fd25a55 |
This is not good idea, because frozen object should not receive
|
|
|
fd25a55 |
modifications, because these possibly can't be undone. This is
|
|
|
fd25a55 |
prohibited since rspec-mock 3.10.1.
|
|
|
fd25a55 |
|
|
|
fd25a55 |
Signed-off-by: Vít Ondruch <vondruch@redhat.com>
|
|
|
fd25a55 |
---
|
|
|
fd25a55 |
test/unit/plugins/providers/docker/provider_test.rb | 2 +-
|
|
|
fd25a55 |
.../plugins/provisioners/puppet/provisioner/puppet_test.rb | 4 ++--
|
|
|
fd25a55 |
.../plugins/synced_folders/rsync/command/rsync_auto_test.rb | 2 +-
|
|
|
fd25a55 |
test/unit/vagrant/util/ssh_test.rb | 2 +-
|
|
|
fd25a55 |
4 files changed, 5 insertions(+), 5 deletions(-)
|
|
|
fd25a55 |
|
|
|
fd25a55 |
diff --git a/test/unit/plugins/providers/docker/provider_test.rb b/test/unit/plugins/providers/docker/provider_test.rb
|
|
|
fd25a55 |
index 3cb6e03cb..b420ba527 100644
|
|
|
fd25a55 |
--- a/test/unit/plugins/providers/docker/provider_test.rb
|
|
|
fd25a55 |
+++ b/test/unit/plugins/providers/docker/provider_test.rb
|
|
|
fd25a55 |
@@ -78,7 +78,7 @@ describe VagrantPlugins::DockerProvider::Provider do
|
|
|
fd25a55 |
it "returns the host machine object" do
|
|
|
fd25a55 |
allow(machine.provider_config).to receive(:vagrant_vagrantfile).and_return("/path/to/Vagrantfile")
|
|
|
fd25a55 |
allow(machine.provider_config).to receive(:vagrant_machine).and_return(:default)
|
|
|
fd25a55 |
- allow(machine).to receive(:env).and_return(true)
|
|
|
fd25a55 |
+ allow(machine).to receive(:env).and_return(double())
|
|
|
fd25a55 |
allow(machine.env).to receive(:root_path).and_return("/.vagrant.d")
|
|
|
fd25a55 |
allow(machine.env).to receive(:home_path).and_return("/path/to")
|
|
|
fd25a55 |
allow(machine.env).to receive(:ui_class).and_return(true)
|
|
|
fd25a55 |
diff --git a/test/unit/plugins/provisioners/puppet/provisioner/puppet_test.rb b/test/unit/plugins/provisioners/puppet/provisioner/puppet_test.rb
|
|
|
fd25a55 |
index c4ee727cc..27f5d9435 100644
|
|
|
fd25a55 |
--- a/test/unit/plugins/provisioners/puppet/provisioner/puppet_test.rb
|
|
|
fd25a55 |
+++ b/test/unit/plugins/provisioners/puppet/provisioner/puppet_test.rb
|
|
|
fd25a55 |
@@ -81,7 +81,7 @@ describe VagrantPlugins::Puppet::Provisioner::Puppet do
|
|
|
fd25a55 |
let(:environment_paths) { ["/etc/puppet/environment"] }
|
|
|
fd25a55 |
|
|
|
fd25a55 |
it "builds structured facts if set" do
|
|
|
fd25a55 |
- allow(machine).to receive(:guest).and_return(true)
|
|
|
fd25a55 |
+ allow(machine).to receive(:guest).and_return(double())
|
|
|
fd25a55 |
allow(machine.guest).to receive(:capability?).and_return(false)
|
|
|
fd25a55 |
allow(config).to receive(:environment_path).and_return(environment_paths)
|
|
|
fd25a55 |
allow(config).to receive(:environment).and_return("production")
|
|
|
fd25a55 |
@@ -105,7 +105,7 @@ describe VagrantPlugins::Puppet::Provisioner::Puppet do
|
|
|
fd25a55 |
end
|
|
|
fd25a55 |
|
|
|
fd25a55 |
it "does not build structured facts if not set" do
|
|
|
fd25a55 |
- allow(machine).to receive(:guest).and_return(true)
|
|
|
fd25a55 |
+ allow(machine).to receive(:guest).and_return(double())
|
|
|
fd25a55 |
allow(machine.guest).to receive(:capability?).and_return(false)
|
|
|
fd25a55 |
allow(config).to receive(:environment_path).and_return(environment_paths)
|
|
|
fd25a55 |
allow(config).to receive(:environment).and_return("production")
|
|
|
fd25a55 |
diff --git a/test/unit/plugins/synced_folders/rsync/command/rsync_auto_test.rb b/test/unit/plugins/synced_folders/rsync/command/rsync_auto_test.rb
|
|
|
fd25a55 |
index 5a9c691ff..3600fbd67 100644
|
|
|
fd25a55 |
--- a/test/unit/plugins/synced_folders/rsync/command/rsync_auto_test.rb
|
|
|
fd25a55 |
+++ b/test/unit/plugins/synced_folders/rsync/command/rsync_auto_test.rb
|
|
|
fd25a55 |
@@ -81,7 +81,7 @@ describe VagrantPlugins::SyncedFolderRSync::Command::RsyncAuto do
|
|
|
fd25a55 |
allow(machine.env).to receive(:cwd).
|
|
|
fd25a55 |
and_return("/Users/brian/code/vagrant-sandbox")
|
|
|
fd25a55 |
allow(machine.provider).to receive(:capability?).and_return(false)
|
|
|
fd25a55 |
- allow(machine.config).to receive(:vm).and_return(true)
|
|
|
fd25a55 |
+ allow(machine.config).to receive(:vm).and_return(double())
|
|
|
fd25a55 |
allow(machine.config.vm).to receive(:synced_folders).and_return(config_synced_folders)
|
|
|
fd25a55 |
|
|
|
fd25a55 |
allow(subject).to receive(:synced_folders).
|
|
|
fd25a55 |
diff --git a/test/unit/vagrant/util/ssh_test.rb b/test/unit/vagrant/util/ssh_test.rb
|
|
|
fd25a55 |
index 9f30727a0..0fc6146cf 100644
|
|
|
fd25a55 |
--- a/test/unit/vagrant/util/ssh_test.rb
|
|
|
fd25a55 |
+++ b/test/unit/vagrant/util/ssh_test.rb
|
|
|
fd25a55 |
@@ -270,7 +270,7 @@ describe Vagrant::Util::SSH do
|
|
|
fd25a55 |
# mock out ChildProcess
|
|
|
fd25a55 |
process = double()
|
|
|
fd25a55 |
allow(ChildProcess).to receive(:build).and_return(process)
|
|
|
fd25a55 |
- allow(process).to receive(:io).and_return(true)
|
|
|
fd25a55 |
+ allow(process).to receive(:io).and_return(double())
|
|
|
fd25a55 |
allow(process.io).to receive(:inherit!).and_return(true)
|
|
|
fd25a55 |
allow(process).to receive(:start).and_return(true)
|
|
|
fd25a55 |
allow(process).to receive(:wait).and_return(true)
|
|
|
fd25a55 |
--
|
|
|
fd25a55 |
2.29.2
|
|
|
fd25a55 |
|