lib/aruba/api/core.rb in aruba-0.9.0.pre vs lib/aruba/api/core.rb in aruba-0.9.0.pre2
- old
+ new
@@ -51,34 +51,33 @@
if block_given?
begin
fail ArgumentError, "#{expand_path(dir)} is not a directory or does not exist." unless Aruba.platform.directory? expand_path(dir)
aruba.current_directory << dir
+ announcer.announce :directory, expand_path(dir)
old_dir = Aruba.platform.getwd
- old_oldpwd = ENV['OLDPWD']
- old_pwd = ENV['PWD']
- ENV['OLDPWD'] = Aruba.platform.getwd
- ENV['PWD'] = File.join(aruba.root_directory, aruba.current_directory).sub(%r{/$}, '')
-
Aruba.platform.chdir File.join(aruba.root_directory, aruba.current_directory)
- result = block.call
+ result = Aruba.platform.with_environment(
+ 'OLDPWD' => old_dir,
+ 'PWD' => File.expand_path(File.join(aruba.root_directory, aruba.current_directory)),
+ &block
+ )
ensure
aruba.current_directory.pop
Aruba.platform.chdir old_dir
- ENV['OLDPWD'] = old_oldpwd
- ENV['PWD'] = old_pwd
end
return result
end
fail ArgumentError, "#{expand_path(dir)} is not a directory or does not exist." unless Aruba.platform.directory? expand_path(dir)
aruba.current_directory << dir
+ announcer.announce :directory, expand_path(dir)
self
end
# rubocop:enable Metrics/MethodLength
@@ -127,26 +126,36 @@
# 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)
# rubocop:enable Metrics/LineLength
if RUBY_VERSION < '1.9'
- prefix = file_name.chars.to_a[0]
- rest = file_name.chars.to_a[1..-1].join('')
+ prefix = file_name.chars.to_a[0].to_s
+ rest = if file_name.chars.to_a[2..-1].nil?
+ nil
+ else
+ file_name.chars.to_a[2..-1].join
+ end
else
prefix = file_name[0]
- rest = file_name[1..-1]
+ rest = file_name[2..-1]
end
if aruba.config.fixtures_path_prefix == prefix
- File.join aruba.fixtures_directory, rest
+ 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
path = with_environment do
ArubaPath.new(File.expand_path(file_name))
end
- fail 'Expanding "~/" to "/" is not allowed' if path.to_s == '/'
- fail %(Expanding "~/" to a relative path "#{path}" is not allowed) unless path.absolute?
+ 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
else
directory = File.join(aruba.root_directory, aruba.current_directory)
ArubaPath.new(File.join(*[directory, dir_string, file_name].compact)).expand_path.to_s
@@ -161,26 +170,15 @@
# The variables to be used for block.
#
# @yield
# The block of code which should be run with the modified environment variables
def with_environment(env = {}, &block)
- if RUBY_VERSION <= '1.9.3'
- old_env = ENV.to_hash.dup
- else
- old_env = ENV.to_h.dup
- end
-
old_aruba_env = aruba.environment.to_h
- ENV.update aruba.environment.update(env).to_h
-
- block.call if block_given?
+ Aruba.platform.with_environment aruba.environment.update(env).to_h, &block
ensure
aruba.environment.clear
aruba.environment.update old_aruba_env
-
- ENV.clear
- ENV.update old_env
end
end
end
end