aruba 1.0.0.pre.alpha.3 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +0 -1
  3. data/.rubocop.yml +40 -1
  4. data/.rubocop_todo.yml +106 -254
  5. data/.simplecov +7 -5
  6. data/.travis.yml +25 -38
  7. data/CHANGELOG.md +246 -46
  8. data/CONTRIBUTING.md +8 -17
  9. data/Gemfile +5 -54
  10. data/LICENSE +1 -1
  11. data/README.md +37 -30
  12. data/Rakefile +23 -50
  13. data/appveyor.yml +4 -8
  14. data/aruba.gemspec +34 -13
  15. data/bin/console +1 -1
  16. data/cucumber.yml +4 -15
  17. data/exe/aruba +1 -1
  18. data/fixtures/cli-app/bin/aruba-test-cli +1 -1
  19. data/fixtures/cli-app/cli-app.gemspec +4 -5
  20. data/fixtures/cli-app/lib/cli/app.rb +1 -1
  21. data/fixtures/cli-app/spec/spec_helper.rb +3 -2
  22. data/fixtures/empty-app/cli-app.gemspec +4 -5
  23. data/fixtures/empty-app/lib/cli/app.rb +0 -2
  24. data/fixtures/getting-started-app/Gemfile +1 -1
  25. data/lib/aruba/api.rb +6 -6
  26. data/lib/aruba/api/bundler.rb +1 -1
  27. data/lib/aruba/api/commands.rb +36 -13
  28. data/lib/aruba/api/core.rb +74 -47
  29. data/lib/aruba/api/environment.rb +16 -4
  30. data/lib/aruba/api/filesystem.rb +48 -48
  31. data/lib/aruba/api/text.rb +15 -3
  32. data/lib/aruba/aruba_path.rb +24 -95
  33. data/lib/aruba/basic_configuration.rb +5 -6
  34. data/lib/aruba/basic_configuration/option.rb +2 -2
  35. data/lib/aruba/cli.rb +4 -1
  36. data/lib/aruba/colorizer.rb +10 -99
  37. data/lib/aruba/config/jruby.rb +15 -5
  38. data/lib/aruba/config_wrapper.rb +17 -2
  39. data/lib/aruba/configuration.rb +43 -14
  40. data/lib/aruba/console.rb +0 -2
  41. data/lib/aruba/console/help.rb +5 -2
  42. data/lib/aruba/contracts/absolute_path.rb +3 -3
  43. data/lib/aruba/contracts/is_power_of_two.rb +2 -2
  44. data/lib/aruba/contracts/relative_path.rb +3 -3
  45. data/lib/aruba/cucumber.rb +0 -2
  46. data/lib/aruba/cucumber/command.rb +190 -93
  47. data/lib/aruba/cucumber/file.rb +53 -35
  48. data/lib/aruba/cucumber/hooks.rb +4 -1
  49. data/lib/aruba/cucumber/testing_frameworks.rb +76 -50
  50. data/lib/aruba/event_bus.rb +4 -2
  51. data/lib/aruba/event_bus/name_resolver.rb +9 -8
  52. data/lib/aruba/events.rb +2 -1
  53. data/lib/aruba/hooks.rb +2 -4
  54. data/lib/aruba/in_config_wrapper.rb +10 -3
  55. data/lib/aruba/initializer.rb +37 -31
  56. data/lib/aruba/matchers/base/base_matcher.rb +2 -11
  57. data/lib/aruba/matchers/base/message_indenter.rb +1 -1
  58. data/lib/aruba/matchers/base/object_formatter.rb +0 -5
  59. data/lib/aruba/matchers/collection/include_an_object.rb +4 -4
  60. data/lib/aruba/matchers/command/be_successfully_executed.rb +6 -0
  61. data/lib/aruba/matchers/command/have_exit_status.rb +15 -3
  62. data/lib/aruba/matchers/command/have_finished_in_time.rb +3 -1
  63. data/lib/aruba/matchers/command/have_output.rb +3 -1
  64. data/lib/aruba/matchers/command/have_output_on_stderr.rb +3 -1
  65. data/lib/aruba/matchers/command/have_output_on_stdout.rb +3 -1
  66. data/lib/aruba/matchers/command/have_output_size.rb +1 -1
  67. data/lib/aruba/matchers/directory/be_an_existing_directory.rb +1 -1
  68. data/lib/aruba/matchers/directory/have_sub_directory.rb +8 -3
  69. data/lib/aruba/matchers/file/be_an_existing_file.rb +1 -1
  70. data/lib/aruba/matchers/file/have_file_size.rb +4 -2
  71. data/lib/aruba/matchers/path/have_permissions.rb +4 -2
  72. data/lib/aruba/platform.rb +0 -7
  73. data/lib/aruba/platforms/announcer.rb +36 -17
  74. data/lib/aruba/platforms/aruba_file_creator.rb +3 -1
  75. data/lib/aruba/platforms/aruba_fixed_size_file_creator.rb +7 -2
  76. data/lib/aruba/platforms/command_monitor.rb +39 -3
  77. data/lib/aruba/platforms/determine_disk_usage.rb +56 -19
  78. data/lib/aruba/platforms/simple_table.rb +2 -10
  79. data/lib/aruba/platforms/unix_environment_variables.rb +10 -13
  80. data/lib/aruba/platforms/unix_platform.rb +16 -12
  81. data/lib/aruba/platforms/unix_which.rb +1 -1
  82. data/lib/aruba/platforms/windows_command_string.rb +2 -2
  83. data/lib/aruba/platforms/windows_environment_variables.rb +9 -2
  84. data/lib/aruba/platforms/windows_platform.rb +4 -0
  85. data/lib/aruba/platforms/windows_which.rb +6 -2
  86. data/lib/aruba/processes/basic_process.rb +13 -15
  87. data/lib/aruba/processes/debug_process.rb +11 -5
  88. data/lib/aruba/processes/in_process.rb +4 -2
  89. data/lib/aruba/processes/spawn_process.rb +32 -16
  90. data/lib/aruba/rspec.rb +24 -14
  91. data/lib/aruba/runtime.rb +11 -4
  92. data/lib/aruba/setup.rb +27 -14
  93. data/lib/aruba/tasks/docker_helpers.rb +3 -1
  94. data/lib/aruba/version.rb +1 -1
  95. metadata +190 -34
  96. data/bin/build +0 -3
  97. data/bin/release +0 -3
  98. data/lib/aruba/platforms/disk_usage_calculator.rb +0 -20
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
3
+ $LOAD_PATH.unshift File.expand_path('../lib', __dir__)
4
4
 
5
5
  require 'aruba/console'
6
6
 
@@ -1,17 +1,6 @@
1
1
  <%
2
- $LOAD_PATH << ::File.expand_path('../lib', __FILE__)
3
- require 'aruba/version'
4
- require 'ffi'
5
-
6
- java_version = (RUBY_DESCRIPTION.match(/.*?on.*?(1\.[\d]\..*? )/))[1] if defined?(JRUBY_VERSION)
7
-
8
- std_opts = "--format pretty --color --exclude features/fixtures --require features --tags ~@unsupported-on"
9
- java_default_opts = "--tags ~@wip-jruby-java-1.6" if defined?(JRUBY_VERSION) && (java_version < '1.7.0')
10
- java_wip_opts = "--tags @wip-jruby-java-1.6:3" if defined?(JRUBY_VERSION) && (java_version < '1.7.0')
11
-
12
- ignore_opts = []
13
- ignore_opts << '--tags ~@ignore'
14
- ignore_opts = ignore_opts.join(' ')
2
+ std_opts = "--format pretty --color --exclude features/fixtures --require features --tags 'not @unsupported-on'"
3
+ ignore_opts = "--tags 'not @ignore'"
15
4
  %>
16
- default: <%= std_opts %> --tags ~@wip <%= java_default_opts %> <%= ignore_opts %>
17
- wip: <%= std_opts %> --wip --tags @wip:3 <%= java_wip_opts %> <%= ignore_opts %>
5
+ default: <%= std_opts %> --tags 'not @wip' <%= ignore_opts %>
6
+ wip: <%= std_opts %> --wip --tags @wip:3 <%= ignore_opts %>
data/exe/aruba CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- $LOAD_PATH << File.expand_path('../../lib', __FILE__)
3
+ $LOAD_PATH << File.expand_path('../lib', __dir__)
4
4
 
5
5
  require 'aruba/cli'
6
6
 
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- $LOAD_PATH << File.expand_path('../../lib', __FILE__)
3
+ $LOAD_PATH << File.expand_path('../lib', __dir__)
4
4
  require 'cli/app'
5
5
 
6
6
  exit 0
@@ -1,6 +1,4 @@
1
- # coding: utf-8
2
-
3
- lib = File.expand_path('../lib', __FILE__)
1
+ lib = File.expand_path('lib', __dir__)
4
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
3
  require 'cli/app/version'
6
4
 
@@ -17,11 +15,12 @@ Gem::Specification.new do |spec|
17
15
  # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
16
  # delete this section to allow pushing this gem to any host.
19
17
 
20
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.files = `git ls-files -z`.split("\x0")
19
+ .reject { |f| f.match(%r{^(test|spec|features)/}) }
21
20
  spec.bindir = 'exe'
22
21
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
22
  spec.require_paths = ['lib']
24
23
 
25
24
  spec.add_development_dependency 'bundler', '~> 1.9'
26
- spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'rake', '~> 13.0'
27
26
  end
@@ -1,6 +1,6 @@
1
1
  require 'cli/app/version'
2
2
 
3
- ::Dir.glob(File.expand_path('../**/*.rb', __FILE__)).each { |f| require_relative f }
3
+ ::Dir.glob(File.expand_path('**/*.rb', __dir__)).each { |f| require_relative f }
4
4
 
5
5
  module Cli
6
6
  module App
@@ -1,7 +1,8 @@
1
- $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
1
+ $LOAD_PATH.unshift File.expand_path('../lib', __dir__)
2
2
 
3
3
  require 'cli/app'
4
4
 
5
5
  require_relative 'support/aruba'
6
6
 
7
- ::Dir.glob(::File.expand_path('../support/**/*.rb', __FILE__)).each { |f| require_relative f }
7
+ ::Dir.glob(::File.expand_path('../support/**/*.rb', __FILE__))
8
+ .each { |f| require_relative f }
@@ -1,6 +1,4 @@
1
- # coding: utf-8
2
-
3
- lib = File.expand_path('../lib', __FILE__)
1
+ lib = File.expand_path('lib', __dir__)
4
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
3
  require 'cli/app/version'
6
4
 
@@ -17,11 +15,12 @@ Gem::Specification.new do |spec|
17
15
  # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
16
  # delete this section to allow pushing this gem to any host.
19
17
 
20
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.files = `git ls-files -z`.split("\x0")
19
+ .reject { |f| f.match(%r{^(test|spec|features)/}) }
21
20
  spec.bindir = 'exe'
22
21
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
22
  spec.require_paths = ['lib']
24
23
 
25
24
  spec.add_development_dependency 'bundler', '~> 1.9'
26
- spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'rake', '~> 13.0'
27
26
  end
@@ -1,7 +1,5 @@
1
1
  require 'cli/app/version'
2
2
 
3
- ::Dir.glob(File.expand_path('../**/*.rb', __FILE__)).each { |f| require_relative f }
4
-
5
3
  module Cli
6
4
  module App
7
5
  # Your code goes here...
@@ -1,4 +1,4 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'aruba', path: File.expand_path('../../../../', __FILE__)
3
+ gem 'aruba', path: File.expand_path('../../..', __dir__)
4
4
  gem 'cucumber'
@@ -19,11 +19,11 @@ Aruba.platform.require_matching_files('../matchers/**/*.rb', __FILE__)
19
19
  module Aruba
20
20
  # Api
21
21
  module Api
22
- include Aruba::Api::Core
23
- include Aruba::Api::Commands
24
- include Aruba::Api::Environment
25
- include Aruba::Api::Filesystem
26
- include Aruba::Api::Text
27
- include Aruba::Api::Bundler
22
+ include Core
23
+ include Commands
24
+ include Environment
25
+ include Filesystem
26
+ include Text
27
+ include Bundler
28
28
  end
29
29
  end
@@ -7,7 +7,7 @@ module Aruba
7
7
 
8
8
  # Unset variables used by bundler
9
9
  def unset_bundler_env_vars
10
- %w[RUBYOPT BUNDLE_PATH BUNDLE_BIN_PATH BUNDLE_GEMFILE].each do |key|
10
+ %w(RUBYOPT BUNDLE_PATH BUNDLE_BIN_PATH BUNDLE_GEMFILE).each do |key|
11
11
  delete_environment_variable(key)
12
12
  end
13
13
  end
@@ -92,6 +92,30 @@ module Aruba
92
92
  self
93
93
  end
94
94
 
95
+ # Get stdout of all processes
96
+ #
97
+ # @return [String]
98
+ # The stdout of all processes which have run before
99
+ def all_stdout
100
+ aruba.command_monitor.all_stdout
101
+ end
102
+
103
+ # Get stderr of all processes
104
+ #
105
+ # @return [String]
106
+ # The stderr of all processes which have run before
107
+ def all_stderr
108
+ aruba.command_monitor.all_stderr
109
+ end
110
+
111
+ # Get stderr and stdout of all processes
112
+ #
113
+ # @return [String]
114
+ # The stderr and stdout of all processes which have run before
115
+ def all_output
116
+ aruba.command_monitor.all_output
117
+ end
118
+
95
119
  # Find a started command
96
120
  #
97
121
  # @param [String, Command] commandline
@@ -128,7 +152,7 @@ module Aruba
128
152
 
129
153
  unless command.interactive?
130
154
  raise NotImplementedError,
131
- 'Running interactively is not supported with this process launcher.'
155
+ 'Running interactively is not supported with this process launcher.'
132
156
  end
133
157
 
134
158
  start_command(command)
@@ -144,16 +168,16 @@ module Aruba
144
168
  # @param [String] cmd
145
169
  # The command to be executed
146
170
  #
147
- # @param [Hash] options
171
+ # @param [Hash] opts
148
172
  # Options for aruba
149
173
  #
150
- # @option options [Boolean] fail_on_error
174
+ # @option opts [Boolean] :fail_on_error
151
175
  # Should aruba fail on error?
152
176
  #
153
- # @option options [Numeric] exit_timeout
177
+ # @option opts [Numeric] :exit_timeout
154
178
  # Timeout for execution
155
179
  #
156
- # @option options [Numeric] io_wait_timeout
180
+ # @option opts [Numeric] :io_wait_timeout
157
181
  # Timeout for IO - STDERR, STDOUT
158
182
  #
159
183
  def run_command_and_stop(cmd, opts = {})
@@ -196,12 +220,11 @@ module Aruba
196
220
 
197
221
  private
198
222
 
199
- # rubocop:disable Metrics/MethodLength
200
223
  def prepare_command(cmd, opts)
201
- exit_timeout = opts[:exit_timeout].nil? ? aruba.config.exit_timeout : opts[:exit_timeout]
202
- io_wait_timeout = opts[:io_wait_timeout].nil? ? aruba.config.io_wait_timeout : opts[:io_wait_timeout]
203
- stop_signal = opts[:stop_signal].nil? ? aruba.config.stop_signal : opts[:stop_signal]
204
- startup_wait_time = opts[:startup_wait_time].nil? ? aruba.config.startup_wait_time : opts[:startup_wait_time]
224
+ exit_timeout = opts[:exit_timeout] || aruba.config.exit_timeout
225
+ io_wait_timeout = opts[:io_wait_timeout] || aruba.config.io_wait_timeout
226
+ stop_signal = opts[:stop_signal] || aruba.config.stop_signal
227
+ startup_wait_time = opts[:startup_wait_time] || aruba.config.startup_wait_time
205
228
 
206
229
  cmd = replace_variables(cmd)
207
230
 
@@ -232,12 +255,12 @@ module Aruba
232
255
  )
233
256
  end
234
257
 
235
- # rubocop:enable Metrics/MethodLength
236
-
237
258
  def start_command(command)
238
259
  aruba.config.before(:command, self, command)
239
260
 
240
- command.start
261
+ in_current_directory do
262
+ command.start
263
+ end
241
264
 
242
265
  stop_signal = command.stop_signal
243
266
  aruba.announcer.announce(:stop_signal, command.pid, stop_signal) if stop_signal
@@ -3,8 +3,6 @@ require 'aruba/runtime'
3
3
  require 'aruba/errors'
4
4
  require 'aruba/setup'
5
5
 
6
- require 'aruba/config/jruby'
7
-
8
6
  # Aruba
9
7
  module Aruba
10
8
  # Api
@@ -17,6 +15,10 @@ module Aruba
17
15
 
18
16
  # Aruba Runtime
19
17
  def aruba
18
+ # TODO: Check this variable being accessed inconsistently. Should only
19
+ # be using the memo!
20
+ # Renaming this to `aruba` causes 100's of rspec failures. Needs a
21
+ # deeper dive, approach with caution!
20
22
  @_aruba_runtime ||= Runtime.new
21
23
  end
22
24
 
@@ -31,6 +33,15 @@ module Aruba
31
33
  self
32
34
  end
33
35
 
36
+ # Execute block in Aruba's current directory
37
+ #
38
+ # @yield
39
+ # The block which should be run in current directory
40
+ def in_current_directory(&block)
41
+ create_directory '.' unless directory?('.')
42
+ cd('.', &block)
43
+ end
44
+
34
45
  # Switch to directory
35
46
  #
36
47
  # @param [String] dir
@@ -45,25 +56,30 @@ module Aruba
45
56
  # @example Run code in directory
46
57
  # result = cd('some-dir') { Dir.getwd }
47
58
  #
48
- # rubocop:disable Metrics/MethodLength
49
59
  def cd(dir, &block)
50
60
  if block_given?
51
61
  begin
52
- fail ArgumentError, "#{expand_path(dir)} is not a directory or does not exist." unless Aruba.platform.directory? expand_path(dir)
62
+ unless Aruba.platform.directory?(expand_path(dir))
63
+ raise ArgumentError,
64
+ "#{expand_path(dir)} is not a directory or does not exist."
65
+ end
53
66
 
54
67
  old_directory = expand_path('.')
55
68
  aruba.current_directory << dir
56
69
  new_directory = expand_path('.')
57
70
 
58
- aruba.event_bus.notify Events::ChangedWorkingDirectory.new(old: old_directory, new: new_directory)
71
+ aruba.event_bus.notify Events::ChangedWorkingDirectory.new(old: old_directory,
72
+ new: new_directory)
59
73
 
60
74
  old_dir = Aruba.platform.getwd
61
75
 
62
- Aruba.platform.chdir File.join(aruba.root_directory, aruba.current_directory)
76
+ real_new_directory = File.expand_path(aruba.current_directory,
77
+ aruba.root_directory)
78
+ Aruba.platform.chdir real_new_directory
63
79
 
64
80
  result = with_environment(
65
81
  'OLDPWD' => old_dir,
66
- 'PWD' => File.expand_path(File.join(aruba.root_directory, aruba.current_directory)),
82
+ 'PWD' => real_new_directory,
67
83
  &block
68
84
  )
69
85
  ensure
@@ -74,17 +90,19 @@ module Aruba
74
90
  return result
75
91
  end
76
92
 
77
- fail ArgumentError, "#{expand_path(dir)} is not a directory or does not exist." unless Aruba.platform.directory? expand_path(dir)
93
+ unless Aruba.platform.directory?(expand_path(dir))
94
+ raise ArgumentError, "#{expand_path(dir)} is not a directory or does not exist."
95
+ end
78
96
 
79
97
  old_directory = expand_path('.')
80
98
  aruba.current_directory << dir
81
99
  new_directory = expand_path('.')
82
100
 
83
- aruba.event_bus.notify Events::ChangedWorkingDirectory.new(old: old_directory, new: new_directory)
101
+ aruba.event_bus.notify Events::ChangedWorkingDirectory.new(old: old_directory,
102
+ new: new_directory)
84
103
 
85
104
  self
86
105
  end
87
- # rubocop:enable Metrics/MethodLength
88
106
 
89
107
  # Expand file name
90
108
  #
@@ -122,57 +140,70 @@ module Aruba
122
140
  # # => /foo/bar
123
141
  # expand_path('/foo/bar')
124
142
  #
125
- # rubocop:disable Metrics/MethodLength
126
- # rubocop:disable Metrics/CyclomaticComplexity
127
- # rubocop:disable Metrics/PerceivedComplexity
128
143
  def expand_path(file_name, dir_string = nil)
129
- # rubocop:disable Metrics/LineLength
130
- 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.)
131
- # rubocop:enable Metrics/LineLength
144
+ unless file_name.is_a?(String) && !file_name.empty?
145
+ message = "Filename #{file_name} needs to be a string." \
146
+ ' It cannot be nil or empty either. '\
147
+ "Please use `expand_path('.')` if you want the current directory to be expanded."
132
148
 
133
- fail ArgumentError, message unless file_name.is_a?(String) && !file_name.empty?
134
-
135
- # rubocop:disable Metrics/LineLength
136
- 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)
149
+ raise ArgumentError, message
150
+ end
137
151
 
138
- # rubocop:enable Metrics/LineLength
152
+ unless Aruba.platform.directory? File.join(aruba.config.root_directory,
153
+ aruba.config.working_directory)
154
+ raise "Aruba's working directory does not exist." \
155
+ ' Maybe you forgot to run `setup_aruba` before using its API.'
156
+ end
139
157
 
140
158
  prefix = file_name[0]
141
- rest = file_name[2..-1]
142
159
 
143
160
  if aruba.config.fixtures_path_prefix == prefix
161
+ rest = file_name[2..-1]
144
162
  path = File.join(*[aruba.fixtures_directory, rest].compact)
145
-
146
- # rubocop:disable Metrics/LineLength
147
- 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
148
-
149
- # rubocop:enable Metrics/LineLength
163
+ unless Aruba.platform.exist? path
164
+ aruba_fixture_candidates = aruba.config.fixtures_directories
165
+ .map { |p| format('"%s"', p) }.join(', ')
166
+
167
+ raise ArgumentError,
168
+ "Fixture \"#{rest}\" does not exist" \
169
+ " in fixtures directory \"#{aruba.fixtures_directory}\"." \
170
+ ' This was the one we found first on your system from all possible' \
171
+ " candidates: #{aruba_fixture_candidates}."
172
+ end
150
173
 
151
174
  path
152
175
  elsif prefix == '~'
153
176
  path = with_environment do
154
- ArubaPath.new(File.expand_path(file_name))
177
+ File.expand_path(file_name)
155
178
  end
156
179
 
157
- fail ArgumentError, 'Expanding "~/" to "/" is not allowed' if path.to_s == '/'
158
- fail ArgumentError, %(Expanding "~/" to a relative path "#{path}" is not allowed) unless path.absolute?
180
+ raise ArgumentError, 'Expanding "~/" to "/" is not allowed' if path == '/'
181
+
182
+ unless Aruba.platform.absolute_path? path
183
+ raise ArgumentError,
184
+ "Expanding \"~\" to a relative path \"#{path}\" is not allowed"
185
+ end
159
186
 
160
187
  path.to_s
161
- elsif absolute? file_name
188
+ elsif absolute?(file_name)
162
189
  unless aruba.config.allow_absolute_paths
163
- aruba.logger.warn 'Using absolute paths in Aruba is not recommended.' \
164
- ' Set config.allow_absolute_paths = true to silence this warning'
190
+ caller_location = caller_locations(1, 1).first
191
+ caller_file_line = "#{caller_location.path}:#{caller_location.lineno}"
192
+ aruba.logger.warn \
193
+ "Aruba's `expand_path` method was called with an absolute path" \
194
+ " at #{caller_file_line}, which is not recommended." \
195
+ ' Change the call to pass a relative path or set '\
196
+ '`config.allow_absolute_paths = true` to silence this warning'
165
197
  end
166
198
  file_name
167
199
  else
168
- directory = File.join(aruba.root_directory, aruba.current_directory)
169
- directory = File.expand_path(dir_string, directory) if dir_string
170
- File.expand_path(file_name, directory)
200
+ with_environment do
201
+ directory = File.expand_path(aruba.current_directory, aruba.root_directory)
202
+ directory = File.expand_path(dir_string, directory) if dir_string
203
+ File.expand_path(file_name, directory)
204
+ end
171
205
  end
172
206
  end
173
- # rubocop:enable Metrics/MethodLength
174
- # rubocop:enable Metrics/CyclomaticComplexity
175
- # rubocop:enable Metrics/PerceivedComplexity
176
207
 
177
208
  # Run block with environment
178
209
  #
@@ -182,14 +213,10 @@ module Aruba
182
213
  # @yield
183
214
  # The block of code which should be run with the changed environment variables
184
215
  def with_environment(env = {}, &block)
185
- old_aruba_env = aruba.environment.to_h
186
-
187
- # make sure the old environment is really restored in "ENV"
188
- Aruba.platform.with_environment aruba.environment.update(env).to_h, &block
189
- ensure
190
- # make sure the old environment is really restored in "aruba.environment"
191
- aruba.environment.clear
192
- aruba.environment.update old_aruba_env
216
+ aruba.environment.nest do |nested_env|
217
+ nested_env.update(env)
218
+ Aruba.platform.with_environment nested_env.to_h, &block
219
+ end
193
220
  end
194
221
  end
195
222
  end