jcaamano / rpms / vagrant

Forked from rpms/vagrant 2 years ago
Clone
Blob Blame History Raw
From ba7ee11601b5d79278b6ca9ffe61867a21af06b9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?V=C3=ADt=20Ondruch?= <vondruch@redhat.com>
Date: Wed, 20 Jan 2021 18:43:18 +0100
Subject: [PATCH] Use test doubles instead of `true`.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This solves possible issues such as:

~~~
  1) VagrantPlugins::DockerProvider::Provider#host_vm returns the host machine object
     Failure/Error: allow(machine.env).to receive(:root_path).and_return("/.vagrant.d")
     ArgumentError:
       Cannot proxy frozen objects, rspec-mocks relies on proxies for method stubbing and expectations.
     # ./test/unit/plugins/providers/docker/provider_test.rb:82:in `block (3 levels) in <top (required)>'
~~~

This is not good idea, because frozen object should not receive
modifications, because these possibly can't be undone. This is
prohibited since rspec-mock 3.10.1.

Signed-off-by: Vít Ondruch <vondruch@redhat.com>
---
 test/unit/plugins/providers/docker/provider_test.rb           | 2 +-
 .../plugins/provisioners/puppet/provisioner/puppet_test.rb    | 4 ++--
 .../plugins/synced_folders/rsync/command/rsync_auto_test.rb   | 2 +-
 test/unit/vagrant/util/ssh_test.rb                            | 2 +-
 4 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/test/unit/plugins/providers/docker/provider_test.rb b/test/unit/plugins/providers/docker/provider_test.rb
index 3cb6e03cb..b420ba527 100644
--- a/test/unit/plugins/providers/docker/provider_test.rb
+++ b/test/unit/plugins/providers/docker/provider_test.rb
@@ -78,7 +78,7 @@ describe VagrantPlugins::DockerProvider::Provider do
     it "returns the host machine object" do
       allow(machine.provider_config).to receive(:vagrant_vagrantfile).and_return("/path/to/Vagrantfile")
       allow(machine.provider_config).to receive(:vagrant_machine).and_return(:default)
-      allow(machine).to receive(:env).and_return(true)
+      allow(machine).to receive(:env).and_return(double())
       allow(machine.env).to receive(:root_path).and_return("/.vagrant.d")
       allow(machine.env).to receive(:home_path).and_return("/path/to")
       allow(machine.env).to receive(:ui_class).and_return(true)
diff --git a/test/unit/plugins/provisioners/puppet/provisioner/puppet_test.rb b/test/unit/plugins/provisioners/puppet/provisioner/puppet_test.rb
index c4ee727cc..27f5d9435 100644
--- a/test/unit/plugins/provisioners/puppet/provisioner/puppet_test.rb
+++ b/test/unit/plugins/provisioners/puppet/provisioner/puppet_test.rb
@@ -81,7 +81,7 @@ describe VagrantPlugins::Puppet::Provisioner::Puppet do
     let(:environment_paths) { ["/etc/puppet/environment"] }
 
     it "builds structured facts if set" do
-      allow(machine).to receive(:guest).and_return(true)
+      allow(machine).to receive(:guest).and_return(double())
       allow(machine.guest).to receive(:capability?).and_return(false)
       allow(config).to receive(:environment_path).and_return(environment_paths)
       allow(config).to receive(:environment).and_return("production")
@@ -105,7 +105,7 @@ describe VagrantPlugins::Puppet::Provisioner::Puppet do
     end
 
     it "does not build structured facts if not set" do
-      allow(machine).to receive(:guest).and_return(true)
+      allow(machine).to receive(:guest).and_return(double())
       allow(machine.guest).to receive(:capability?).and_return(false)
       allow(config).to receive(:environment_path).and_return(environment_paths)
       allow(config).to receive(:environment).and_return("production")
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
index 5a9c691ff..3600fbd67 100644
--- a/test/unit/plugins/synced_folders/rsync/command/rsync_auto_test.rb
+++ b/test/unit/plugins/synced_folders/rsync/command/rsync_auto_test.rb
@@ -81,7 +81,7 @@ describe VagrantPlugins::SyncedFolderRSync::Command::RsyncAuto do
       allow(machine.env).to receive(:cwd).
         and_return("/Users/brian/code/vagrant-sandbox")
       allow(machine.provider).to receive(:capability?).and_return(false)
-      allow(machine.config).to receive(:vm).and_return(true)
+      allow(machine.config).to receive(:vm).and_return(double())
       allow(machine.config.vm).to receive(:synced_folders).and_return(config_synced_folders)
 
       allow(subject).to receive(:synced_folders).
diff --git a/test/unit/vagrant/util/ssh_test.rb b/test/unit/vagrant/util/ssh_test.rb
index 9f30727a0..0fc6146cf 100644
--- a/test/unit/vagrant/util/ssh_test.rb
+++ b/test/unit/vagrant/util/ssh_test.rb
@@ -270,7 +270,7 @@ describe Vagrant::Util::SSH do
         # mock out ChildProcess
         process = double()
         allow(ChildProcess).to receive(:build).and_return(process)
-        allow(process).to receive(:io).and_return(true)
+        allow(process).to receive(:io).and_return(double())
         allow(process.io).to receive(:inherit!).and_return(true)
         allow(process).to receive(:start).and_return(true)
         allow(process).to receive(:wait).and_return(true)
-- 
2.29.2