lib/aruba/api/core.rb in aruba-1.0.0.pre.alpha.2 vs lib/aruba/api/core.rb in aruba-1.0.0.pre.alpha.3
- old
+ new
@@ -23,12 +23,12 @@
# Clean the working directory of aruba
#
# This will only clean up aruba's working directory to remove all
# artifacts of your tests. This does NOT clean up the current working
# directory.
- def setup_aruba
- Aruba::Setup.new(aruba).call
+ def setup_aruba(clobber = true)
+ Aruba::Setup.new(aruba).call(clobber)
self
end
# Switch to directory
@@ -53,11 +53,11 @@
old_directory = expand_path('.')
aruba.current_directory << dir
new_directory = expand_path('.')
- aruba.event_bus.notify Events::ChangedWorkingDirectory.new(:old => old_directory, :new => new_directory)
+ aruba.event_bus.notify Events::ChangedWorkingDirectory.new(old: old_directory, new: new_directory)
old_dir = Aruba.platform.getwd
Aruba.platform.chdir File.join(aruba.root_directory, aruba.current_directory)
@@ -78,11 +78,11 @@
old_directory = expand_path('.')
aruba.current_directory << dir
new_directory = expand_path('.')
- aruba.event_bus.notify Events::ChangedWorkingDirectory.new(:old => old_directory, :new => new_directory)
+ aruba.event_bus.notify Events::ChangedWorkingDirectory.new(old: old_directory, new: new_directory)
self
end
# rubocop:enable Metrics/MethodLength
@@ -115,51 +115,65 @@
# @example using fixtures directory
#
# # => <path>/test/fixtures/file
# expand_path('%/file')
#
+ # @example Absolute directory
+ #
+ # # => /foo/bar
+ # expand_path('/foo/bar')
+ #
# rubocop:disable Metrics/MethodLength
# rubocop:disable Metrics/CyclomaticComplexity
+ # rubocop:disable Metrics/PerceivedComplexity
def expand_path(file_name, dir_string = nil)
- check_for_deprecated_variables if Aruba::VERSION < '1'
-
# rubocop:disable Metrics/LineLength
message = %(Filename "#{file_name}" needs to be a string. It cannot be nil or empty either. Please use `expand_path('.')` if you want the current directory to be expanded.)
# rubocop:enable Metrics/LineLength
fail ArgumentError, message unless file_name.is_a?(String) && !file_name.empty?
# rubocop:disable Metrics/LineLength
- aruba.logger.warn %(`aruba`'s working directory does not exist. Maybe you forgot to run `setup_aruba` before using it's API. This warning will be an error from 1.0.0) unless Aruba.platform.directory? File.join(aruba.config.root_directory, aruba.config.working_directory)
+ fail %(Aruba's working directory does not exist. Maybe you forgot to run `setup_aruba` before using its API.) unless Aruba.platform.directory? File.join(aruba.config.root_directory, aruba.config.working_directory)
+
# rubocop:enable Metrics/LineLength
prefix = file_name[0]
rest = file_name[2..-1]
if aruba.config.fixtures_path_prefix == prefix
path = File.join(*[aruba.fixtures_directory, rest].compact)
# rubocop:disable Metrics/LineLength
fail ArgumentError, %(Fixture "#{rest}" does not exist in fixtures directory "#{aruba.fixtures_directory}". This was the one we found first on your system from all possible candidates: #{aruba.config.fixtures_directories.map { |p| format('"%s"', p) }.join(', ')}.) unless Aruba.platform.exist? path
+
# rubocop:enable Metrics/LineLength
path
- elsif '~' == prefix
+ elsif prefix == '~'
path = with_environment do
ArubaPath.new(File.expand_path(file_name))
end
fail ArgumentError, 'Expanding "~/" to "/" is not allowed' if path.to_s == '/'
fail ArgumentError, %(Expanding "~/" to a relative path "#{path}" is not allowed) unless path.absolute?
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'
+ end
+ file_name
else
directory = File.join(aruba.root_directory, aruba.current_directory)
- ArubaPath.new(File.join(*[directory, dir_string, file_name].compact)).expand_path.to_s
+ directory = File.expand_path(dir_string, directory) if dir_string
+ File.expand_path(file_name, directory)
end
end
# rubocop:enable Metrics/MethodLength
- # rubocop:enable Metrics/CyclomaticComplexity
+ # rubocop:enable Metrics/CyclomaticComplexity
+ # rubocop:enable Metrics/PerceivedComplexity
# Run block with environment
#
# @param [Hash] env (optional)
# The variables to be used for block.