1 #! /usr/bin/env ruby -S rspec
4 describe Puppet::Parser::Functions.function(:validate_absolute_path) do
5 let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
7 # The subject of these examples is the method itself.
9 # This makes sure the function is loaded within each test
10 function_name = Puppet::Parser::Functions.function(:validate_absolute_path)
11 scope.method(function_name)
14 describe "Valid Paths" do
25 /var/opt/../lib/puppet
29 context "Without Puppet::Util.absolute_path? (e.g. Puppet <= 2.6)" do
31 # The intent here is to mock Puppet to behave like Puppet 2.6 does.
32 # Puppet 2.6 does not have the absolute_path? method. This is only a
33 # convenience test, stdlib should be run with the Puppet 2.6.x in the
34 # $LOAD_PATH in addition to 2.7.x and master.
35 Puppet::Util.expects(:respond_to?).with(:absolute_path?).returns(false)
37 valid_paths.each do |path|
38 it "validate_absolute_path(#{path.inspect}) should not fail" do
39 expect { subject.call [path] }.not_to raise_error
43 it "validate_absolute_path(#{valid_paths.inspect}) should not fail" do
44 expect { subject.call [valid_paths] }.not_to raise_error
49 context "Puppet without mocking" do
50 valid_paths.each do |path|
51 it "validate_absolute_path(#{path.inspect}) should not fail" do
52 expect { subject.call [path] }.not_to raise_error
56 it "validate_absolute_path(#{valid_paths.inspect}) should not fail" do
57 expect { subject.call [valid_paths] }.not_to raise_error
63 describe 'Invalid paths' do
64 context 'Garbage inputs' do
73 it "validate_absolute_path(#{path.inspect}) should fail" do
74 expect { subject.call [path] }.to raise_error Puppet::ParseError
79 context 'Relative paths' do
91 rel_paths.each do |path|
92 it "validate_absolute_path(#{path.inspect}) should fail" do
93 expect { subject.call [path] }.to raise_error Puppet::ParseError
97 it "validate_absolute_path(#{rel_paths.inspect}) should fail" do
98 expect { subject.call [rel_paths] }.to raise_error Puppet::ParseError