Skip to content

Commit afbaf19

Browse files
Merge pull request #2060 from ekohl/ruby-2.7
Use Ruby 2.7 compatible string matching
2 parents 86486cb + 4332276 commit afbaf19

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

lib/puppet/functions/apache/bool2httpd.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,14 @@
1717
# apache::bool2httpd(undef) # returns 'Off'
1818
#
1919
def bool2httpd(arg)
20-
return 'Off' if arg.nil? || arg == false || arg =~ %r{false}i || arg == :undef
21-
return 'On' if arg == true || arg =~ %r{true}i
20+
return 'Off' if arg.nil? || arg == false || matches_string?(arg, %r{false}i) || arg == :undef
21+
return 'On' if arg == true || matches_string?(arg, %r{true}i)
2222
arg.to_s
2323
end
24+
25+
private
26+
27+
def matches_string?(value, matcher)
28+
value.is_a?(String) && value.match?(matcher)
29+
end
2430
end

spec/functions/bool2httpd_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
it { is_expected.to run.with_params.and_raise_error(ArgumentError) }
66
it { is_expected.to run.with_params('1', '2').and_raise_error(ArgumentError) }
77
it { is_expected.to run.with_params(true).and_return('On') }
8+
it { is_expected.to run.with_params('true').and_return('On') }
89
it 'expected to return a string "On"' do
910
expect(subject.execute(true)).to be_an_instance_of(String)
1011
end
1112
it { is_expected.to run.with_params(false).and_return('Off') }
13+
it { is_expected.to run.with_params('false').and_return('Off') }
1214
it 'expected to return a string "Off"' do
1315
expect(subject.execute(false)).to be_an_instance_of(String)
1416
end

0 commit comments

Comments
 (0)