aruba 0.7.4 → 0.8.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (141) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.nav +12 -0
  4. data/.rspec +1 -0
  5. data/.rubocop.yml +12 -0
  6. data/.simplecov +2 -0
  7. data/.travis.yml +5 -6
  8. data/Gemfile +53 -26
  9. data/History.md +17 -0
  10. data/LICENSE +1 -1
  11. data/README.md +45 -19
  12. data/Rakefile +12 -2
  13. data/TODO.md +3 -0
  14. data/aruba.gemspec +19 -8
  15. data/cucumber.yml +1 -1
  16. data/features/api/cd.feature +119 -0
  17. data/features/api/command/run.feature +37 -0
  18. data/features/api/command/which.feature +37 -0
  19. data/features/api/environment/append_environment_variable.feature +118 -0
  20. data/features/api/environment/prepend_environment_variable.feature +118 -0
  21. data/features/api/environment/set_environment_variable.feature +252 -0
  22. data/features/configuration/exit_timeout.feature +51 -0
  23. data/features/configuration/fixtures_directories.feature +31 -0
  24. data/features/configuration/fixtures_path_prefix.feature +24 -0
  25. data/features/configuration/io_timeout.feature +31 -0
  26. data/features/configuration/keep_ansi.feature +31 -0
  27. data/features/configuration/root_directory.feature +31 -0
  28. data/features/configuration/working_directory.feature +32 -0
  29. data/features/fixtures/cli-app/.gitignore +9 -0
  30. data/features/fixtures/cli-app/.rspec +2 -0
  31. data/features/fixtures/cli-app/README.md +34 -0
  32. data/features/fixtures/cli-app/Rakefile +1 -0
  33. data/features/fixtures/cli-app/bin/cli +6 -0
  34. data/features/fixtures/cli-app/cli-app.gemspec +26 -0
  35. data/features/fixtures/cli-app/features/support/env.rb +1 -0
  36. data/features/fixtures/cli-app/lib/cli/app.rb +13 -0
  37. data/features/fixtures/cli-app/lib/cli/app/version.rb +5 -0
  38. data/features/fixtures/cli-app/script/console +14 -0
  39. data/features/fixtures/cli-app/spec/cli/app_spec.rb +7 -0
  40. data/features/fixtures/cli-app/spec/spec_helper.rb +10 -0
  41. data/features/fixtures/copy/file.txt +1 -1
  42. data/features/hooks/after/command.feature +34 -0
  43. data/features/hooks/before/command.feature +61 -0
  44. data/features/matchers/directory/have_sub_directory.feature +110 -0
  45. data/features/matchers/file/be_existing_file.feature +82 -0
  46. data/features/matchers/file/have_file_content.feature +123 -0
  47. data/features/matchers/file/have_file_size.feature +107 -0
  48. data/features/matchers/path/be_an_absolute_path.feature +74 -0
  49. data/features/matchers/path/be_an_existing_path.feature +97 -0
  50. data/features/matchers/path/have_permissions.feature +118 -0
  51. data/features/matchers/timeouts.feature +48 -0
  52. data/features/step_definitions/aruba_dev_steps.rb +69 -1
  53. data/features/steps/commands/exit_statuses.feature +136 -0
  54. data/features/steps/commands/in_process.feature +129 -0
  55. data/features/steps/commands/run.feature +36 -0
  56. data/features/steps/environment/home_variable.feature +49 -0
  57. data/features/steps/environment/set_environment_variable.feature +34 -0
  58. data/features/support/aruba.rb +5 -0
  59. data/features/support/env.rb +8 -4
  60. data/lib/aruba.rb +20 -8
  61. data/lib/aruba/announcer.rb +1 -0
  62. data/lib/aruba/api.rb +18 -1179
  63. data/lib/aruba/api/command.rb +351 -0
  64. data/lib/aruba/api/core.rb +141 -0
  65. data/lib/aruba/api/deprecated.rb +549 -0
  66. data/lib/aruba/api/environment.rb +61 -0
  67. data/lib/aruba/api/filesystem.rb +305 -0
  68. data/lib/aruba/api/rvm.rb +39 -0
  69. data/lib/aruba/aruba_path.rb +75 -0
  70. data/lib/aruba/basic_configuration.rb +208 -0
  71. data/lib/aruba/basic_configuration/option.rb +25 -0
  72. data/lib/aruba/config.rb +43 -30
  73. data/lib/aruba/config/jruby.rb +14 -0
  74. data/lib/aruba/config_wrapper.rb +17 -0
  75. data/lib/aruba/contracts/relative_path.rb +13 -0
  76. data/lib/aruba/creators/aruba_file_creator.rb +32 -0
  77. data/lib/aruba/creators/aruba_fixed_size_file_creator.rb +32 -0
  78. data/lib/aruba/cucumber.rb +87 -53
  79. data/lib/aruba/cucumber/hooks.rb +65 -10
  80. data/lib/aruba/environment.rb +121 -0
  81. data/lib/aruba/errors.rb +3 -0
  82. data/lib/aruba/extensions/string/strip.rb +24 -0
  83. data/lib/aruba/hooks.rb +54 -0
  84. data/lib/aruba/jruby.rb +4 -9
  85. data/lib/aruba/matchers/command.rb +1 -79
  86. data/lib/aruba/matchers/command/be_successfully_executed.rb +30 -0
  87. data/lib/aruba/matchers/command/have_exit_status.rb +47 -0
  88. data/lib/aruba/matchers/command/have_finished_in_time.rb +42 -0
  89. data/lib/aruba/matchers/directory.rb +1 -59
  90. data/lib/aruba/matchers/directory/be_an_existing_directory.rb +34 -0
  91. data/lib/aruba/matchers/directory/have_sub_directory.rb +49 -0
  92. data/lib/aruba/matchers/file.rb +1 -177
  93. data/lib/aruba/matchers/file/be_an_existing_file.rb +34 -0
  94. data/lib/aruba/matchers/file/have_file_content.rb +58 -0
  95. data/lib/aruba/matchers/file/have_file_size.rb +43 -0
  96. data/lib/aruba/matchers/file/have_same_file_content.rb +44 -0
  97. data/lib/aruba/matchers/path.rb +1 -99
  98. data/lib/aruba/matchers/path/a_path_matching_pattern.rb +21 -0
  99. data/lib/aruba/matchers/path/be_an_absolute_path.rb +32 -0
  100. data/lib/aruba/matchers/path/be_an_existing_path.rb +33 -0
  101. data/lib/aruba/matchers/path/have_permissions.rb +60 -0
  102. data/lib/aruba/matchers/path/match_path_pattern.rb +41 -0
  103. data/lib/aruba/matchers/rspec.rb +0 -0
  104. data/lib/aruba/matchers/rspec_matcher_include_regexp.rb +1 -1
  105. data/lib/aruba/platform.rb +230 -0
  106. data/lib/aruba/process_monitor.rb +23 -5
  107. data/lib/aruba/processes/basic_process.rb +35 -1
  108. data/lib/aruba/processes/debug_process.rb +26 -15
  109. data/lib/aruba/processes/in_process.rb +21 -9
  110. data/lib/aruba/processes/spawn_process.rb +29 -19
  111. data/lib/aruba/reporting.rb +2 -0
  112. data/lib/aruba/rspec.rb +61 -13
  113. data/lib/aruba/runtime.rb +33 -0
  114. data/script/bootstrap +4 -6
  115. data/spec/aruba/api/runtime_spec.rb +28 -0
  116. data/spec/aruba/api_spec.rb +129 -126
  117. data/spec/aruba/aruba_path_spec.rb +65 -0
  118. data/spec/aruba/basic_configuration_spec.rb +5 -0
  119. data/spec/aruba/config_wrapper_spec.rb +25 -0
  120. data/spec/aruba/configuration_spec.rb +5 -0
  121. data/spec/aruba/jruby_spec.rb +34 -18
  122. data/spec/aruba/matchers/directory_spec.rb +6 -7
  123. data/spec/aruba/matchers/file_spec.rb +16 -20
  124. data/spec/aruba/matchers/path_spec.rb +14 -11
  125. data/spec/aruba/rspec_spec.rb +15 -0
  126. data/spec/aruba/runtime_spec.rb +29 -0
  127. data/spec/aruba/spawn_process_spec.rb +2 -2
  128. data/spec/spec_helper.rb +10 -2
  129. data/spec/support/configs/rspec.rb +1 -1
  130. data/spec/support/matchers/option.rb +35 -0
  131. data/spec/support/shared_contexts/aruba.rb +10 -8
  132. data/spec/support/shared_examples/configuration.rb +116 -0
  133. metadata +182 -33
  134. data/.rvmrc +0 -1
  135. data/features/before_cmd_hooks.feature +0 -61
  136. data/features/command_environment_variables.feature +0 -31
  137. data/features/custom_ruby_process.feature +0 -12
  138. data/features/exit_statuses.feature +0 -30
  139. data/features/support/custom_main.rb +0 -28
  140. data/lib/aruba/matchers/mode.rb +0 -52
  141. data/lib/aruba/utils.rb +0 -21
@@ -0,0 +1,351 @@
1
+ require 'pathname'
2
+
3
+ require 'aruba/platform'
4
+ require 'aruba/process_monitor'
5
+ require 'aruba/spawn_process'
6
+
7
+ require 'win32/file' if File::ALT_SEPARATOR
8
+
9
+ module Aruba
10
+ class << self
11
+ attr_accessor :process
12
+ end
13
+
14
+ self.process = Aruba::Processes::SpawnProcess
15
+ end
16
+
17
+ module Aruba
18
+ module Api
19
+ module Commands
20
+ # Resolve path for command using the PATH-environment variable
21
+ #
22
+ # @param [#to_s] program
23
+ # The name of the program which should be resolved
24
+ #
25
+ # @param [String] path
26
+ # The PATH, a string concatenated with ":", e.g. /usr/bin/:/bin on a
27
+ # UNIX-system
28
+ def which(program, path = ENV['PATH'])
29
+ Aruba::Platform.which(program, path)
30
+ end
31
+
32
+ # Pipe data in file
33
+ #
34
+ # @param [String] file_name
35
+ # The file which should be used to pipe in data
36
+ def pipe_in_file(file_name)
37
+ file_name = expand_path(file_name)
38
+
39
+ File.open(file_name, 'r').each_line do |line|
40
+ last_command.write(line)
41
+ end
42
+ end
43
+
44
+ # Fetch output (stdout, stderr) from command
45
+ #
46
+ # @param [String] cmd
47
+ # The command
48
+ def output_from(cmd)
49
+ process_monitor.output_from(cmd)
50
+ end
51
+
52
+ # Fetch stdout from command
53
+ #
54
+ # @param [String] cmd
55
+ # The command
56
+ def stdout_from(cmd)
57
+ process_monitor.stdout_from(cmd)
58
+ end
59
+
60
+ # Fetch stderr from command
61
+ #
62
+ # @param [String] cmd
63
+ # The command
64
+ def stderr_from(cmd)
65
+ process_monitor.stderr_from(cmd)
66
+ end
67
+
68
+ # Get stdout of all processes
69
+ #
70
+ # @return [String]
71
+ # The stdout of all process which have run before
72
+ def all_stdout
73
+ process_monitor.all_stdout
74
+ end
75
+
76
+ # Get stderr of all processes
77
+ #
78
+ # @return [String]
79
+ # The stderr of all process which have run before
80
+ def all_stderr
81
+ process_monitor.all_stderr
82
+ end
83
+
84
+ # Get stderr and stdout of all processes
85
+ #
86
+ # @return [String]
87
+ # The stderr and stdout of all process which have run before
88
+ def all_output
89
+ process_monitor.all_output
90
+ end
91
+
92
+ # Full compare arg1 and arg2
93
+ #
94
+ # @return [TrueClass, FalseClass]
95
+ # If arg1 is exactly the same as arg2 return true, otherwise false
96
+ def assert_exact_output(expected, actual)
97
+ actual.force_encoding(expected.encoding) if RUBY_VERSION >= "1.9"
98
+ expect(Aruba::Platform.unescape(actual, aruba.config.keep_ansi)).to eq Aruba::Platform.unescape(expected, aruba.config.keep_ansi)
99
+ end
100
+
101
+ # Partial compare arg1 and arg2
102
+ #
103
+ # @return [TrueClass, FalseClass]
104
+ # If arg2 contains arg1 return true, otherwise false
105
+ def assert_partial_output(expected, actual)
106
+ actual.force_encoding(expected.encoding) if RUBY_VERSION >= "1.9"
107
+ expect(Aruba::Platform.unescape(actual, aruba.config.keep_ansi)).to include(Aruba::Platform.unescape(expected, aruba.config.keep_ansi))
108
+ end
109
+
110
+ # Regex Compare arg1 and arg2
111
+ #
112
+ # @return [TrueClass, FalseClass]
113
+ # If arg2 matches arg1 return true, otherwise false
114
+ def assert_matching_output(expected, actual)
115
+ actual.force_encoding(expected.encoding) if RUBY_VERSION >= "1.9"
116
+ expect(Aruba::Platform.unescape(actual, aruba.config.keep_ansi)).to match(/#{Aruba::Platform.unescape(expected, aruba.config.keep_ansi)}/m)
117
+ end
118
+
119
+ # Negative regex compare arg1 and arg2
120
+ #
121
+ # @return [TrueClass, FalseClass]
122
+ # If arg2 does not match arg1 return true, otherwise false
123
+ def assert_not_matching_output(expected, actual)
124
+ actual.force_encoding(expected.encoding) if RUBY_VERSION >= "1.9"
125
+ expect(Aruba::Platform.unescape(actual, aruba.config.keep_ansi)).not_to match(/#{Aruba::Platform.unescape(expected, aruba.config.keep_ansi)}/m)
126
+ end
127
+
128
+ # Negative partial compare arg1 and arg2
129
+ #
130
+ # @return [TrueClass, FalseClass]
131
+ # If arg2 does not match/include arg1 return true, otherwise false
132
+ def assert_no_partial_output(unexpected, actual)
133
+ actual.force_encoding(unexpected.encoding) if RUBY_VERSION >= "1.9"
134
+ if Regexp === unexpected
135
+ expect(Aruba::Platform.unescape(actual, aruba.config.keep_ansi)).not_to match unexpected
136
+ else
137
+ expect(Aruba::Platform.unescape(actual, aruba.config.keep_ansi)).not_to include(unexpected)
138
+ end
139
+ end
140
+
141
+ # Partial compare output of interactive command and arg1
142
+ #
143
+ # @return [TrueClass, FalseClass]
144
+ # If output of interactive command includes arg1 return true, otherwise false
145
+ def assert_partial_output_interactive(expected)
146
+ Aruba::Platform.unescape(last_command.stdout, aruba.config.keep_ansi).include?(Aruba::Platform.unescape(expected, aruba.config.keep_ansi)) ? true : false
147
+ end
148
+
149
+ # Check if command succeeded and if arg1 is included in output
150
+ #
151
+ # @return [TrueClass, FalseClass]
152
+ # If exit status is 0 and arg1 is included in output return true, otherwise false
153
+ def assert_passing_with(expected)
154
+ assert_success(true)
155
+ assert_partial_output(expected, all_output)
156
+ end
157
+
158
+ # Check if command failed and if arg1 is included in output
159
+ #
160
+ # @return [TrueClass, FalseClass]
161
+ # If exit status is not equal 0 and arg1 is included in output return true, otherwise false
162
+ def assert_failing_with(expected)
163
+ assert_success(false)
164
+ assert_partial_output(expected, all_output)
165
+ end
166
+
167
+ # Check exit status of process
168
+ #
169
+ # @return [TrueClass, FalseClass]
170
+ # If arg1 is true, return true if command was successful
171
+ # If arg1 is false, return true if command failed
172
+ def assert_success(success)
173
+ if success
174
+ expect(last_command).to be_successfully_executed
175
+ else
176
+ expect(last_command).not_to be_successfully_executed
177
+ end
178
+ end
179
+
180
+ # @private
181
+ def assert_exit_status(status)
182
+ expect(last_command).to have_exit_status(status)
183
+ end
184
+
185
+ # @private
186
+ def assert_not_exit_status(status)
187
+ expect(last_exit_status).not_to eq(status),
188
+ append_output_to("Exit status was #{last_exit_status} which was not expected.")
189
+ end
190
+
191
+ # @private
192
+ def append_output_to(message)
193
+ "#{message} Output:\n\n#{all_output}\n"
194
+ end
195
+
196
+ def process_monitor
197
+ return @process_monitor if defined? @process_monitor
198
+
199
+ @process_monitor = ProcessMonitor.new(announcer)
200
+
201
+ @process_monitor
202
+ end
203
+
204
+ # @private
205
+ def processes
206
+ process_monitor.send(:processes)
207
+ end
208
+
209
+ # @private
210
+ def stop_processes!
211
+ process_monitor.stop_processes!
212
+ end
213
+
214
+ # Terminate all running processes
215
+ def terminate_processes!
216
+ process_monitor.terminate_processes!
217
+ end
218
+
219
+ # @private
220
+ def last_command
221
+ processes.last[1]
222
+ end
223
+
224
+ # @private
225
+ def register_process(*args)
226
+ process_monitor.register_process(*args)
227
+ end
228
+
229
+ # @private
230
+ def get_process(wanted)
231
+ process_monitor.get_process(wanted)
232
+ end
233
+
234
+ # Run given command and stop it if timeout is reached
235
+ #
236
+ # @param [String] cmd
237
+ # The command which should be executed
238
+ #
239
+ # @param [Integer] timeout
240
+ # If the timeout is reached the command will be killed
241
+ #
242
+ # @yield [SpawnProcess]
243
+ # Run block with process
244
+ def run(cmd, timeout = nil)
245
+ timeout ||= exit_timeout
246
+ @commands ||= []
247
+ @commands << cmd
248
+
249
+ cmd = Aruba::Platform.detect_ruby(cmd)
250
+
251
+ announcer.announce(:directory, Dir.pwd)
252
+ announcer.announce(:command, cmd)
253
+ announcer.announce(:timeout, 'exit', aruba.config.exit_timeout)
254
+
255
+ process = Aruba.process.new(cmd, timeout, io_wait, expand_path('.'), aruba.environment.to_h)
256
+
257
+ if aruba.config.before? :cmd
258
+ # rubocop:disable Metrics/LineLength
259
+ Aruba::Platform.deprecated('The use of "before"-hook" ":cmd" is deprecated. Use ":command" instead. Please be aware that this hook gets the command passed in not the cmdline itself. To get the commandline use "#cmd.commandline"')
260
+ # rubocop:enable Metrics/LineLength
261
+ aruba.config.before(:cmd, self, cmd)
262
+ end
263
+
264
+ aruba.config.before(:command, self, process)
265
+
266
+ process_monitor.register_process(cmd, process)
267
+ process.run!
268
+
269
+ aruba.config.after(:command, self, process)
270
+
271
+ block_given? ? yield(process) : process
272
+ end
273
+
274
+ # Default exit timeout for running commands with aruba
275
+ #
276
+ # Overwrite this method if you want a different timeout or set
277
+ # `@aruba_timeout_seconds`.
278
+ def exit_timeout
279
+ aruba.config.exit_timeout
280
+ end
281
+
282
+ # Default io wait timeout
283
+ #
284
+ # Overwrite this method if you want a different timeout or set
285
+ # `@aruba_io_wait_seconds
286
+ def io_wait
287
+ aruba.config.io_wait_timeout
288
+ end
289
+
290
+ # The root directory of aruba
291
+ def root_directory
292
+ aruba.config.root_directory
293
+ end
294
+
295
+ # Run a command with aruba
296
+ #
297
+ # Checks for error during command execution and checks the output to detect
298
+ # an timeout error.
299
+ #
300
+ # @param [String] cmd
301
+ # The command to be executed
302
+ #
303
+ # @param [TrueClass,FalseClass] fail_on_error
304
+ # Should aruba fail on error?
305
+ #
306
+ # @param [Integer] timeout
307
+ # Timeout for execution
308
+ def run_simple(cmd, fail_on_error = true, timeout = nil)
309
+ command = run(cmd, timeout)
310
+ @last_exit_status = command.stop(announcer)
311
+
312
+ @timed_out = command.timed_out?
313
+
314
+ if fail_on_error
315
+ expect(command).to have_finished_in_time
316
+ expect(command).to be_successfully_executed
317
+ end
318
+ end
319
+
320
+ # Provide data to command via stdin
321
+ #
322
+ # @param [String] input
323
+ # The input for the command
324
+ def type(input)
325
+ return close_input if "" == input
326
+ last_command.write(input << "\n")
327
+ end
328
+
329
+ # Close stdin
330
+ def close_input
331
+ last_command.close_io(:stdin)
332
+ end
333
+
334
+ # TODO: move some more methods under here!
335
+
336
+ private
337
+
338
+ def last_exit_status
339
+ process_monitor.last_exit_status
340
+ end
341
+
342
+ def stop_process(process)
343
+ process_monitor.stop_process(process)
344
+ end
345
+
346
+ def terminate_process(process)
347
+ process_monitor.terminate_process(process)
348
+ end
349
+ end
350
+ end
351
+ end
@@ -0,0 +1,141 @@
1
+ require 'rspec/expectations'
2
+ require 'aruba/announcer'
3
+ require 'aruba/runtime'
4
+ require 'aruba/errors'
5
+
6
+ require 'aruba/config/jruby'
7
+
8
+ module Aruba
9
+ module Api
10
+ module Core
11
+ include ::RSpec::Matchers
12
+
13
+ # Aruba Runtime
14
+ def aruba
15
+ @_aruba_runtime ||= Runtime.new
16
+ end
17
+
18
+ # Clean the working directory of aruba
19
+ #
20
+ # This will only clean up aruba's working directory to remove all
21
+ # artifacts of your tests. This does NOT clean up the current working
22
+ # directory.
23
+ def setup_aruba
24
+ Aruba::Platform.rm File.join(Aruba.config.root_directory, Aruba.config.working_directory), :force => true
25
+ Aruba::Platform.mkdir File.join(Aruba.config.root_directory, Aruba.config.working_directory)
26
+ Aruba::Platform.chdir Aruba.config.root_directory
27
+
28
+ self
29
+ end
30
+
31
+ # Switch to directory
32
+ #
33
+ # @param [String] dir
34
+ # The directory
35
+ #
36
+ # @example Normal directory
37
+ # cd 'dir'
38
+ #
39
+ # @example Move up
40
+ # cd '..'
41
+ #
42
+ # @example Run code in directory
43
+ # result = cd('some-dir') { Dir.getwd }
44
+ #
45
+ def cd(dir, &block)
46
+ fail ArgumentError, "#{expand_path(dir)} is not a directory or does not exist." unless directory?(dir)
47
+
48
+ if block_given?
49
+ cwd = (aruba.current_directory.dup << dir)
50
+ return Aruba::Platform.chdir(cwd, &block)
51
+ end
52
+
53
+ aruba.current_directory << dir
54
+
55
+ self
56
+ end
57
+
58
+ # Expand file name
59
+ #
60
+ # @param [String] file_name
61
+ # Name of file
62
+ #
63
+ # @param [String] dir_string
64
+ # Name of directory to use as starting point, otherwise current directory is used.
65
+ #
66
+ # @return [String]
67
+ # The full path
68
+ #
69
+ # @example Single file name
70
+ #
71
+ # # => <path>/tmp/aruba/file
72
+ # expand_path('file')
73
+ #
74
+ # @example Single Dot
75
+ #
76
+ # # => <path>/tmp/aruba
77
+ # expand_path('.')
78
+ #
79
+ # @example using home directory
80
+ #
81
+ # # => <path>/home/<name>/file
82
+ # expand_path('~/file')
83
+ #
84
+ # @example using fixtures directory
85
+ #
86
+ # # => <path>/test/fixtures/file
87
+ # expand_path('%/file')
88
+ #
89
+ def expand_path(file_name, dir_string = nil)
90
+ # rubocop:disable Metrics/LineLength
91
+ 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.)
92
+ # rubocop:enable Metrics/LineLength
93
+
94
+ fail ArgumentError, message unless file_name.is_a?(String) && !file_name.empty?
95
+
96
+ if RUBY_VERSION < '1.9'
97
+ prefix = file_name.chars.to_a[0]
98
+ rest = file_name.chars.to_a[1..-1].join('')
99
+ else
100
+ prefix = file_name[0]
101
+ rest = file_name[1..-1]
102
+ end
103
+
104
+ if aruba.config.fixtures_path_prefix == prefix
105
+ File.join aruba.fixtures_directory, rest
106
+ else
107
+ with_environment do
108
+ Aruba::Platform.chdir(aruba.current_directory) { Aruba::Platform.expand_path(file_name, dir_string) }
109
+ end
110
+ end
111
+ end
112
+
113
+ # Run block with environment
114
+ #
115
+ # @param [Hash] env (optional)
116
+ # The variables to be used for block.
117
+ #
118
+ # @yield
119
+ # The block of code which should be run with the modified environment variables
120
+ def with_environment(env = {}, &block)
121
+ if RUBY_VERSION <= '1.9.3'
122
+ old_env = ENV.to_hash
123
+ else
124
+ old_env = ENV.to_h
125
+ end
126
+
127
+ old_aruba_env = aruba.environment.to_h
128
+
129
+ ENV.update aruba.environment.update(env).to_h
130
+
131
+ block.call if block_given?
132
+ ensure
133
+ aruba.environment.clear
134
+ aruba.environment.update old_aruba_env
135
+
136
+ ENV.clear
137
+ ENV.update old_env
138
+ end
139
+ end
140
+ end
141
+ end