Skip to content

Commit

Permalink
Merge pull request #687 from cucumber/improve_expand_path_warnings
Browse files Browse the repository at this point in the history
Improve `expand_path` warnings
  • Loading branch information
mvz authored Jan 2, 2020
2 parents 41ffd30 + 6aab02f commit c2fed66
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
4 changes: 2 additions & 2 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2019-12-31 14:33:14 +0100 using RuboCop version 0.78.0.
# on 2020-01-01 19:49:41 +0100 using RuboCop version 0.78.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand Down Expand Up @@ -38,7 +38,7 @@ Metrics/BlockLength:
Metrics/ClassLength:
Max: 145

# Offense count: 18
# Offense count: 20
# Configuration parameters: CountComments, ExcludedMethods.
Metrics/MethodLength:
Max: 22
Expand Down
4 changes: 2 additions & 2 deletions features/04_aruba_api/core/expand_path.feature
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Feature: Expand paths with aruba
Then the specs should all pass
And the output should contain:
"""
Using absolute paths in Aruba is not recommended
Aruba's `expand_path` method was called with an absolute path
"""

Scenario: Silence warning about using absolute path
Expand All @@ -78,7 +78,7 @@ Feature: Expand paths with aruba
Then the specs should all pass
And the output should not contain:
"""
Using absolute paths in Aruba is not recommended
Aruba's `expand_path` method was called with an absolute path
"""

Scenario: Raise an error if aruba's working directory does not exist
Expand Down
6 changes: 4 additions & 2 deletions lib/aruba/api/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,10 @@ def expand_path(file_name, dir_string = nil)
path.to_s
elsif absolute? file_name
unless aruba.config.allow_absolute_paths
aruba.logger.warn 'Using absolute paths in Aruba is not recommended.' \
' Set config.allow_absolute_paths = true to silence this warning'
caller_location = caller_locations(1, 1).first
caller_file_line = "#{caller_location.path}:#{caller_location.lineno}"
aruba.logger.warn "Aruba's `expand_path` method was called with an absolute path at #{caller_file_line}, which is not recommended." \
' Change the call to pass a relative path or set config.allow_absolute_paths = true to silence this warning'
end
file_name
else
Expand Down
4 changes: 3 additions & 1 deletion spec/aruba/api/core_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@

it 'warns about it' do
@aruba.expand_path(@file_path)
expect(logger).to have_received(:warn).with(/Using absolute paths in Aruba is not recommended/)
expect(logger).to have_received(:warn).with(
/Aruba's `expand_path` method was called with an absolute path at .*:\d+, which is not recommended/
)
end

it 'does not warn about it if told not to' do
Expand Down

0 comments on commit c2fed66

Please sign in to comment.