Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions lib/puppet/functions/stdlib/end_with.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# @summary
# Return true if test_string ends with suffux
#
# @example
# 'foobar'.stdlib::end_with('bar') => true
# 'foobar'.stdlib::end_with('foo') => false
Puppet::Functions.create_function(:'stdlib::end_with') do
# @param test_string the string to check
# @param suffix the suffix to check
#
# @return [Boolean] True or False
dispatch :end_with do
param 'String[1]', :test_string
param 'String[1]', :suffix
return_type 'Boolean'
end

def end_with(test_string, suffix)
test_string.end_with?(suffix)
end
end
16 changes: 16 additions & 0 deletions spec/functions/end_with_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require 'spec_helper'

describe 'stdlib::end_with' do
it { is_expected.to run.with_params('foobar', 'bar').and_return(true) }
it { is_expected.to run.with_params('foobar', 'foo').and_return(false) }
it do
is_expected.to run.with_params('', 'foo').and_raise_error(
ArgumentError, %r{'stdlib::end_with' parameter 'test_string' expects a String\[1\]}
)
end
it do
is_expected.to run.with_params('foobar', '').and_raise_error(
ArgumentError, %r{'stdlib::end_with' parameter 'suffix' expects a String\[1\]}
)
end
end