From c2937f13b1ec60efee14f2a390c305c7bb19720b Mon Sep 17 00:00:00 2001 From: Gilles Cornu Date: Mon, 7 Aug 2017 08:55:00 +0200 Subject: [PATCH] Update Ansible unit tests after RSpec 3.5 ugrade - The 'ansible-galaxy' + 'ansible-playbook' sequence can now be verified - The "final true" expectation trick can now be removed - Fixed some little mistakes in 1a62743 rebase of original e8e248d --- .../provisioners/ansible/provisioner_test.rb | 37 ++++++------------- 1 file changed, 12 insertions(+), 25 deletions(-) diff --git a/test/unit/plugins/provisioners/ansible/provisioner_test.rb b/test/unit/plugins/provisioners/ansible/provisioner_test.rb index a9eb51a01..2c4b014fe 100644 --- a/test/unit/plugins/provisioners/ansible/provisioner_test.rb +++ b/test/unit/plugins/provisioners/ansible/provisioner_test.rb @@ -266,10 +266,6 @@ VF expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args| inventory_content = File.read(generated_inventory_file) expect(inventory_content).to_not match(/^\s*\[^\\+\]\s*$/) - - # Ending this block with a negative expectation (to_not / not_to) - # would lead to a failure of the above expectation. - true }.and_return(default_execute_result) end @@ -678,8 +674,7 @@ VF cmd_opts = args.last expect(cmd_opts[:env]['ANSIBLE_SSH_ARGS']).to include("-o IdentityFile=/an/other/identity") expect(cmd_opts[:env]['ANSIBLE_SSH_ARGS']).to include("-o IdentityFile=/yet/an/other/key") - default_execute_result - } + }.and_return(default_execute_result) end end @@ -689,12 +684,11 @@ VF end it "replaces `%` with `%%`" do - expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) do |*args| + expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args| cmd_opts = args.last expect(cmd_opts[:env]['ANSIBLE_SSH_ARGS']).to include("-o IdentityFile=/foo%%bar/key") expect(cmd_opts[:env]['ANSIBLE_SSH_ARGS']).to include("-o IdentityFile=/bar%%%%buz/key") - default_execute_result - end + }.and_return(default_execute_result) end end @@ -822,9 +816,14 @@ VF expect {subject.provision}.to raise_error(VagrantPlugins::Ansible::Errors::AnsibleCommandFailed) end - it "execute ansible-galaxy and ansible-playbook" do - # TODO: to be improved, but I'm currenty facing some issues, maybe only present in RSpec 2.14... - expect(Vagrant::Util::Subprocess).to receive(:execute).twice + it "execute ansible-galaxy, and then ansible-playbook" do + expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |cmd, *args| + expect(cmd).to eq("ansible-galaxy") + }.and_return(default_execute_result) + + expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |cmd, *args| + expect(cmd).to eq("ansible-playbook") + }.and_return(default_execute_result) end describe "with verbose option enabled" do @@ -987,10 +986,6 @@ VF expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args| cmd_opts = args.last expect(cmd_opts[:env]['ANSIBLE_SSH_ARGS']).to_not include("-o IdentitiesOnly=yes") - - # Ending this block with a negative expectation (to_not / not_to) - # would lead to a failure of the above expectation. - true }.and_return(default_execute_result) end @@ -1001,10 +996,6 @@ VF expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args| cmd_opts = args.last expect(cmd_opts[:env]).to_not include('ANSIBLE_SSH_ARGS') - - # Ending this block with a negative expectation (to_not / not_to) - # would lead to a failure of the above expectation. - true }.and_return(Vagrant::Util::Subprocess::Result.new(0, "", "")) end end @@ -1018,11 +1009,7 @@ VF expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args| cmd_opts = args.last expect(cmd_opts[:env]['ANSIBLE_SSH_ARGS']).to_not include("-o IdentitiesOnly=yes") - - # Ending this block with a negative expectation (to_not / not_to) - # would lead to a failure of the above expectation. - default_execute_result - } + }.and_return(default_execute_result) end end end