test/unit/plugins/provisioners/ansible/provisioner_test.rb in vagrant-unbundled-2.0.1.0 vs test/unit/plugins/provisioners/ansible/provisioner_test.rb in vagrant-unbundled-2.0.2.0

- old
+ new

@@ -200,10 +200,18 @@ expect(find_last_argument_after(inventory_index, args, /--inventory-file=\w+/)).to be(false) }.and_return(default_execute_result) end end + def ensure_that_config_is_valid + # Abort the test when an invalid configuration is detected + config.validate(machine) + if config._detected_errors.length > 0 + raise "Invalid Provisioner Configuration! Detected Errors:\n#{config._detected_errors.to_s}" + end + end + describe "#provision" do before do unless RSpec.current_example.metadata[:skip_before] config.finalize! @@ -214,10 +222,12 @@ end end after do unless RSpec.current_example.metadata[:skip_after] + ensure_that_config_is_valid + subject.provision end end describe 'checking existence of Ansible configuration files' do @@ -231,10 +241,11 @@ path: STUBBED_INVALID_PATH, system: "host") config.playbook = STUBBED_INVALID_PATH config.finalize! + ensure_that_config_is_valid expect {subject.provision}.to raise_error(VagrantPlugins::Ansible::Errors::AnsibleError, "`playbook` does not exist on the host: #{STUBBED_INVALID_PATH}") end @@ -243,15 +254,12 @@ allow(Vagrant::Util::Subprocess).to receive(:execute) .and_return( Vagrant::Util::Subprocess::Result.new(0, "", "")) config.playbook = existing_file config.send(option_name + '=', STUBBED_INVALID_PATH) - if option_name == 'extra_vars' - # little trick to auto-append the '@' prefix, which is a duty of the config validator... - config.validate(machine) - end config.finalize! + ensure_that_config_is_valid expect {subject.provision}.to raise_error(VagrantPlugins::Ansible::Errors::AnsibleError, "`#{option_name}` does not exist on the host: #{STUBBED_INVALID_PATH}") end end @@ -259,10 +267,11 @@ end describe 'when ansible-playbook fails' do it "raises an error", skip_before: true, skip_after: true do config.finalize! + ensure_that_config_is_valid allow(subject).to receive(:check_path) allow(Vagrant::Util::Subprocess).to receive(:execute) .and_return(Vagrant::Util::Subprocess::Result.new(1, "", "")) @@ -396,10 +405,11 @@ before do allow(subject).to receive(:gather_ansible_version).and_return("ansible 1.9.3\n...\n") end it "raises a compatibility conflict error", skip_before: false, skip_after: true do + ensure_that_config_is_valid expect {subject.provision}.to raise_error(VagrantPlugins::Ansible::Errors::AnsibleCompatibilityModeConflict) end end describe "deprecated 'sudo' options are aliases for equivalent 'become' options" do @@ -984,10 +994,11 @@ before do allow(subject).to receive(:gather_ansible_version).and_return("ansible 1.9.6\n...\n") end it "raises an error about the ansible version mismatch", skip_before: false, skip_after: true do + ensure_that_config_is_valid expect {subject.provision}.to raise_error(VagrantPlugins::Ansible::Errors::AnsibleVersionMismatch) end end describe "and the installed ansible version cannot be detected" do @@ -1018,9 +1029,10 @@ config.galaxy_role_file = existing_file end it "raises an error when ansible-galaxy command fails", skip_before: true, skip_after: true do config.finalize! + ensure_that_config_is_valid allow(subject).to receive(:check_path) allow(Vagrant::Util::Subprocess).to receive(:execute) .and_return(Vagrant::Util::Subprocess::Result.new(1, "", ""))