Skip to content

Commit

Permalink
Make error message expectation more flexible (#21591)
Browse files Browse the repository at this point in the history
To support different Ruby versions formatting the error message slightly differently
  • Loading branch information
AliSoftware committed Oct 21, 2023
1 parent bb3c4c1 commit 72d83cd
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions fastlane/spec/runner_spec.rb
Expand Up @@ -69,31 +69,28 @@
end

context 'when a lane expects its parameters as keywords' do
def keywords_list(list)
# The way keyword lists appear in error messages is different in Windows & Linux vs macOS
if FastlaneCore::Helper.windows? || FastlaneCore::Helper.linux?
list.map(&:to_s).join(', ') # On Windows and Linux, keyword names don't show the `:` prefix in error messages
else
list.map(&:inspect).join(', ') # On other platforms, they do have `:` in front or keyword names
end
def keywords_error_message(error, *kwlist)
# Depending on Ruby versions, the keyword names appear with or without a `:` in error messages, hence the `:?` Regexp
list = kwlist.map { |kw| ":?#{kw}" }.join(', ')
/#{Regexp.escape(error)}: #{list}/
end

it 'fails when calling the lane with required parameters not being passed' do
expect do
@ff.runner.execute(:lane_kw_params, :ios)
end.to raise_error(ArgumentError, "missing keywords: #{keywords_list(%i[name version])}")
end.to raise_error(ArgumentError, keywords_error_message('missing keywords', :name, :version))
end

it 'fails when calling the lane with some missing parameters' do
expect do
@ff.runner.execute(:lane_kw_params, :ios, { name: 'test', interactive: true })
end.to raise_error(ArgumentError, "missing keyword: #{keywords_list(%i[version])}")
end.to raise_error(ArgumentError, keywords_error_message('missing keyword', :version))
end

it 'fails when calling the lane with extra parameters' do
expect do
@ff.runner.execute(:lane_kw_params, :ios, { name: 'test', version: '12.3', interactive: true, unexpected: 42 })
end.to raise_error(ArgumentError, "unknown keyword: #{keywords_list(%i[unexpected])}")
end.to raise_error(ArgumentError, keywords_error_message('unknown keyword', :unexpected))
end

it 'takes all parameters into account when all are passed explicitly' do
Expand Down

0 comments on commit 72d83cd

Please sign in to comment.