aruba 1.0.0.pre.alpha.5 → 1.0.4
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +153 -28
- data/CONTRIBUTING.md +0 -9
- data/LICENSE +1 -1
- data/README.md +37 -30
- data/lib/aruba/api.rb +0 -1
- data/lib/aruba/api/bundler.rb +17 -2
- data/lib/aruba/api/commands.rb +15 -16
- data/lib/aruba/api/core.rb +64 -50
- data/lib/aruba/api/environment.rb +12 -4
- data/lib/aruba/api/filesystem.rb +32 -46
- data/lib/aruba/api/text.rb +15 -3
- data/lib/aruba/aruba_path.rb +23 -95
- data/lib/aruba/basic_configuration.rb +46 -65
- data/lib/aruba/basic_configuration/option.rb +2 -2
- data/lib/aruba/cli.rb +4 -1
- data/lib/aruba/config/jruby.rb +1 -1
- data/lib/aruba/config_wrapper.rb +17 -4
- data/lib/aruba/configuration.rb +29 -22
- data/lib/aruba/console.rb +0 -2
- data/lib/aruba/console/help.rb +8 -5
- data/lib/aruba/contracts/absolute_path.rb +3 -3
- data/lib/aruba/contracts/is_power_of_two.rb +2 -2
- data/lib/aruba/contracts/relative_path.rb +3 -3
- data/lib/aruba/cucumber/command.rb +93 -82
- data/lib/aruba/cucumber/file.rb +43 -23
- data/lib/aruba/cucumber/hooks.rb +4 -1
- data/lib/aruba/cucumber/testing_frameworks.rb +14 -12
- data/lib/aruba/event_bus.rb +4 -2
- data/lib/aruba/event_bus/name_resolver.rb +9 -8
- data/lib/aruba/events.rb +2 -1
- data/lib/aruba/hooks.rb +2 -4
- data/lib/aruba/in_config_wrapper.rb +8 -5
- data/lib/aruba/initializer.rb +9 -3
- data/lib/aruba/matchers/base/base_matcher.rb +2 -11
- data/lib/aruba/matchers/base/message_indenter.rb +1 -1
- data/lib/aruba/matchers/base/object_formatter.rb +0 -5
- data/lib/aruba/matchers/collection/include_an_object.rb +4 -4
- data/lib/aruba/matchers/command/be_successfully_executed.rb +3 -1
- data/lib/aruba/matchers/command/have_exit_status.rb +3 -1
- data/lib/aruba/matchers/command/have_finished_in_time.rb +3 -1
- data/lib/aruba/matchers/command/have_output.rb +3 -1
- data/lib/aruba/matchers/command/have_output_on_stderr.rb +3 -1
- data/lib/aruba/matchers/command/have_output_on_stdout.rb +3 -1
- data/lib/aruba/matchers/directory/have_sub_directory.rb +8 -3
- data/lib/aruba/matchers/file/have_file_size.rb +4 -2
- data/lib/aruba/matchers/path/have_permissions.rb +7 -4
- data/lib/aruba/platforms/announcer.rb +25 -11
- data/lib/aruba/platforms/aruba_file_creator.rb +3 -1
- data/lib/aruba/platforms/aruba_fixed_size_file_creator.rb +7 -2
- data/lib/aruba/platforms/aruba_logger.rb +10 -9
- data/lib/aruba/platforms/command_monitor.rb +4 -6
- data/lib/aruba/platforms/determine_disk_usage.rb +55 -20
- data/lib/aruba/platforms/filesystem_status.rb +19 -13
- data/lib/aruba/platforms/simple_table.rb +2 -2
- data/lib/aruba/platforms/unix_environment_variables.rb +9 -4
- data/lib/aruba/platforms/unix_platform.rb +10 -10
- data/lib/aruba/platforms/unix_which.rb +1 -1
- data/lib/aruba/platforms/windows_command_string.rb +1 -1
- data/lib/aruba/platforms/windows_environment_variables.rb +2 -1
- data/lib/aruba/platforms/windows_platform.rb +3 -3
- data/lib/aruba/platforms/windows_which.rb +6 -2
- data/lib/aruba/processes/basic_process.rb +4 -6
- data/lib/aruba/processes/debug_process.rb +4 -2
- data/lib/aruba/processes/in_process.rb +5 -3
- data/lib/aruba/processes/spawn_process.rb +27 -16
- data/lib/aruba/rspec.rb +25 -15
- data/lib/aruba/runtime.rb +11 -4
- data/lib/aruba/setup.rb +23 -10
- data/lib/aruba/tasks/docker_helpers.rb +3 -1
- data/lib/aruba/version.rb +1 -1
- metadata +96 -109
- data/.cucumberproignore +0 -3
- data/.document +0 -5
- data/.github/ISSUE_TEMPLATE.md +0 -48
- data/.github/PULL_REQUEST_TEMPLATE.md +0 -41
- data/.gitignore +0 -38
- data/.rspec +0 -3
- data/.rubocop.yml +0 -31
- data/.rubocop_todo.yml +0 -258
- data/.simplecov +0 -34
- data/.travis.yml +0 -73
- data/.yardopts +0 -11
- data/Dockerfile +0 -67
- data/Gemfile +0 -15
- data/Rakefile +0 -92
- data/TODO.md +0 -13
- data/appveyor.yml +0 -30
- data/aruba.gemspec +0 -46
- data/bin/console +0 -7
- data/bin/test +0 -9
- data/config/.gitignore +0 -1
- data/cucumber.yml +0 -6
- data/docker-compose.yml +0 -26
- data/fixtures/cli-app/.gitignore +0 -9
- data/fixtures/cli-app/.rspec +0 -2
- data/fixtures/cli-app/README.md +0 -39
- data/fixtures/cli-app/Rakefile +0 -1
- data/fixtures/cli-app/bin/aruba-test-cli +0 -6
- data/fixtures/cli-app/cli-app.gemspec +0 -25
- data/fixtures/cli-app/features/support/aruba.rb +0 -1
- data/fixtures/cli-app/features/support/env.rb +0 -1
- data/fixtures/cli-app/lib/cli/app.rb +0 -9
- data/fixtures/cli-app/lib/cli/app/suppress_simple_cov_output.rb +0 -15
- data/fixtures/cli-app/lib/cli/app/version.rb +0 -5
- data/fixtures/cli-app/script/console +0 -14
- data/fixtures/cli-app/spec/spec_helper.rb +0 -7
- data/fixtures/cli-app/spec/support/aruba.rb +0 -1
- data/fixtures/copy/file.txt +0 -1
- data/fixtures/empty-app/.gitignore +0 -9
- data/fixtures/empty-app/.rspec +0 -2
- data/fixtures/empty-app/README.md +0 -24
- data/fixtures/empty-app/Rakefile +0 -1
- data/fixtures/empty-app/cli-app.gemspec +0 -25
- data/fixtures/empty-app/lib/cli/app.rb +0 -7
- data/fixtures/empty-app/lib/cli/app/version.rb +0 -5
- data/fixtures/getting-started-app/.gitignore +0 -4
- data/fixtures/getting-started-app/Gemfile +0 -4
- data/fixtures/getting-started-app/README.md +0 -3
- data/fixtures/getting-started-app/features/support/env.rb +0 -1
- data/lib/aruba/extensions/string/strip.rb +0 -25
- data/lib/aruba/platforms/disk_usage_calculator.rb +0 -20
data/lib/aruba/api.rb
CHANGED
data/lib/aruba/api/bundler.rb
CHANGED
|
@@ -7,8 +7,23 @@ module Aruba
|
|
|
7
7
|
|
|
8
8
|
# Unset variables used by bundler
|
|
9
9
|
def unset_bundler_env_vars
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
empty_env = with_environment { with_unbundled_env { ENV.to_h } }
|
|
11
|
+
aruba_env = aruba.environment.to_h
|
|
12
|
+
(aruba_env.keys - empty_env.keys).each do |key|
|
|
13
|
+
delete_environment_variable key
|
|
14
|
+
end
|
|
15
|
+
empty_env.each do |k, v|
|
|
16
|
+
set_environment_variable k, v
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
private
|
|
21
|
+
|
|
22
|
+
def with_unbundled_env(&block)
|
|
23
|
+
if ::Bundler.respond_to?(:with_unbundled_env)
|
|
24
|
+
::Bundler.with_unbundled_env(&block)
|
|
25
|
+
else
|
|
26
|
+
::Bundler.with_clean_env(&block)
|
|
12
27
|
end
|
|
13
28
|
end
|
|
14
29
|
end
|
data/lib/aruba/api/commands.rb
CHANGED
|
@@ -64,7 +64,7 @@ module Aruba
|
|
|
64
64
|
# If block is given use it to filter the commands which should be
|
|
65
65
|
# stoppend.
|
|
66
66
|
def stop_all_commands(&block)
|
|
67
|
-
cmds = if
|
|
67
|
+
cmds = if block
|
|
68
68
|
all_commands.select(&block)
|
|
69
69
|
else
|
|
70
70
|
all_commands
|
|
@@ -81,7 +81,7 @@ module Aruba
|
|
|
81
81
|
# If block is given use it to filter the commands which should be
|
|
82
82
|
# terminated.
|
|
83
83
|
def terminate_all_commands(&block)
|
|
84
|
-
cmds = if
|
|
84
|
+
cmds = if block
|
|
85
85
|
all_commands.select(&block)
|
|
86
86
|
else
|
|
87
87
|
all_commands
|
|
@@ -168,16 +168,16 @@ module Aruba
|
|
|
168
168
|
# @param [String] cmd
|
|
169
169
|
# The command to be executed
|
|
170
170
|
#
|
|
171
|
-
# @param [Hash]
|
|
171
|
+
# @param [Hash] opts
|
|
172
172
|
# Options for aruba
|
|
173
173
|
#
|
|
174
|
-
# @option
|
|
174
|
+
# @option opts [Boolean] :fail_on_error
|
|
175
175
|
# Should aruba fail on error?
|
|
176
176
|
#
|
|
177
|
-
# @option
|
|
177
|
+
# @option opts [Numeric] :exit_timeout
|
|
178
178
|
# Timeout for execution
|
|
179
179
|
#
|
|
180
|
-
# @option
|
|
180
|
+
# @option opts [Numeric] :io_wait_timeout
|
|
181
181
|
# Timeout for IO - STDERR, STDOUT
|
|
182
182
|
#
|
|
183
183
|
def run_command_and_stop(cmd, opts = {})
|
|
@@ -220,12 +220,11 @@ module Aruba
|
|
|
220
220
|
|
|
221
221
|
private
|
|
222
222
|
|
|
223
|
-
# rubocop:disable Metrics/MethodLength
|
|
224
223
|
def prepare_command(cmd, opts)
|
|
225
|
-
exit_timeout = opts[:exit_timeout]
|
|
226
|
-
io_wait_timeout = opts[:io_wait_timeout]
|
|
227
|
-
stop_signal = opts[:stop_signal]
|
|
228
|
-
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
|
|
229
228
|
|
|
230
229
|
cmd = replace_variables(cmd)
|
|
231
230
|
|
|
@@ -256,17 +255,17 @@ module Aruba
|
|
|
256
255
|
)
|
|
257
256
|
end
|
|
258
257
|
|
|
259
|
-
# rubocop:enable Metrics/MethodLength
|
|
260
|
-
|
|
261
258
|
def start_command(command)
|
|
262
|
-
aruba.config.
|
|
259
|
+
aruba.config.run_before_hook(:command, self, command)
|
|
263
260
|
|
|
264
|
-
|
|
261
|
+
in_current_directory do
|
|
262
|
+
command.start
|
|
263
|
+
end
|
|
265
264
|
|
|
266
265
|
stop_signal = command.stop_signal
|
|
267
266
|
aruba.announcer.announce(:stop_signal, command.pid, stop_signal) if stop_signal
|
|
268
267
|
|
|
269
|
-
aruba.config.
|
|
268
|
+
aruba.config.run_after_hook(:command, self, command)
|
|
270
269
|
end
|
|
271
270
|
end
|
|
272
271
|
end
|
data/lib/aruba/api/core.rb
CHANGED
|
@@ -15,8 +15,10 @@ module Aruba
|
|
|
15
15
|
|
|
16
16
|
# Aruba Runtime
|
|
17
17
|
def aruba
|
|
18
|
-
# TODO: Check this variable being accessed inconsistently. Should only
|
|
19
|
-
#
|
|
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
|
|
|
@@ -54,27 +56,30 @@ module Aruba
|
|
|
54
56
|
# @example Run code in directory
|
|
55
57
|
# result = cd('some-dir') { Dir.getwd }
|
|
56
58
|
#
|
|
57
|
-
# rubocop:disable Metrics/MethodLength
|
|
58
59
|
def cd(dir, &block)
|
|
59
|
-
if
|
|
60
|
+
if block
|
|
60
61
|
begin
|
|
61
|
-
unless Aruba.platform.directory?
|
|
62
|
-
|
|
62
|
+
unless Aruba.platform.directory?(expand_path(dir))
|
|
63
|
+
raise ArgumentError,
|
|
64
|
+
"#{expand_path(dir)} is not a directory or does not exist."
|
|
63
65
|
end
|
|
64
66
|
|
|
65
67
|
old_directory = expand_path('.')
|
|
66
68
|
aruba.current_directory << dir
|
|
67
69
|
new_directory = expand_path('.')
|
|
68
70
|
|
|
69
|
-
aruba.event_bus.notify Events::ChangedWorkingDirectory.new(old: old_directory,
|
|
71
|
+
aruba.event_bus.notify Events::ChangedWorkingDirectory.new(old: old_directory,
|
|
72
|
+
new: new_directory)
|
|
70
73
|
|
|
71
74
|
old_dir = Aruba.platform.getwd
|
|
72
75
|
|
|
73
|
-
|
|
76
|
+
real_new_directory = File.expand_path(aruba.current_directory,
|
|
77
|
+
aruba.root_directory)
|
|
78
|
+
Aruba.platform.chdir real_new_directory
|
|
74
79
|
|
|
75
80
|
result = with_environment(
|
|
76
81
|
'OLDPWD' => old_dir,
|
|
77
|
-
'PWD' =>
|
|
82
|
+
'PWD' => real_new_directory,
|
|
78
83
|
&block
|
|
79
84
|
)
|
|
80
85
|
ensure
|
|
@@ -85,19 +90,19 @@ module Aruba
|
|
|
85
90
|
return result
|
|
86
91
|
end
|
|
87
92
|
|
|
88
|
-
unless Aruba.platform.directory?
|
|
89
|
-
|
|
93
|
+
unless Aruba.platform.directory?(expand_path(dir))
|
|
94
|
+
raise ArgumentError, "#{expand_path(dir)} is not a directory or does not exist."
|
|
90
95
|
end
|
|
91
96
|
|
|
92
97
|
old_directory = expand_path('.')
|
|
93
98
|
aruba.current_directory << dir
|
|
94
99
|
new_directory = expand_path('.')
|
|
95
100
|
|
|
96
|
-
aruba.event_bus.notify Events::ChangedWorkingDirectory.new(old: old_directory,
|
|
101
|
+
aruba.event_bus.notify Events::ChangedWorkingDirectory.new(old: old_directory,
|
|
102
|
+
new: new_directory)
|
|
97
103
|
|
|
98
104
|
self
|
|
99
105
|
end
|
|
100
|
-
# rubocop:enable Metrics/MethodLength
|
|
101
106
|
|
|
102
107
|
# Expand file name
|
|
103
108
|
#
|
|
@@ -135,57 +140,70 @@ module Aruba
|
|
|
135
140
|
# # => /foo/bar
|
|
136
141
|
# expand_path('/foo/bar')
|
|
137
142
|
#
|
|
138
|
-
# rubocop:disable Metrics/MethodLength
|
|
139
|
-
# rubocop:disable Metrics/CyclomaticComplexity
|
|
140
|
-
# rubocop:disable Metrics/PerceivedComplexity
|
|
141
143
|
def expand_path(file_name, dir_string = nil)
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
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."
|
|
145
148
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
# rubocop:disable Metrics/LineLength
|
|
149
|
-
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
|
|
150
151
|
|
|
151
|
-
|
|
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
|
|
152
157
|
|
|
153
158
|
prefix = file_name[0]
|
|
154
|
-
rest = file_name[2..-1]
|
|
155
159
|
|
|
156
160
|
if aruba.config.fixtures_path_prefix == prefix
|
|
161
|
+
rest = file_name[2..-1]
|
|
157
162
|
path = File.join(*[aruba.fixtures_directory, rest].compact)
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
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
|
|
163
173
|
|
|
164
174
|
path
|
|
165
175
|
elsif prefix == '~'
|
|
166
176
|
path = with_environment do
|
|
167
|
-
|
|
177
|
+
File.expand_path(file_name)
|
|
168
178
|
end
|
|
169
179
|
|
|
170
|
-
|
|
171
|
-
|
|
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
|
|
172
186
|
|
|
173
187
|
path.to_s
|
|
174
|
-
elsif absolute?
|
|
188
|
+
elsif absolute?(file_name)
|
|
175
189
|
unless aruba.config.allow_absolute_paths
|
|
176
|
-
|
|
177
|
-
|
|
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'
|
|
178
197
|
end
|
|
179
198
|
file_name
|
|
180
199
|
else
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
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
|
|
184
205
|
end
|
|
185
206
|
end
|
|
186
|
-
# rubocop:enable Metrics/MethodLength
|
|
187
|
-
# rubocop:enable Metrics/CyclomaticComplexity
|
|
188
|
-
# rubocop:enable Metrics/PerceivedComplexity
|
|
189
207
|
|
|
190
208
|
# Run block with environment
|
|
191
209
|
#
|
|
@@ -195,14 +213,10 @@ module Aruba
|
|
|
195
213
|
# @yield
|
|
196
214
|
# The block of code which should be run with the changed environment variables
|
|
197
215
|
def with_environment(env = {}, &block)
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
ensure
|
|
203
|
-
# make sure the old environment is really restored in "aruba.environment"
|
|
204
|
-
aruba.environment.clear
|
|
205
|
-
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
|
|
206
220
|
end
|
|
207
221
|
end
|
|
208
222
|
end
|
|
@@ -23,7 +23,9 @@ module Aruba
|
|
|
23
23
|
aruba.environment[name] = value
|
|
24
24
|
new_environment = aruba.environment.to_h
|
|
25
25
|
|
|
26
|
-
environment_change = { old: old_environment,
|
|
26
|
+
environment_change = { old: old_environment,
|
|
27
|
+
new: new_environment,
|
|
28
|
+
changed: { name: name, value: value } }
|
|
27
29
|
aruba.event_bus.notify Events::AddedEnvironmentVariable.new(environment_change)
|
|
28
30
|
|
|
29
31
|
self
|
|
@@ -46,7 +48,9 @@ module Aruba
|
|
|
46
48
|
aruba.environment.append name, value
|
|
47
49
|
new_environment = aruba.environment.to_h
|
|
48
50
|
|
|
49
|
-
environment_change = { old: old_environment,
|
|
51
|
+
environment_change = { old: old_environment,
|
|
52
|
+
new: new_environment,
|
|
53
|
+
changed: { name: name, value: value } }
|
|
50
54
|
aruba.event_bus.notify Events::ChangedEnvironmentVariable.new(environment_change)
|
|
51
55
|
|
|
52
56
|
self
|
|
@@ -69,7 +73,9 @@ module Aruba
|
|
|
69
73
|
aruba.environment.prepend name, value
|
|
70
74
|
new_environment = aruba.environment.to_h
|
|
71
75
|
|
|
72
|
-
environment_change = { old: old_environment,
|
|
76
|
+
environment_change = { old: old_environment,
|
|
77
|
+
new: new_environment,
|
|
78
|
+
changed: { name: name, value: value } }
|
|
73
79
|
aruba.event_bus.notify Events::ChangedEnvironmentVariable.new(environment_change)
|
|
74
80
|
|
|
75
81
|
self
|
|
@@ -88,7 +94,9 @@ module Aruba
|
|
|
88
94
|
aruba.environment.delete name
|
|
89
95
|
new_environment = aruba.environment.to_h
|
|
90
96
|
|
|
91
|
-
environment_change = { old: old_environment,
|
|
97
|
+
environment_change = { old: old_environment,
|
|
98
|
+
new: new_environment,
|
|
99
|
+
changed: { name: name, value: '' } }
|
|
92
100
|
aruba.event_bus.notify Events::ChangedEnvironmentVariable.new(environment_change)
|
|
93
101
|
|
|
94
102
|
self
|
data/lib/aruba/api/filesystem.rb
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
require '
|
|
2
|
-
|
|
3
|
-
require 'aruba/extensions/string/strip'
|
|
1
|
+
require 'pathname'
|
|
4
2
|
|
|
5
|
-
require 'aruba/
|
|
3
|
+
require 'aruba/platform'
|
|
6
4
|
|
|
7
5
|
Aruba.platform.require_matching_files('../matchers/file/*.rb', __FILE__)
|
|
8
6
|
Aruba.platform.require_matching_files('../matchers/directory/*.rb', __FILE__)
|
|
@@ -54,14 +52,14 @@ module Aruba
|
|
|
54
52
|
#
|
|
55
53
|
# @return [Boolean]
|
|
56
54
|
def absolute?(path)
|
|
57
|
-
|
|
55
|
+
Aruba.platform.absolute_path?(path)
|
|
58
56
|
end
|
|
59
57
|
|
|
60
58
|
# Check if path is relative
|
|
61
59
|
#
|
|
62
60
|
# @return [Boolean]
|
|
63
61
|
def relative?(path)
|
|
64
|
-
|
|
62
|
+
Aruba.platform.relative_path?(path)
|
|
65
63
|
end
|
|
66
64
|
|
|
67
65
|
# Return all existing paths (directories, files) in current dir
|
|
@@ -93,7 +91,7 @@ module Aruba
|
|
|
93
91
|
# @return [Dir]
|
|
94
92
|
# The directory object
|
|
95
93
|
def directory(path)
|
|
96
|
-
|
|
94
|
+
raise ArgumentError, %(Path "#{name}" does not exist.) unless exist? name
|
|
97
95
|
|
|
98
96
|
Dir.new(expand_path(path))
|
|
99
97
|
end
|
|
@@ -103,24 +101,31 @@ module Aruba
|
|
|
103
101
|
# @return [Array]
|
|
104
102
|
# The content of directory
|
|
105
103
|
def list(name)
|
|
106
|
-
|
|
104
|
+
raise ArgumentError, %(Path "#{name}" does not exist.) unless exist? name
|
|
105
|
+
|
|
107
106
|
unless directory? name
|
|
108
|
-
|
|
107
|
+
raise ArgumentError,
|
|
108
|
+
%(Only directories are supported. Path "#{name}" is not a directory.)
|
|
109
109
|
end
|
|
110
110
|
|
|
111
111
|
existing_files = Dir.glob(expand_path(File.join(name, '**', '*')))
|
|
112
|
-
current_working_directory =
|
|
112
|
+
current_working_directory = Pathname.new(expand_path('.'))
|
|
113
113
|
|
|
114
|
-
existing_files.map
|
|
114
|
+
existing_files.map do |d|
|
|
115
|
+
Pathname.new(d).relative_path_from(current_working_directory).to_s
|
|
116
|
+
end
|
|
115
117
|
end
|
|
116
118
|
|
|
117
119
|
# Return content of file
|
|
118
120
|
#
|
|
119
121
|
# @return [Array]
|
|
120
|
-
# The content of file, without "\n" or "\r\n" at the end.
|
|
122
|
+
# The content of file, without "\n" or "\r\n" at the end.
|
|
123
|
+
# To rebuild the file use `content.join("\n")`
|
|
121
124
|
def read(name)
|
|
122
|
-
|
|
123
|
-
|
|
125
|
+
raise ArgumentError, %(Path "#{name}" does not exist.) unless exist? name
|
|
126
|
+
unless file? name
|
|
127
|
+
raise ArgumentError, %(Only files are supported. Path "#{name}" is not a file.)
|
|
128
|
+
end
|
|
124
129
|
|
|
125
130
|
File.readlines(expand_path(name)).map(&:chomp)
|
|
126
131
|
end
|
|
@@ -148,7 +153,7 @@ module Aruba
|
|
|
148
153
|
def touch(*args)
|
|
149
154
|
args = args.flatten
|
|
150
155
|
|
|
151
|
-
options = if args.last.
|
|
156
|
+
options = if args.last.is_a? Hash
|
|
152
157
|
args.pop
|
|
153
158
|
else
|
|
154
159
|
{}
|
|
@@ -171,9 +176,6 @@ module Aruba
|
|
|
171
176
|
# @param [String] destination
|
|
172
177
|
# A file or directory name. If multiple sources are given the destination
|
|
173
178
|
# needs to be a directory
|
|
174
|
-
#
|
|
175
|
-
# rubocop:disable Metrics/CyclomaticComplexity
|
|
176
|
-
# def copy(*source, destination)
|
|
177
179
|
def copy(*args)
|
|
178
180
|
args = args.flatten
|
|
179
181
|
destination = args.pop
|
|
@@ -184,7 +186,8 @@ module Aruba
|
|
|
184
186
|
end
|
|
185
187
|
|
|
186
188
|
if destination.start_with? aruba.config.fixtures_path_prefix
|
|
187
|
-
raise ArgumentError,
|
|
189
|
+
raise ArgumentError,
|
|
190
|
+
"Using a fixture as destination (#{destination}) is not supported"
|
|
188
191
|
end
|
|
189
192
|
|
|
190
193
|
if source.count > 1 && exist?(destination) && !directory?(destination)
|
|
@@ -205,7 +208,6 @@ module Aruba
|
|
|
205
208
|
|
|
206
209
|
self
|
|
207
210
|
end
|
|
208
|
-
# rubocop:enable Metrics/CyclomaticComplexity
|
|
209
211
|
|
|
210
212
|
# Move a file and/or directory
|
|
211
213
|
#
|
|
@@ -217,9 +219,6 @@ module Aruba
|
|
|
217
219
|
# @param [String] destination
|
|
218
220
|
# A file or directory name. If multiple sources are given the destination
|
|
219
221
|
# needs to be a directory
|
|
220
|
-
#
|
|
221
|
-
# rubocop:disable Metrics/CyclomaticComplexity
|
|
222
|
-
# rubocop:disable Metrics/MethodLength
|
|
223
222
|
def move(*args)
|
|
224
223
|
args = args.flatten
|
|
225
224
|
destination = args.pop
|
|
@@ -232,7 +231,8 @@ module Aruba
|
|
|
232
231
|
end
|
|
233
232
|
|
|
234
233
|
if destination.start_with? aruba.config.fixtures_path_prefix
|
|
235
|
-
raise ArgumentError,
|
|
234
|
+
raise ArgumentError,
|
|
235
|
+
"Using a fixture as destination (#{destination}) is not supported"
|
|
236
236
|
end
|
|
237
237
|
|
|
238
238
|
source.each do |s|
|
|
@@ -257,8 +257,6 @@ module Aruba
|
|
|
257
257
|
|
|
258
258
|
self
|
|
259
259
|
end
|
|
260
|
-
# rubocop:enable Metrics/MethodLength
|
|
261
|
-
# rubocop:enable Metrics/CyclomaticComplexity
|
|
262
260
|
|
|
263
261
|
# Create a file with the given size
|
|
264
262
|
#
|
|
@@ -290,21 +288,21 @@ module Aruba
|
|
|
290
288
|
# Change file system permissions of file
|
|
291
289
|
#
|
|
292
290
|
# @param [Octal] mode
|
|
293
|
-
# File system mode, eg.
|
|
291
|
+
# File system mode, eg. 0o755
|
|
294
292
|
#
|
|
295
293
|
# @param [String] file_name
|
|
296
294
|
# Name of file to be modified. This file needs to be present to succeed
|
|
297
295
|
def chmod(*args)
|
|
298
296
|
args = args.flatten
|
|
299
297
|
|
|
300
|
-
options = if args.last.
|
|
298
|
+
options = if args.last.is_a? Hash
|
|
301
299
|
args.pop
|
|
302
300
|
else
|
|
303
301
|
{}
|
|
304
302
|
end
|
|
305
303
|
|
|
306
304
|
mode = args.shift
|
|
307
|
-
mode = if mode.
|
|
305
|
+
mode = if mode.is_a? String
|
|
308
306
|
mode.to_i(8)
|
|
309
307
|
else
|
|
310
308
|
mode
|
|
@@ -349,7 +347,7 @@ module Aruba
|
|
|
349
347
|
def remove(*args)
|
|
350
348
|
args = args.flatten
|
|
351
349
|
|
|
352
|
-
options = if args.last.
|
|
350
|
+
options = if args.last.is_a? Hash
|
|
353
351
|
args.pop
|
|
354
352
|
else
|
|
355
353
|
{}
|
|
@@ -386,23 +384,11 @@ module Aruba
|
|
|
386
384
|
# @return [FileSize]
|
|
387
385
|
# Bytes on disk
|
|
388
386
|
def disk_usage(*paths)
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
# TODO: change the API so that you could set something like
|
|
393
|
-
# aruba.config.fs_allocation_unit_size directly
|
|
394
|
-
|
|
395
|
-
typical_fs_unit = 4096 # very typical, except for giant or embedded filesystems
|
|
396
|
-
typical_dev_bsize = 512 # google dev_bsize for more info
|
|
397
|
-
|
|
398
|
-
block_multiplier = typical_fs_unit / typical_dev_bsize
|
|
399
|
-
fs_unit_size = aruba.config.physical_block_size * block_multiplier
|
|
387
|
+
paths = paths.flatten
|
|
388
|
+
expect(paths).to Aruba::Matchers.all be_an_existing_path
|
|
389
|
+
expanded = paths.map { |path| expand_path(path) }
|
|
400
390
|
|
|
401
|
-
|
|
402
|
-
# what the disk usage of a file is (even if Aruba.config needs to be
|
|
403
|
-
# read)
|
|
404
|
-
deprecated_block_count = fs_unit_size / block_multiplier
|
|
405
|
-
Aruba.platform.determine_disk_usage(expanded, deprecated_block_count)
|
|
391
|
+
Aruba.platform.determine_disk_usage(expanded)
|
|
406
392
|
end
|
|
407
393
|
|
|
408
394
|
# Get size of file
|