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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.nav +12 -0
- data/.rspec +1 -0
- data/.rubocop.yml +12 -0
- data/.simplecov +2 -0
- data/.travis.yml +5 -6
- data/Gemfile +53 -26
- data/History.md +17 -0
- data/LICENSE +1 -1
- data/README.md +45 -19
- data/Rakefile +12 -2
- data/TODO.md +3 -0
- data/aruba.gemspec +19 -8
- data/cucumber.yml +1 -1
- data/features/api/cd.feature +119 -0
- data/features/api/command/run.feature +37 -0
- data/features/api/command/which.feature +37 -0
- data/features/api/environment/append_environment_variable.feature +118 -0
- data/features/api/environment/prepend_environment_variable.feature +118 -0
- data/features/api/environment/set_environment_variable.feature +252 -0
- data/features/configuration/exit_timeout.feature +51 -0
- data/features/configuration/fixtures_directories.feature +31 -0
- data/features/configuration/fixtures_path_prefix.feature +24 -0
- data/features/configuration/io_timeout.feature +31 -0
- data/features/configuration/keep_ansi.feature +31 -0
- data/features/configuration/root_directory.feature +31 -0
- data/features/configuration/working_directory.feature +32 -0
- data/features/fixtures/cli-app/.gitignore +9 -0
- data/features/fixtures/cli-app/.rspec +2 -0
- data/features/fixtures/cli-app/README.md +34 -0
- data/features/fixtures/cli-app/Rakefile +1 -0
- data/features/fixtures/cli-app/bin/cli +6 -0
- data/features/fixtures/cli-app/cli-app.gemspec +26 -0
- data/features/fixtures/cli-app/features/support/env.rb +1 -0
- data/features/fixtures/cli-app/lib/cli/app.rb +13 -0
- data/features/fixtures/cli-app/lib/cli/app/version.rb +5 -0
- data/features/fixtures/cli-app/script/console +14 -0
- data/features/fixtures/cli-app/spec/cli/app_spec.rb +7 -0
- data/features/fixtures/cli-app/spec/spec_helper.rb +10 -0
- data/features/fixtures/copy/file.txt +1 -1
- data/features/hooks/after/command.feature +34 -0
- data/features/hooks/before/command.feature +61 -0
- data/features/matchers/directory/have_sub_directory.feature +110 -0
- data/features/matchers/file/be_existing_file.feature +82 -0
- data/features/matchers/file/have_file_content.feature +123 -0
- data/features/matchers/file/have_file_size.feature +107 -0
- data/features/matchers/path/be_an_absolute_path.feature +74 -0
- data/features/matchers/path/be_an_existing_path.feature +97 -0
- data/features/matchers/path/have_permissions.feature +118 -0
- data/features/matchers/timeouts.feature +48 -0
- data/features/step_definitions/aruba_dev_steps.rb +69 -1
- data/features/steps/commands/exit_statuses.feature +136 -0
- data/features/steps/commands/in_process.feature +129 -0
- data/features/steps/commands/run.feature +36 -0
- data/features/steps/environment/home_variable.feature +49 -0
- data/features/steps/environment/set_environment_variable.feature +34 -0
- data/features/support/aruba.rb +5 -0
- data/features/support/env.rb +8 -4
- data/lib/aruba.rb +20 -8
- data/lib/aruba/announcer.rb +1 -0
- data/lib/aruba/api.rb +18 -1179
- data/lib/aruba/api/command.rb +351 -0
- data/lib/aruba/api/core.rb +141 -0
- data/lib/aruba/api/deprecated.rb +549 -0
- data/lib/aruba/api/environment.rb +61 -0
- data/lib/aruba/api/filesystem.rb +305 -0
- data/lib/aruba/api/rvm.rb +39 -0
- data/lib/aruba/aruba_path.rb +75 -0
- data/lib/aruba/basic_configuration.rb +208 -0
- data/lib/aruba/basic_configuration/option.rb +25 -0
- data/lib/aruba/config.rb +43 -30
- data/lib/aruba/config/jruby.rb +14 -0
- data/lib/aruba/config_wrapper.rb +17 -0
- data/lib/aruba/contracts/relative_path.rb +13 -0
- data/lib/aruba/creators/aruba_file_creator.rb +32 -0
- data/lib/aruba/creators/aruba_fixed_size_file_creator.rb +32 -0
- data/lib/aruba/cucumber.rb +87 -53
- data/lib/aruba/cucumber/hooks.rb +65 -10
- data/lib/aruba/environment.rb +121 -0
- data/lib/aruba/errors.rb +3 -0
- data/lib/aruba/extensions/string/strip.rb +24 -0
- data/lib/aruba/hooks.rb +54 -0
- data/lib/aruba/jruby.rb +4 -9
- data/lib/aruba/matchers/command.rb +1 -79
- data/lib/aruba/matchers/command/be_successfully_executed.rb +30 -0
- data/lib/aruba/matchers/command/have_exit_status.rb +47 -0
- data/lib/aruba/matchers/command/have_finished_in_time.rb +42 -0
- data/lib/aruba/matchers/directory.rb +1 -59
- data/lib/aruba/matchers/directory/be_an_existing_directory.rb +34 -0
- data/lib/aruba/matchers/directory/have_sub_directory.rb +49 -0
- data/lib/aruba/matchers/file.rb +1 -177
- data/lib/aruba/matchers/file/be_an_existing_file.rb +34 -0
- data/lib/aruba/matchers/file/have_file_content.rb +58 -0
- data/lib/aruba/matchers/file/have_file_size.rb +43 -0
- data/lib/aruba/matchers/file/have_same_file_content.rb +44 -0
- data/lib/aruba/matchers/path.rb +1 -99
- data/lib/aruba/matchers/path/a_path_matching_pattern.rb +21 -0
- data/lib/aruba/matchers/path/be_an_absolute_path.rb +32 -0
- data/lib/aruba/matchers/path/be_an_existing_path.rb +33 -0
- data/lib/aruba/matchers/path/have_permissions.rb +60 -0
- data/lib/aruba/matchers/path/match_path_pattern.rb +41 -0
- data/lib/aruba/matchers/rspec.rb +0 -0
- data/lib/aruba/matchers/rspec_matcher_include_regexp.rb +1 -1
- data/lib/aruba/platform.rb +230 -0
- data/lib/aruba/process_monitor.rb +23 -5
- data/lib/aruba/processes/basic_process.rb +35 -1
- data/lib/aruba/processes/debug_process.rb +26 -15
- data/lib/aruba/processes/in_process.rb +21 -9
- data/lib/aruba/processes/spawn_process.rb +29 -19
- data/lib/aruba/reporting.rb +2 -0
- data/lib/aruba/rspec.rb +61 -13
- data/lib/aruba/runtime.rb +33 -0
- data/script/bootstrap +4 -6
- data/spec/aruba/api/runtime_spec.rb +28 -0
- data/spec/aruba/api_spec.rb +129 -126
- data/spec/aruba/aruba_path_spec.rb +65 -0
- data/spec/aruba/basic_configuration_spec.rb +5 -0
- data/spec/aruba/config_wrapper_spec.rb +25 -0
- data/spec/aruba/configuration_spec.rb +5 -0
- data/spec/aruba/jruby_spec.rb +34 -18
- data/spec/aruba/matchers/directory_spec.rb +6 -7
- data/spec/aruba/matchers/file_spec.rb +16 -20
- data/spec/aruba/matchers/path_spec.rb +14 -11
- data/spec/aruba/rspec_spec.rb +15 -0
- data/spec/aruba/runtime_spec.rb +29 -0
- data/spec/aruba/spawn_process_spec.rb +2 -2
- data/spec/spec_helper.rb +10 -2
- data/spec/support/configs/rspec.rb +1 -1
- data/spec/support/matchers/option.rb +35 -0
- data/spec/support/shared_contexts/aruba.rb +10 -8
- data/spec/support/shared_examples/configuration.rb +116 -0
- metadata +182 -33
- data/.rvmrc +0 -1
- data/features/before_cmd_hooks.feature +0 -61
- data/features/command_environment_variables.feature +0 -31
- data/features/custom_ruby_process.feature +0 -12
- data/features/exit_statuses.feature +0 -30
- data/features/support/custom_main.rb +0 -28
- data/lib/aruba/matchers/mode.rb +0 -52
- data/lib/aruba/utils.rb +0 -21
@@ -0,0 +1,230 @@
|
|
1
|
+
require 'rbconfig'
|
2
|
+
require 'pathname'
|
3
|
+
|
4
|
+
module Aruba
|
5
|
+
# WARNING:
|
6
|
+
# All methods found here are not considered part of the public API of aruba.
|
7
|
+
#
|
8
|
+
# Those methods can be changed at any time in the feature or removed without
|
9
|
+
# any further notice.
|
10
|
+
module Platform
|
11
|
+
def detect_ruby(cmd)
|
12
|
+
if cmd =~ /^ruby\s/
|
13
|
+
cmd.gsub(/^ruby\s/, "#{current_ruby} ")
|
14
|
+
else
|
15
|
+
cmd
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def deprecated(msg)
|
20
|
+
warn(format('%s. Called by %s', msg, caller[1]))
|
21
|
+
end
|
22
|
+
|
23
|
+
def current_ruby
|
24
|
+
::File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name'])
|
25
|
+
end
|
26
|
+
|
27
|
+
# @deprecated
|
28
|
+
# Add newline at the end
|
29
|
+
def ensure_newline(str)
|
30
|
+
deprecated('The use of "#ensure_newline" is deprecated. It will be removed soon')
|
31
|
+
|
32
|
+
str.chomp << "\n"
|
33
|
+
end
|
34
|
+
|
35
|
+
def require_matching_files(pattern, base)
|
36
|
+
if RUBY_VERSION < '1.9.'
|
37
|
+
::Dir.glob(::File.expand_path(pattern, base)).each { |f| require File.join(File.dirname(f), File.basename(f, '.rb')) }
|
38
|
+
else
|
39
|
+
::Dir.glob(::File.expand_path(pattern, base)).each { |f| require_relative f }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# Create directory and subdirectories
|
44
|
+
def mkdir(dir_name)
|
45
|
+
dir_name = ::File.expand_path(dir_name)
|
46
|
+
|
47
|
+
::FileUtils.mkdir_p(dir_name) unless ::File.directory?(dir_name)
|
48
|
+
end
|
49
|
+
|
50
|
+
# Remove file, directory + sub-directories
|
51
|
+
def rm(paths, options = {})
|
52
|
+
paths = Array(paths).map { |p| ::File.expand_path(p) }
|
53
|
+
|
54
|
+
FileUtils.rm_r(paths, options)
|
55
|
+
end
|
56
|
+
|
57
|
+
# Change to directory
|
58
|
+
def chdir(dir_name, &block)
|
59
|
+
dir_name = ::File.expand_path(dir_name.to_s)
|
60
|
+
|
61
|
+
::Dir.chdir(dir_name, &block)
|
62
|
+
end
|
63
|
+
|
64
|
+
# Touch file, directory
|
65
|
+
def touch(args, options)
|
66
|
+
FileUtils.touch(args, options)
|
67
|
+
end
|
68
|
+
|
69
|
+
# Copy file/directory
|
70
|
+
def cp(args, options)
|
71
|
+
FileUtils.cp_r(args, options)
|
72
|
+
end
|
73
|
+
|
74
|
+
# Change mode of file/directory
|
75
|
+
def chmod(mode, args, options)
|
76
|
+
FileUtils.chmod_R(mode, args, options)
|
77
|
+
end
|
78
|
+
|
79
|
+
# Exists and is file
|
80
|
+
def file?(f)
|
81
|
+
File.file? f
|
82
|
+
end
|
83
|
+
|
84
|
+
# Exists and is directory
|
85
|
+
def directory?(f)
|
86
|
+
File.directory? f
|
87
|
+
end
|
88
|
+
|
89
|
+
# Path Exists
|
90
|
+
def exist?(f)
|
91
|
+
File.exist? f
|
92
|
+
end
|
93
|
+
|
94
|
+
# Path is executable
|
95
|
+
def executable_file?(f)
|
96
|
+
File.file?(f) && File.executable?(f)
|
97
|
+
end
|
98
|
+
|
99
|
+
# Expand path
|
100
|
+
def expand_path(path, base)
|
101
|
+
File.expand_path(path, base)
|
102
|
+
end
|
103
|
+
|
104
|
+
def absolute_path?(path)
|
105
|
+
Pathname.new(path).absolute?
|
106
|
+
end
|
107
|
+
|
108
|
+
# Check if command is relative
|
109
|
+
#
|
110
|
+
# @return [TrueClass, FalseClass]
|
111
|
+
# true
|
112
|
+
# * bin/command.sh
|
113
|
+
#
|
114
|
+
# false
|
115
|
+
# * /bin/command.sh
|
116
|
+
# * command.sh
|
117
|
+
def relative_command?(path)
|
118
|
+
p = Pathname.new(path)
|
119
|
+
p.relative? && p.basename != p
|
120
|
+
end
|
121
|
+
|
122
|
+
# Write to file
|
123
|
+
def write_file(path, content)
|
124
|
+
if RUBY_VERSION < '1.9'
|
125
|
+
File.open(path, 'wb') do |f|
|
126
|
+
f.print content
|
127
|
+
end
|
128
|
+
else
|
129
|
+
File.write(path, content)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
# Unescape string
|
134
|
+
#
|
135
|
+
# @param [String] string
|
136
|
+
# The string which should be unescaped, e.g. the output of a command
|
137
|
+
#
|
138
|
+
# @return
|
139
|
+
# The string stripped from escape sequences
|
140
|
+
def unescape(string, keep_ansi = true)
|
141
|
+
string = string.gsub('\n', "\n").gsub('\"', '"').gsub('\e', "\e")
|
142
|
+
string = string.gsub(/\e\[\d+(?>(;\d+)*)m/, '') unless keep_ansi
|
143
|
+
string
|
144
|
+
end
|
145
|
+
|
146
|
+
# Resolve path for command using the PATH-environment variable
|
147
|
+
#
|
148
|
+
# Mostly taken from here: https://github.com/djberg96/ptools
|
149
|
+
#
|
150
|
+
# @param [#to_s] program
|
151
|
+
# The name of the program which should be resolved
|
152
|
+
#
|
153
|
+
# @param [String] path
|
154
|
+
# The PATH, a string concatenated with ":", e.g. /usr/bin/:/bin on a
|
155
|
+
# UNIX-system
|
156
|
+
#
|
157
|
+
# rubocop:disable Metrics/MethodLength
|
158
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
159
|
+
def which(program, path = ENV['PATH'])
|
160
|
+
on_windows = false
|
161
|
+
on_windows = true if File::ALT_SEPARATOR
|
162
|
+
|
163
|
+
program = program.to_s
|
164
|
+
|
165
|
+
path_exts = ENV['PATHEXT'] ? ('.{' + ENV['PATHEXT'].tr(';', ',').tr('.','') + '}').downcase : '.{exe,com,bat}' if on_windows
|
166
|
+
|
167
|
+
raise ArgumentError, "ENV['PATH'] cannot be empty" if path.nil? || path.empty?
|
168
|
+
|
169
|
+
# Bail out early if an absolute path is provided or the command path is relative
|
170
|
+
# Examples: /usr/bin/command or bin/command.sh
|
171
|
+
if Aruba::Platform.absolute_path?(program) || Aruba::Platform.relative_command?(program)
|
172
|
+
program += path_exts if on_windows && File.extname(program).empty?
|
173
|
+
|
174
|
+
found = Dir[program].first
|
175
|
+
|
176
|
+
return File.expand_path(found) if found && Aruba::Platform.executable_file?(found)
|
177
|
+
return nil
|
178
|
+
end
|
179
|
+
|
180
|
+
# Iterate over each path glob the dir + program.
|
181
|
+
path.split(File::PATH_SEPARATOR).each do |dir|
|
182
|
+
dir = Aruba::Platform.expand_path(dir, Dir.getwd)
|
183
|
+
|
184
|
+
next unless Aruba::Platform.exist?(dir) # In case of bogus second argument
|
185
|
+
file = File.join(dir, program)
|
186
|
+
|
187
|
+
# Dir[] doesn't handle backslashes properly, so convert them. Also, if
|
188
|
+
# the program name doesn't have an extension, try them all.
|
189
|
+
if on_windows
|
190
|
+
file = file.tr("\\", "/")
|
191
|
+
file += path_exts if File.extname(program).empty?
|
192
|
+
end
|
193
|
+
|
194
|
+
found = Dir[file].first
|
195
|
+
|
196
|
+
# Convert all forward slashes to backslashes if supported
|
197
|
+
if found && Aruba::Platform.executable_file?(found)
|
198
|
+
found.tr!(File::SEPARATOR, File::ALT_SEPARATOR) if on_windows
|
199
|
+
return found
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
nil
|
204
|
+
end
|
205
|
+
# rubocop:enable Metrics/MethodLength
|
206
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
207
|
+
|
208
|
+
module_function :detect_ruby, \
|
209
|
+
:current_ruby, \
|
210
|
+
:ensure_newline, \
|
211
|
+
:require_matching_files, \
|
212
|
+
:mkdir, \
|
213
|
+
:rm, \
|
214
|
+
:chdir, \
|
215
|
+
:deprecated, \
|
216
|
+
:touch, \
|
217
|
+
:cp, \
|
218
|
+
:chmod, \
|
219
|
+
:file?, \
|
220
|
+
:directory?, \
|
221
|
+
:exist?, \
|
222
|
+
:expand_path, \
|
223
|
+
:absolute_path?, \
|
224
|
+
:relative_command?, \
|
225
|
+
:executable_file?, \
|
226
|
+
:unescape, \
|
227
|
+
:which, \
|
228
|
+
:write_file
|
229
|
+
end
|
230
|
+
end
|
@@ -41,6 +41,8 @@ module Aruba
|
|
41
41
|
|
42
42
|
def register_process(name, process)
|
43
43
|
processes << [name, process]
|
44
|
+
|
45
|
+
[name, process]
|
44
46
|
end
|
45
47
|
|
46
48
|
def get_process(wanted)
|
@@ -58,7 +60,7 @@ module Aruba
|
|
58
60
|
# @param [String] cmd
|
59
61
|
# The command
|
60
62
|
def output_from(cmd)
|
61
|
-
cmd =
|
63
|
+
cmd = Platform.detect_ruby(cmd)
|
62
64
|
get_process(cmd).output
|
63
65
|
end
|
64
66
|
|
@@ -67,7 +69,7 @@ module Aruba
|
|
67
69
|
# @param [String] cmd
|
68
70
|
# The command
|
69
71
|
def stdout_from(cmd)
|
70
|
-
cmd =
|
72
|
+
cmd = Platform.detect_ruby(cmd)
|
71
73
|
get_process(cmd).stdout
|
72
74
|
end
|
73
75
|
|
@@ -76,7 +78,7 @@ module Aruba
|
|
76
78
|
# @param [String] cmd
|
77
79
|
# The command
|
78
80
|
def stderr_from(cmd)
|
79
|
-
cmd =
|
81
|
+
cmd = Platform.detect_ruby(cmd)
|
80
82
|
get_process(cmd).stderr
|
81
83
|
end
|
82
84
|
|
@@ -86,7 +88,15 @@ module Aruba
|
|
86
88
|
# The stdout of all process which have run before
|
87
89
|
def all_stdout
|
88
90
|
stop_processes!
|
89
|
-
|
91
|
+
|
92
|
+
if RUBY_VERSION < '1.9'
|
93
|
+
out = ''
|
94
|
+
only_processes.each { |ps| out << ps.stdout }
|
95
|
+
|
96
|
+
out
|
97
|
+
else
|
98
|
+
only_processes.each_with_object("") { |ps, o| o << ps.stdout }
|
99
|
+
end
|
90
100
|
end
|
91
101
|
|
92
102
|
# Get stderr of all processes
|
@@ -95,7 +105,15 @@ module Aruba
|
|
95
105
|
# The stderr of all process which have run before
|
96
106
|
def all_stderr
|
97
107
|
stop_processes!
|
98
|
-
|
108
|
+
|
109
|
+
if RUBY_VERSION < '1.9'
|
110
|
+
out = ''
|
111
|
+
only_processes.each { |ps| out << ps.stderr }
|
112
|
+
|
113
|
+
out
|
114
|
+
else
|
115
|
+
only_processes.each_with_object("") { |ps, o| o << ps.stderr }
|
116
|
+
end
|
99
117
|
end
|
100
118
|
|
101
119
|
# Get stderr and stdout of all processes
|
@@ -1,8 +1,21 @@
|
|
1
|
+
require 'aruba/platform'
|
2
|
+
require 'shellwords'
|
3
|
+
|
1
4
|
module Aruba
|
2
5
|
module Processes
|
3
6
|
class BasicProcess
|
4
|
-
|
7
|
+
attr_reader :exit_status, :environment
|
8
|
+
|
9
|
+
def initialize(cmd, exit_timeout, io_wait, working_directory, environment = ENV.to_hash)
|
10
|
+
@cmd = cmd
|
5
11
|
@working_directory = working_directory
|
12
|
+
@environment = environment
|
13
|
+
@exit_status = nil
|
14
|
+
end
|
15
|
+
|
16
|
+
# Return command line
|
17
|
+
def commandline
|
18
|
+
@cmd
|
6
19
|
end
|
7
20
|
|
8
21
|
# Output stderr and stdout
|
@@ -15,11 +28,32 @@ module Aruba
|
|
15
28
|
@stopped == true
|
16
29
|
end
|
17
30
|
|
31
|
+
# Does the process failed to stop in time
|
32
|
+
def timed_out?
|
33
|
+
@timed_out == true
|
34
|
+
end
|
35
|
+
|
18
36
|
# Hook which is run before command is run
|
19
37
|
def before_run; end
|
20
38
|
|
21
39
|
# Hook which is run after command is run
|
22
40
|
def after_run; end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def which(program, path = environment['PATH'])
|
45
|
+
Aruba::Platform.which(program, path)
|
46
|
+
end
|
47
|
+
|
48
|
+
def command
|
49
|
+
Shellwords.split(commandline).first
|
50
|
+
end
|
51
|
+
|
52
|
+
def arguments
|
53
|
+
return Shellwords.split(commandline)[1..-1] if Shellwords.split(commandline).size > 1
|
54
|
+
|
55
|
+
[]
|
56
|
+
end
|
23
57
|
end
|
24
58
|
end
|
25
59
|
end
|
@@ -16,24 +16,35 @@ module Aruba
|
|
16
16
|
# @params [String] working_directory
|
17
17
|
# The directory where the command will be executed
|
18
18
|
class DebugProcess < BasicProcess
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
super
|
27
|
-
end
|
19
|
+
# rubocop:disable Metrics/MethodLength
|
20
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
21
|
+
def run!
|
22
|
+
# rubocop:disable Metrics/LineLength
|
23
|
+
fail LaunchError, %(Command "#{command}" not found in PATH-variable "#{environment['PATH']}".) unless which(command, environment['PATH'])
|
24
|
+
# rubocop:enable Metrics/LineLength
|
28
25
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
26
|
+
if RUBY_VERSION < '1.9'
|
27
|
+
begin
|
28
|
+
old_env = ENV.to_hash
|
29
|
+
ENV.update environment
|
33
30
|
|
34
|
-
|
35
|
-
|
31
|
+
Dir.chdir @working_directory do
|
32
|
+
@exit_status = system(@cmd) ? 0 : 1
|
33
|
+
end
|
34
|
+
ensure
|
35
|
+
ENV.clear
|
36
|
+
ENV.update old_env
|
37
|
+
end
|
38
|
+
elsif RUBY_VERSION < '2'
|
39
|
+
Dir.chdir @working_directory do
|
40
|
+
@exit_status = system(environment, @cmd) ? 0 : 1
|
41
|
+
end
|
42
|
+
else
|
43
|
+
@exit_status = system(environment, @cmd, :chdir => @working_directory) ? 0 : 1
|
44
|
+
end
|
36
45
|
end
|
46
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
47
|
+
# rubocop:enable Metrics/MethodLength
|
37
48
|
|
38
49
|
def stdin(*); end
|
39
50
|
|
@@ -23,9 +23,9 @@ module Aruba
|
|
23
23
|
attr_accessor :main_class
|
24
24
|
end
|
25
25
|
|
26
|
-
def initialize(cmd, exit_timeout, io_wait, working_directory)
|
27
|
-
|
28
|
-
@argv =
|
26
|
+
def initialize(cmd, exit_timeout, io_wait, working_directory, environment = ENV.to_hash)
|
27
|
+
@cmd = cmd
|
28
|
+
@argv = arguments
|
29
29
|
@stdin = StringIO.new
|
30
30
|
@stdout = StringIO.new
|
31
31
|
@stderr = StringIO.new
|
@@ -34,17 +34,16 @@ module Aruba
|
|
34
34
|
super
|
35
35
|
end
|
36
36
|
|
37
|
-
# Return the commandline
|
38
|
-
def commandline
|
39
|
-
self.class.main_class.to_s + @argv.join(" ")
|
40
|
-
end
|
41
|
-
|
42
37
|
def run!
|
43
38
|
raise "You need to call Aruba::InProcess.main_class = YourMainClass" unless self.class.main_class
|
44
39
|
|
45
40
|
Dir.chdir @working_directory do
|
46
41
|
before_run
|
47
|
-
|
42
|
+
|
43
|
+
with_environment do
|
44
|
+
self.class.main_class.new(@argv, @stdin, @stdout, @stderr, @kernel).execute!
|
45
|
+
end
|
46
|
+
|
48
47
|
after_run
|
49
48
|
|
50
49
|
yield self if block_given?
|
@@ -81,6 +80,19 @@ module Aruba
|
|
81
80
|
def terminate
|
82
81
|
stop
|
83
82
|
end
|
83
|
+
|
84
|
+
private
|
85
|
+
|
86
|
+
def with_environment(&block)
|
87
|
+
old_env = ENV.to_hash
|
88
|
+
|
89
|
+
ENV.update(environment)
|
90
|
+
|
91
|
+
block.call
|
92
|
+
ensure
|
93
|
+
ENV.clear
|
94
|
+
ENV.update old_env
|
95
|
+
end
|
84
96
|
end
|
85
97
|
end
|
86
98
|
end
|