1 #! /usr/bin/env ruby -S rspec
4 describe "the uriescape function" do
5 let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
8 expect(Puppet::Parser::Functions.function("uriescape")).to eq("function_uriescape")
11 it "should raise a ParseError if there is less than 1 arguments" do
12 expect { scope.function_uriescape([]) }.to( raise_error(Puppet::ParseError))
15 it "should uriescape a string" do
16 result = scope.function_uriescape([":/?#[]@!$&'()*+,;= \"{}"])
17 expect(result).to(eq(':/?%23[]@!$&\'()*+,;=%20%22%7B%7D'))
20 it "should uriescape an array of strings, while not touching up nonstrings" do
21 teststring = ":/?#[]@!$&'()*+,;= \"{}"
22 expectstring = ':/?%23[]@!$&\'()*+,;=%20%22%7B%7D'
23 result = scope.function_uriescape([[teststring, teststring, 1]])
24 expect(result).to(eq([expectstring, expectstring, 1]))
27 it "should do nothing if a string is already safe" do
28 result = scope.function_uriescape(["ABCdef"])
29 expect(result).to(eq('ABCdef'))
32 it "should accept objects which extend String" do
33 class AlsoString < String
36 value = AlsoString.new('abc')
37 result = scope.function_uriescape([value])
38 result.should(eq('abc'))