aruba 1.0.0.pre.alpha.2 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. checksums.yaml +5 -5
  2. data/.github/PULL_REQUEST_TEMPLATE.md +2 -1
  3. data/.rspec +0 -1
  4. data/.rubocop.yml +46 -182
  5. data/.rubocop_todo.yml +216 -0
  6. data/.simplecov +7 -5
  7. data/.travis.yml +56 -40
  8. data/.yardopts +3 -0
  9. data/CHANGELOG.md +1312 -0
  10. data/CONTRIBUTING.md +175 -83
  11. data/Gemfile +5 -69
  12. data/LICENSE +1 -1
  13. data/README.md +58 -21
  14. data/Rakefile +27 -54
  15. data/appveyor.yml +7 -10
  16. data/aruba.gemspec +38 -19
  17. data/bin/console +3 -12
  18. data/cucumber.yml +4 -22
  19. data/exe/aruba +1 -1
  20. data/fixtures/cli-app/README.md +1 -1
  21. data/fixtures/cli-app/Rakefile +1 -1
  22. data/fixtures/cli-app/bin/aruba-test-cli +1 -1
  23. data/fixtures/cli-app/cli-app.gemspec +4 -4
  24. data/fixtures/cli-app/lib/cli/app.rb +1 -1
  25. data/fixtures/cli-app/lib/cli/app/suppress_simple_cov_output.rb +3 -3
  26. data/fixtures/cli-app/lib/cli/app/version.rb +1 -1
  27. data/fixtures/cli-app/spec/spec_helper.rb +3 -2
  28. data/fixtures/empty-app/Rakefile +1 -1
  29. data/fixtures/empty-app/cli-app.gemspec +4 -4
  30. data/fixtures/empty-app/lib/cli/app.rb +0 -2
  31. data/fixtures/empty-app/lib/cli/app/version.rb +1 -1
  32. data/fixtures/getting-started-app/Gemfile +1 -1
  33. data/lib/aruba/api.rb +8 -15
  34. data/lib/aruba/api/bundler.rb +16 -0
  35. data/lib/aruba/api/commands.rb +272 -0
  36. data/lib/aruba/api/core.rb +82 -43
  37. data/lib/aruba/api/environment.rb +24 -7
  38. data/lib/aruba/api/filesystem.rb +66 -64
  39. data/lib/aruba/api/text.rb +17 -11
  40. data/lib/aruba/aruba_path.rb +25 -111
  41. data/lib/aruba/basic_configuration.rb +8 -25
  42. data/lib/aruba/basic_configuration/option.rb +2 -2
  43. data/lib/aruba/cli.rb +4 -1
  44. data/lib/aruba/colorizer.rb +10 -99
  45. data/lib/aruba/command.rb +4 -0
  46. data/lib/aruba/config/jruby.rb +15 -5
  47. data/lib/aruba/config_wrapper.rb +17 -2
  48. data/lib/aruba/configuration.rb +107 -0
  49. data/lib/aruba/console.rb +5 -7
  50. data/lib/aruba/console/help.rb +5 -2
  51. data/lib/aruba/contracts/absolute_path.rb +3 -3
  52. data/lib/aruba/contracts/is_power_of_two.rb +2 -2
  53. data/lib/aruba/contracts/relative_path.rb +3 -3
  54. data/lib/aruba/cucumber.rb +0 -3
  55. data/lib/aruba/cucumber/command.rb +227 -190
  56. data/lib/aruba/cucumber/environment.rb +1 -1
  57. data/lib/aruba/cucumber/file.rb +56 -50
  58. data/lib/aruba/cucumber/hooks.rb +10 -63
  59. data/lib/aruba/cucumber/testing_frameworks.rb +76 -50
  60. data/lib/aruba/event_bus.rb +4 -2
  61. data/lib/aruba/event_bus/name_resolver.rb +10 -10
  62. data/lib/aruba/events.rb +2 -1
  63. data/lib/aruba/hooks.rb +3 -5
  64. data/lib/aruba/in_config_wrapper.rb +10 -3
  65. data/lib/aruba/initializer.rb +40 -34
  66. data/lib/aruba/matchers/base/base_matcher.rb +2 -11
  67. data/lib/aruba/matchers/base/message_indenter.rb +19 -0
  68. data/lib/aruba/matchers/base/object_formatter.rb +2 -7
  69. data/lib/aruba/matchers/collection/include_an_object.rb +11 -13
  70. data/lib/aruba/matchers/command/be_successfully_executed.rb +8 -4
  71. data/lib/aruba/matchers/command/have_exit_status.rb +16 -4
  72. data/lib/aruba/matchers/command/have_finished_in_time.rb +5 -5
  73. data/lib/aruba/matchers/command/have_output.rb +12 -5
  74. data/lib/aruba/matchers/command/have_output_on_stderr.rb +4 -2
  75. data/lib/aruba/matchers/command/have_output_on_stdout.rb +4 -2
  76. data/lib/aruba/matchers/command/have_output_size.rb +2 -2
  77. data/lib/aruba/matchers/directory/be_an_existing_directory.rb +5 -7
  78. data/lib/aruba/matchers/directory/have_sub_directory.rb +10 -7
  79. data/lib/aruba/matchers/file/be_a_command_found_in_path.rb +2 -4
  80. data/lib/aruba/matchers/file/be_an_existing_executable.rb +4 -6
  81. data/lib/aruba/matchers/file/be_an_existing_file.rb +5 -7
  82. data/lib/aruba/matchers/file/have_file_content.rb +4 -4
  83. data/lib/aruba/matchers/file/have_file_size.rb +8 -8
  84. data/lib/aruba/matchers/file/have_same_file_content.rb +9 -12
  85. data/lib/aruba/matchers/path/a_path_matching_pattern.rb +2 -4
  86. data/lib/aruba/matchers/path/be_an_absolute_path.rb +3 -5
  87. data/lib/aruba/matchers/path/be_an_existing_path.rb +4 -6
  88. data/lib/aruba/matchers/path/have_permissions.rb +8 -8
  89. data/lib/aruba/matchers/string/include_output_string.rb +8 -10
  90. data/lib/aruba/matchers/string/match_output_string.rb +9 -11
  91. data/lib/aruba/matchers/string/output_string_eq.rb +7 -9
  92. data/lib/aruba/platform.rb +0 -8
  93. data/lib/aruba/platforms/announcer.rb +60 -85
  94. data/lib/aruba/platforms/aruba_file_creator.rb +4 -2
  95. data/lib/aruba/platforms/aruba_fixed_size_file_creator.rb +8 -3
  96. data/lib/aruba/platforms/aruba_logger.rb +22 -2
  97. data/lib/aruba/platforms/command_monitor.rb +15 -102
  98. data/lib/aruba/platforms/determine_disk_usage.rb +56 -19
  99. data/lib/aruba/platforms/filesystem_status.rb +9 -9
  100. data/lib/aruba/platforms/local_environment.rb +2 -2
  101. data/lib/aruba/platforms/simple_table.rb +3 -11
  102. data/lib/aruba/platforms/unix_command_string.rb +7 -4
  103. data/lib/aruba/platforms/unix_environment_variables.rb +19 -26
  104. data/lib/aruba/platforms/unix_platform.rb +18 -39
  105. data/lib/aruba/platforms/unix_which.rb +3 -2
  106. data/lib/aruba/platforms/windows_command_string.rb +20 -7
  107. data/lib/aruba/platforms/windows_environment_variables.rb +42 -30
  108. data/lib/aruba/platforms/windows_platform.rb +4 -0
  109. data/lib/aruba/platforms/windows_which.rb +9 -4
  110. data/lib/aruba/processes/basic_process.rb +21 -27
  111. data/lib/aruba/processes/debug_process.rb +16 -5
  112. data/lib/aruba/processes/in_process.rb +20 -9
  113. data/lib/aruba/processes/spawn_process.rb +64 -36
  114. data/lib/aruba/rspec.rb +28 -31
  115. data/lib/aruba/runtime.rb +16 -7
  116. data/lib/aruba/setup.rb +32 -17
  117. data/lib/aruba/tasks/docker_helpers.rb +4 -2
  118. data/lib/aruba/version.rb +1 -1
  119. metadata +194 -64
  120. data/History.md +0 -612
  121. data/bin/bootstrap +0 -34
  122. data/bin/build +0 -3
  123. data/bin/release +0 -3
  124. data/fixtures/spawn_process/stderr.sh +0 -3
  125. data/lib/aruba/api/command.rb +0 -309
  126. data/lib/aruba/api/deprecated.rb +0 -895
  127. data/lib/aruba/api/rvm.rb +0 -44
  128. data/lib/aruba/config.rb +0 -101
  129. data/lib/aruba/cucumber/rvm.rb +0 -3
  130. data/lib/aruba/in_process.rb +0 -14
  131. data/lib/aruba/jruby.rb +0 -4
  132. data/lib/aruba/matchers/path/match_path_pattern.rb +0 -41
  133. data/lib/aruba/matchers/rspec_matcher_include_regexp.rb +0 -25
  134. data/lib/aruba/platforms/disk_usage_calculator.rb +0 -20
  135. data/lib/aruba/spawn_process.rb +0 -11
@@ -0,0 +1,16 @@
1
+ require 'aruba/api/environment'
2
+
3
+ module Aruba
4
+ module Api
5
+ module Bundler
6
+ include Environment
7
+
8
+ # Unset variables used by bundler
9
+ def unset_bundler_env_vars
10
+ %w(RUBYOPT BUNDLE_PATH BUNDLE_BIN_PATH BUNDLE_GEMFILE).each do |key|
11
+ delete_environment_variable(key)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,272 @@
1
+ require 'pathname'
2
+
3
+ require 'aruba/platform'
4
+ require 'aruba/command'
5
+
6
+ # require 'win32/file' if File::ALT_SEPARATOR
7
+
8
+ # Aruba
9
+ module Aruba
10
+ # Api
11
+ module Api
12
+ # Command module
13
+ module Commands
14
+ # Resolve path for command using the PATH-environment variable
15
+ #
16
+ # @param [#to_s] program
17
+ # The name of the program which should be resolved
18
+ #
19
+ # @param [String] path
20
+ # The PATH, a string concatenated with ":", e.g. /usr/bin/:/bin on a
21
+ # UNIX-system
22
+ def which(program, path = nil)
23
+ with_environment do
24
+ # ENV is set within this block
25
+ path = ENV['PATH'] if path.nil?
26
+
27
+ Aruba.platform.which(program, path)
28
+ end
29
+ end
30
+
31
+ # Pipe data in file
32
+ #
33
+ # @param [String] file_name
34
+ # The file which should be used to pipe in data
35
+ def pipe_in_file(file_name)
36
+ file_name = expand_path(file_name)
37
+
38
+ File.open(file_name, 'r').each_line do |line|
39
+ last_command_started.write(line)
40
+ end
41
+ end
42
+
43
+ # Return all commands
44
+ #
45
+ # @return [Array]
46
+ # List of commands
47
+ def all_commands
48
+ aruba.command_monitor.registered_commands
49
+ end
50
+
51
+ # Last command started
52
+ def last_command_started
53
+ aruba.command_monitor.last_command_started
54
+ end
55
+
56
+ # Last command stopped
57
+ def last_command_stopped
58
+ aruba.command_monitor.last_command_stopped
59
+ end
60
+
61
+ # Stop all commands
62
+ #
63
+ # @yield [Command]
64
+ # If block is given use it to filter the commands which should be
65
+ # stoppend.
66
+ def stop_all_commands(&block)
67
+ cmds = if block_given?
68
+ all_commands.select(&block)
69
+ else
70
+ all_commands
71
+ end
72
+
73
+ cmds.each(&:stop)
74
+
75
+ self
76
+ end
77
+
78
+ # Terminate all commands
79
+ #
80
+ # @yield [Command]
81
+ # If block is given use it to filter the commands which should be
82
+ # terminated.
83
+ def terminate_all_commands(&block)
84
+ cmds = if block_given?
85
+ all_commands.select(&block)
86
+ else
87
+ all_commands
88
+ end
89
+
90
+ cmds.each(&:terminate)
91
+
92
+ self
93
+ end
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
+
119
+ # Find a started command
120
+ #
121
+ # @param [String, Command] commandline
122
+ # The commandline
123
+ def find_command(commandline)
124
+ aruba.command_monitor.find(commandline)
125
+ end
126
+
127
+ # Run given command and stop it if timeout is reached
128
+ #
129
+ # @param [String] cmd
130
+ # The command which should be executed
131
+ #
132
+ # @param [Hash] opts
133
+ # Options
134
+ #
135
+ # @option opts [Numeric] exit_timeout
136
+ # If the timeout is reached the command will be killed
137
+ #
138
+ # @option opts [Numeric] io_wait_timeout
139
+ # Wait for IO to finish
140
+ #
141
+ # @option opts [Numeric] startup_wait_time
142
+ # Wait for a command to start
143
+ #
144
+ # @option opts [String] stop_signal
145
+ # Use signal to stop command
146
+ #
147
+ # @yield [SpawnProcess]
148
+ # Run block with process
149
+ #
150
+ def run_command(cmd, opts = {})
151
+ command = prepare_command(cmd, opts)
152
+
153
+ unless command.interactive?
154
+ raise NotImplementedError,
155
+ 'Running interactively is not supported with this process launcher.'
156
+ end
157
+
158
+ start_command(command)
159
+
160
+ block_given? ? yield(command) : command
161
+ end
162
+
163
+ # Run a command with aruba
164
+ #
165
+ # Checks for error during command execution and checks the output to detect
166
+ # an timeout error.
167
+ #
168
+ # @param [String] cmd
169
+ # The command to be executed
170
+ #
171
+ # @param [Hash] opts
172
+ # Options for aruba
173
+ #
174
+ # @option opts [Boolean] :fail_on_error
175
+ # Should aruba fail on error?
176
+ #
177
+ # @option opts [Numeric] :exit_timeout
178
+ # Timeout for execution
179
+ #
180
+ # @option opts [Numeric] :io_wait_timeout
181
+ # Timeout for IO - STDERR, STDOUT
182
+ #
183
+ def run_command_and_stop(cmd, opts = {})
184
+ fail_on_error = if opts.key?(:fail_on_error)
185
+ opts.delete(:fail_on_error) == true
186
+ else
187
+ true
188
+ end
189
+
190
+ command = prepare_command(cmd, opts)
191
+ start_command(command)
192
+ command.stop
193
+
194
+ return unless fail_on_error
195
+
196
+ begin
197
+ expect(command).to have_finished_in_time
198
+ expect(command).to be_successfully_executed
199
+ rescue ::RSpec::Expectations::ExpectationNotMetError => e
200
+ aruba.announcer.activate(aruba.config.activate_announcer_on_command_failure)
201
+ aruba.event_bus.notify Events::CommandStopped.new(command)
202
+ raise e
203
+ end
204
+ end
205
+
206
+ # Provide data to command via stdin
207
+ #
208
+ # @param [String] input
209
+ # The input for the command
210
+ def type(input)
211
+ return close_input if input == "\u0004"
212
+
213
+ last_command_started.write(input << "\n")
214
+ end
215
+
216
+ # Close stdin
217
+ def close_input
218
+ last_command_started.close_io(:stdin)
219
+ end
220
+
221
+ private
222
+
223
+ def prepare_command(cmd, opts)
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
228
+
229
+ cmd = replace_variables(cmd)
230
+
231
+ @commands ||= []
232
+ @commands << cmd
233
+
234
+ environment = aruba.environment
235
+ working_directory = expand_path('.')
236
+ event_bus = aruba.event_bus
237
+
238
+ cmd = Aruba.platform.detect_ruby(cmd)
239
+
240
+ mode = aruba.config.command_launcher
241
+
242
+ main_class = aruba.config.main_class
243
+
244
+ Command.new(
245
+ cmd,
246
+ mode: mode,
247
+ exit_timeout: exit_timeout,
248
+ io_wait_timeout: io_wait_timeout,
249
+ working_directory: working_directory,
250
+ environment: environment.to_hash,
251
+ main_class: main_class,
252
+ stop_signal: stop_signal,
253
+ startup_wait_time: startup_wait_time,
254
+ event_bus: event_bus
255
+ )
256
+ end
257
+
258
+ def start_command(command)
259
+ aruba.config.before(:command, self, command)
260
+
261
+ in_current_directory do
262
+ command.start
263
+ end
264
+
265
+ stop_signal = command.stop_signal
266
+ aruba.announcer.announce(:stop_signal, command.pid, stop_signal) if stop_signal
267
+
268
+ aruba.config.after(:command, self, command)
269
+ end
270
+ end
271
+ end
272
+ end
@@ -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
 
@@ -25,12 +27,21 @@ module Aruba
25
27
  # This will only clean up aruba's working directory to remove all
26
28
  # artifacts of your tests. This does NOT clean up the current working
27
29
  # directory.
28
- def setup_aruba
29
- Aruba::Setup.new(aruba).call
30
+ def setup_aruba(clobber = true)
31
+ Aruba::Setup.new(aruba).call(clobber)
30
32
 
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
  #
@@ -117,48 +135,73 @@ module Aruba
117
135
  # # => <path>/test/fixtures/file
118
136
  # expand_path('%/file')
119
137
  #
120
- # rubocop:disable Metrics/MethodLength
121
- # rubocop:disable Metrics/CyclomaticComplexity
138
+ # @example Absolute directory
139
+ #
140
+ # # => /foo/bar
141
+ # expand_path('/foo/bar')
142
+ #
122
143
  def expand_path(file_name, dir_string = nil)
123
- check_for_deprecated_variables if Aruba::VERSION < '1'
124
-
125
- # rubocop:disable Metrics/LineLength
126
- 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.)
127
- # rubocop:enable Metrics/LineLength
144
+ message = "Filename #{file_name} needs to be a string." \
145
+ ' It cannot be nil or empty either. '\
146
+ "Please use `expand_path('.')` if you want the current directory to be expanded."
128
147
 
129
- fail ArgumentError, message unless file_name.is_a?(String) && !file_name.empty?
148
+ raise ArgumentError, message unless file_name.is_a?(String) && !file_name.empty?
130
149
 
131
- # rubocop:disable Metrics/LineLength
132
- 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)
133
- # rubocop:enable Metrics/LineLength
150
+ unless Aruba.platform.directory? File.join(aruba.config.root_directory,
151
+ aruba.config.working_directory)
152
+ raise "Aruba's working directory does not exist." \
153
+ ' Maybe you forgot to run `setup_aruba` before using its API.'
154
+ end
134
155
 
135
156
  prefix = file_name[0]
136
157
  rest = file_name[2..-1]
137
158
 
138
159
  if aruba.config.fixtures_path_prefix == prefix
139
160
  path = File.join(*[aruba.fixtures_directory, rest].compact)
140
-
141
- # rubocop:disable Metrics/LineLength
142
- 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
143
- # rubocop:enable Metrics/LineLength
161
+ unless Aruba.platform.exist? path
162
+ aruba_fixture_candidates = aruba.config.fixtures_directories
163
+ .map { |p| format('"%s"', p) }.join(', ')
164
+
165
+ raise ArgumentError,
166
+ "Fixture \"#{rest}\" does not exist" \
167
+ " in fixtures directory \"#{aruba.fixtures_directory}\"." \
168
+ ' This was the one we found first on your system from all possible' \
169
+ " candidates: #{aruba_fixture_candidates}."
170
+ end
144
171
 
145
172
  path
146
- elsif '~' == prefix
173
+ elsif prefix == '~'
147
174
  path = with_environment do
148
- ArubaPath.new(File.expand_path(file_name))
175
+ File.expand_path(file_name)
149
176
  end
150
177
 
151
- fail ArgumentError, 'Expanding "~/" to "/" is not allowed' if path.to_s == '/'
152
- fail ArgumentError, %(Expanding "~/" to a relative path "#{path}" is not allowed) unless path.absolute?
178
+ raise ArgumentError, 'Expanding "~/" to "/" is not allowed' if path == '/'
179
+
180
+ unless Aruba.platform.absolute_path? path
181
+ raise ArgumentError,
182
+ "Expanding \"~\" to a relative path \"#{path}\" is not allowed"
183
+ end
153
184
 
154
185
  path.to_s
186
+ elsif absolute?(file_name)
187
+ unless aruba.config.allow_absolute_paths
188
+ caller_location = caller_locations(1, 1).first
189
+ caller_file_line = "#{caller_location.path}:#{caller_location.lineno}"
190
+ aruba.logger.warn \
191
+ "Aruba's `expand_path` method was called with an absolute path" \
192
+ " at #{caller_file_line}, which is not recommended." \
193
+ ' Change the call to pass a relative path or set '\
194
+ '`config.allow_absolute_paths = true` to silence this warning'
195
+ end
196
+ file_name
155
197
  else
156
- directory = File.join(aruba.root_directory, aruba.current_directory)
157
- ArubaPath.new(File.join(*[directory, dir_string, file_name].compact)).expand_path.to_s
198
+ with_environment do
199
+ directory = File.expand_path(aruba.current_directory, aruba.root_directory)
200
+ directory = File.expand_path(dir_string, directory) if dir_string
201
+ File.expand_path(file_name, directory)
202
+ end
158
203
  end
159
204
  end
160
- # rubocop:enable Metrics/MethodLength
161
- # rubocop:enable Metrics/CyclomaticComplexity
162
205
 
163
206
  # Run block with environment
164
207
  #
@@ -168,14 +211,10 @@ module Aruba
168
211
  # @yield
169
212
  # The block of code which should be run with the changed environment variables
170
213
  def with_environment(env = {}, &block)
171
- old_aruba_env = aruba.environment.to_h
172
-
173
- # make sure the old environment is really restored in "ENV"
174
- Aruba.platform.with_environment aruba.environment.update(env).to_h, &block
175
- ensure
176
- # make sure the old environment is really restored in "aruba.environment"
177
- aruba.environment.clear
178
- aruba.environment.update old_aruba_env
214
+ aruba.environment.nest do |nested_env|
215
+ nested_env.update(env)
216
+ Aruba.platform.with_environment nested_env.to_h, &block
217
+ end
179
218
  end
180
219
  end
181
220
  end