Skip to content

Commit 2fcea98

Browse files
committed
Addressing uriescape testing
1 parent 6713b71 commit 2fcea98

File tree

2 files changed

+30
-26
lines changed

2 files changed

+30
-26
lines changed

lib/puppet/parser/functions/uriescape.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#
55
# uriescape.rb
66
# Please note: This function is an implementation of a Ruby class and as such may not be entirely UTF8 compatible. To ensure compatibility please use this function with Ruby 2.4.0 or greater - https://bugs.ruby-lang.org/issues/10085.
7+
# URI.escape has been fully removed as of Ruby 3. Therefore, it will not work as it stand on Puppet 8. Consider deprecating or updating this function.
78
#
89
module Puppet::Parser::Functions
910
newfunction(:uriescape, type: :rvalue, doc: <<-DOC

spec/functions/uriescape_spec.rb

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,39 @@
33
require 'spec_helper'
44

55
describe 'uriescape' do
6-
describe 'signature validation' do
7-
it { is_expected.not_to eq(nil) }
8-
it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
9-
it {
10-
pending('Current implementation ignores parameters after the first.')
11-
is_expected.to run.with_params('', '').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i)
12-
}
13-
it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, %r{Requires either array or string to work}) }
14-
it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, %r{Requires either array or string to work}) }
15-
it { is_expected.to run.with_params(true).and_raise_error(Puppet::ParseError, %r{Requires either array or string to work}) }
16-
end
6+
# URI.escape has been fully removed as of Ruby 3. Therefore, it will not work as it stand on Puppet 8.
7+
if Puppet::Util::Package.versioncmp(Puppet.version, '8.0.0').negative?
8+
describe 'signature validation' do
9+
it { is_expected.not_to eq(nil) }
10+
it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
11+
it {
12+
pending('Current implementation ignores parameters after the first.')
13+
is_expected.to run.with_params('', '').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i)
14+
}
15+
it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, %r{Requires either array or string to work}) }
16+
it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, %r{Requires either array or string to work}) }
17+
it { is_expected.to run.with_params(true).and_raise_error(Puppet::ParseError, %r{Requires either array or string to work}) }
18+
end
1719

18-
describe 'handling normal strings' do
19-
it 'calls ruby\'s URI::DEFAULT_PARSER.escape function' do
20-
expect(URI::DEFAULT_PARSER).to receive(:escape).with('uri_string').and_return('escaped_uri_string').once
21-
is_expected.to run.with_params('uri_string').and_return('escaped_uri_string')
20+
describe 'handling normal strings' do
21+
it 'calls ruby\'s URI::DEFAULT_PARSER.escape function' do
22+
expect(URI::DEFAULT_PARSER).to receive(:escape).with('uri_string').and_return('escaped_uri_string').once
23+
is_expected.to run.with_params('uri_string').and_return('escaped_uri_string')
24+
end
2225
end
23-
end
2426

25-
describe 'handling classes derived from String' do
26-
it 'calls ruby\'s URI::DEFAULT_PARSER.escape function' do
27-
uri_string = AlsoString.new('uri_string')
28-
expect(URI::DEFAULT_PARSER).to receive(:escape).with(uri_string).and_return('escaped_uri_string').once
29-
is_expected.to run.with_params(uri_string).and_return('escaped_uri_string')
27+
describe 'handling classes derived from String' do
28+
it 'calls ruby\'s URI::DEFAULT_PARSER.escape function' do
29+
uri_string = AlsoString.new('uri_string')
30+
expect(URI::DEFAULT_PARSER).to receive(:escape).with(uri_string).and_return('escaped_uri_string').once
31+
is_expected.to run.with_params(uri_string).and_return('escaped_uri_string')
32+
end
3033
end
31-
end
3234

33-
describe 'strings in arrays handling' do
34-
it { is_expected.to run.with_params([]).and_return([]) }
35-
it { is_expected.to run.with_params(['one}', 'two']).and_return(['one%7D', 'two']) }
36-
it { is_expected.to run.with_params(['one}', 1, true, {}, 'two']).and_return(['one%7D', 1, true, {}, 'two']) }
35+
describe 'strings in arrays handling' do
36+
it { is_expected.to run.with_params([]).and_return([]) }
37+
it { is_expected.to run.with_params(['one}', 'two']).and_return(['one%7D', 'two']) }
38+
it { is_expected.to run.with_params(['one}', 1, true, {}, 'two']).and_return(['one%7D', 1, true, {}, 'two']) }
39+
end
3740
end
3841
end

0 commit comments

Comments
 (0)