aruba 0.9.0.pre → 0.9.0.pre2

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 (158) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +8 -3
  3. data/History.md +61 -19
  4. data/README.md +10 -6
  5. data/TODO.md +6 -1
  6. data/cucumber.yml +10 -6
  7. data/features/.nav +72 -0
  8. data/features/announce.feature +203 -0
  9. data/features/api/command/extract_text.feature +10 -0
  10. data/features/api/command/run.feature +6 -6
  11. data/features/api/command/stop_all_commands.feature +53 -0
  12. data/features/api/command/terminate_all_commands.feature +53 -0
  13. data/features/api/command/unescape_text.feature +12 -0
  14. data/features/api/command/which.feature +3 -3
  15. data/features/api/core/expand_path.feature +4 -4
  16. data/features/api/environment/append_environment_variable.feature +18 -8
  17. data/features/api/environment/prepend_environment_variable.feature +18 -8
  18. data/features/api/environment/set_environment_variable.feature +33 -16
  19. data/features/api/filesystem/cd.feature +23 -13
  20. data/features/api/filesystem/create_directory.feature +2 -2
  21. data/features/api/filesystem/disk_usage.feature +7 -6
  22. data/features/api/filesystem/does_exist.feature +2 -2
  23. data/features/api/filesystem/is_absolute.feature +2 -2
  24. data/features/api/filesystem/is_directory.feature +2 -2
  25. data/features/api/filesystem/is_file.feature +2 -2
  26. data/features/api/filesystem/is_relative.feature +2 -2
  27. data/features/api/filesystem/move.feature +119 -0
  28. data/features/cli/console.feature +3 -3
  29. data/features/commands/debug_command.feature +93 -0
  30. data/features/commands/environment_variables.feature +64 -0
  31. data/features/commands/flushing.feature +74 -0
  32. data/features/commands/interactive.feature +90 -0
  33. data/features/commands/output/all_output.feature +445 -0
  34. data/features/commands/output/stdout.feature +66 -0
  35. data/features/configuration/exit_timeout.feature +5 -5
  36. data/features/configuration/fixtures_directories.feature +3 -3
  37. data/features/configuration/fixtures_path_prefix.feature +1 -1
  38. data/features/configuration/home_directory.feature +4 -4
  39. data/features/configuration/io_timeout.feature +2 -2
  40. data/features/configuration/keep_ansi.feature +2 -2
  41. data/features/configuration/log_level.feature +3 -3
  42. data/features/configuration/physical_block_size.feature +3 -3
  43. data/features/configuration/usage.feature +159 -0
  44. data/features/core/cleanup_aruba_directory.feature +52 -0
  45. data/features/development/build.feature +16 -0
  46. data/features/development/test.feature +24 -0
  47. data/features/file_system_commands.feature +12 -12
  48. data/features/getting_started/supported_programming_languages.feature +89 -0
  49. data/features/hooks/after/command.feature +1 -1
  50. data/features/hooks/before/command.feature +2 -2
  51. data/features/matchers/collection/include_an_object.feature +72 -0
  52. data/features/matchers/timeouts.feature +2 -2
  53. data/features/output.feature +60 -181
  54. data/features/step_definitions/aruba_dev_steps.rb +17 -10
  55. data/features/step_definitions/hooks.rb +11 -0
  56. data/features/steps/commands/exit_statuses.feature +3 -3
  57. data/features/steps/commands/run.feature +0 -15
  58. data/features/steps/filesystem/copy.feature +45 -0
  59. data/features/steps/filesystem/create_directory.feature +47 -0
  60. data/features/steps/filesystem/create_file.feature +53 -0
  61. data/features/steps/filesystem/file_content.feature +1 -1
  62. data/features/steps/filesystem/move.feature +45 -0
  63. data/features/steps/filesystem/overwrite_file.feature +72 -0
  64. data/features/steps/filesystem/use_fixture.feature +77 -0
  65. data/features/usage/install.feature +8 -0
  66. data/{features/fixtures → fixtures}/cli-app/.gitignore +0 -0
  67. data/{features/fixtures → fixtures}/cli-app/.rspec +0 -0
  68. data/{features/fixtures → fixtures}/cli-app/README.md +0 -0
  69. data/{features/fixtures → fixtures}/cli-app/Rakefile +0 -0
  70. data/{features/fixtures → fixtures}/cli-app/bin/cli +0 -0
  71. data/{features/fixtures → fixtures}/cli-app/cli-app.gemspec +0 -0
  72. data/{features/fixtures → fixtures}/cli-app/features/support/env.rb +0 -0
  73. data/{features/fixtures → fixtures}/cli-app/lib/cli/app.rb +0 -0
  74. data/fixtures/cli-app/lib/cli/app/suppress_simple_cov_output.rb +15 -0
  75. data/{features/fixtures → fixtures}/cli-app/lib/cli/app/version.rb +0 -0
  76. data/{features/fixtures/empty-app → fixtures/cli-app}/script/console +3 -3
  77. data/{features/fixtures → fixtures}/cli-app/spec/spec_helper.rb +0 -0
  78. data/{features/fixtures → fixtures}/cli-app/spec/support/aruba.rb +0 -0
  79. data/{features/fixtures → fixtures}/copy/file.txt +0 -0
  80. data/{features/fixtures → fixtures}/empty-app/.gitignore +0 -0
  81. data/{features/fixtures → fixtures}/empty-app/.rspec +0 -0
  82. data/{features/fixtures → fixtures}/empty-app/README.md +0 -0
  83. data/{features/fixtures → fixtures}/empty-app/Rakefile +0 -0
  84. data/{features/fixtures → fixtures}/empty-app/bin/cli +0 -0
  85. data/{features/fixtures → fixtures}/empty-app/cli-app.gemspec +0 -0
  86. data/{features/fixtures → fixtures}/empty-app/lib/cli/app.rb +0 -0
  87. data/{features/fixtures → fixtures}/empty-app/lib/cli/app/version.rb +0 -0
  88. data/{features/fixtures/cli-app → fixtures/empty-app}/script/console +3 -3
  89. data/{features/fixtures → fixtures}/empty-app/spec/spec_helper.rb +0 -0
  90. data/{features/fixtures → fixtures}/fixtures-app/test.txt +0 -0
  91. data/fixtures/getting-started-app/.gitignore +4 -0
  92. data/fixtures/getting-started-app/Gemfile +4 -0
  93. data/fixtures/getting-started-app/README.md +3 -0
  94. data/fixtures/getting-started-app/features/support/env.rb +1 -0
  95. data/{features/fixtures → fixtures}/spawn_process/stderr.sh +0 -0
  96. data/lib/aruba/announcer.rb +6 -2
  97. data/lib/aruba/api.rb +0 -16
  98. data/lib/aruba/api/command.rb +64 -266
  99. data/lib/aruba/api/core.rb +24 -26
  100. data/lib/aruba/api/deprecated.rb +370 -12
  101. data/lib/aruba/api/filesystem.rb +64 -15
  102. data/lib/aruba/aruba_path.rb +4 -0
  103. data/lib/aruba/config.rb +1 -1
  104. data/lib/aruba/cucumber.rb +5 -449
  105. data/lib/aruba/cucumber/command.rb +378 -0
  106. data/lib/aruba/cucumber/core.rb +29 -0
  107. data/lib/aruba/cucumber/environment.rb +30 -0
  108. data/lib/aruba/cucumber/file.rb +210 -0
  109. data/lib/aruba/cucumber/hooks.rb +11 -14
  110. data/lib/aruba/cucumber/rvm.rb +3 -0
  111. data/lib/aruba/matchers/base/base_matcher.rb +94 -0
  112. data/lib/aruba/matchers/collection.rb +1 -0
  113. data/lib/aruba/matchers/collection/all_objects.rb +2 -0
  114. data/lib/aruba/matchers/collection/include_an_object.rb +120 -0
  115. data/lib/aruba/matchers/command/be_successfully_executed.rb +3 -3
  116. data/lib/aruba/matchers/command/have_exit_status.rb +2 -11
  117. data/lib/aruba/matchers/command/have_finished_in_time.rb +5 -5
  118. data/lib/aruba/matchers/command/have_output.rb +46 -0
  119. data/lib/aruba/matchers/command/have_output_on_stderr.rb +42 -0
  120. data/lib/aruba/matchers/command/have_output_on_stdout.rb +42 -0
  121. data/lib/aruba/matchers/command/have_output_size.rb +28 -0
  122. data/lib/aruba/matchers/directory/be_an_existing_directory.rb +1 -1
  123. data/lib/aruba/matchers/file/be_an_existing_file.rb +1 -1
  124. data/lib/aruba/matchers/file/have_file_content.rb +1 -1
  125. data/lib/aruba/matchers/file/have_file_size.rb +2 -2
  126. data/lib/aruba/matchers/file/have_same_file_content.rb +1 -1
  127. data/lib/aruba/matchers/path/have_permissions.rb +1 -1
  128. data/lib/aruba/platforms/aruba_file_creator.rb +2 -3
  129. data/lib/aruba/platforms/aruba_fixed_size_file_creator.rb +2 -3
  130. data/lib/aruba/platforms/determine_disk_usage.rb +23 -0
  131. data/lib/aruba/platforms/determine_file_size.rb +13 -0
  132. data/lib/aruba/platforms/disk_usage_calculator.rb +11 -0
  133. data/lib/aruba/platforms/local_environment.rb +15 -0
  134. data/lib/aruba/platforms/unix_environment_variables.rb +1 -1
  135. data/lib/aruba/platforms/unix_platform.rb +35 -14
  136. data/lib/aruba/process_monitor.rb +53 -7
  137. data/lib/aruba/processes/basic_process.rb +25 -5
  138. data/lib/aruba/processes/debug_process.rb +27 -25
  139. data/lib/aruba/processes/in_process.rb +7 -22
  140. data/lib/aruba/processes/spawn_process.rb +74 -31
  141. data/lib/aruba/rspec.rb +1 -6
  142. data/lib/aruba/version.rb +1 -1
  143. data/script/console +0 -1
  144. data/spec/aruba/api/environment/restore_env_spec.rb +65 -0
  145. data/spec/aruba/api/environment/set_env_spec.rb +42 -0
  146. data/spec/aruba/api/filesystem/file_size_spec.rb +28 -0
  147. data/spec/aruba/api_spec.rb +10 -7
  148. data/spec/aruba/matchers/command/have_output_size_spec.rb +25 -0
  149. data/spec/aruba/matchers/command_spec.rb +135 -4
  150. data/spec/aruba/spawn_process_spec.rb +1 -1
  151. metadata +107 -65
  152. data/.nav +0 -12
  153. data/features/debug.feature +0 -15
  154. data/features/fixtures/cli-app/spec/cli/app_spec.rb +0 -7
  155. data/features/flushing.feature +0 -26
  156. data/features/interactive.feature +0 -66
  157. data/features/no_clobber.feature +0 -25
  158. data/lib/aruba/disk_usage_calculator.rb +0 -7
@@ -0,0 +1,8 @@
1
+ Feature: Install aruba
2
+
3
+ Background:
4
+ Given the default aruba exit timeout is 60 seconds
5
+
6
+ Scenario: Using rubygems
7
+ Given I successfully run `gem install aruba`
8
+ Then aruba should be installed on the local system
@@ -0,0 +1,15 @@
1
+ module SimpleCov
2
+ module Formatter
3
+ class HTMLFormatter
4
+ def format(result)
5
+ Dir[File.join(File.dirname(__FILE__), "../public/*")].each do |path|
6
+ FileUtils.cp_r(path, asset_output_path)
7
+ end
8
+
9
+ File.open(File.join(output_path, "index.html"), "wb") do |file|
10
+ file.puts template("layout").result(binding)
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
- require "cli/app"
3
+ require 'bundler/setup'
4
+ require 'cli/app'
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
@@ -10,5 +10,5 @@ require "cli/app"
10
10
  # require "pry"
11
11
  # Pry.start
12
12
 
13
- require "irb"
13
+ require 'irb'
14
14
  IRB.start
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
- require "cli/app"
3
+ require 'bundler/setup'
4
+ require 'cli/app'
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
@@ -10,5 +10,5 @@ require "cli/app"
10
10
  # require "pry"
11
11
  # Pry.start
12
12
 
13
- require "irb"
13
+ require 'irb'
14
14
  IRB.start
@@ -0,0 +1,4 @@
1
+ /coverage/
2
+ /doc/
3
+ /pkg/
4
+ /tmp/
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'cucumber'
4
+ gem 'aruba'
@@ -0,0 +1,3 @@
1
+ # Simple Cli App
2
+
3
+ This is a simple app to get started with `aruba`.
@@ -0,0 +1 @@
1
+ require 'aruba/cucumber'
@@ -1,3 +1,5 @@
1
+ require 'shellwords'
2
+
1
3
  module Aruba
2
4
  # Announcer
3
5
  #
@@ -78,10 +80,12 @@ module Aruba
78
80
  def after_init
79
81
  output_format :directory, '$ cd %s'
80
82
  output_format :command, '$ %s'
81
- output_format :environment, '$ export %s=%s"'
82
- output_format :modified_environment, '$ export %s=%s"'
83
+ output_format :environment, proc { |n, v| format('$ export %s=%s', n, Shellwords.escape(v)) }
84
+ output_format :modified_environment, proc { |n, v| format('$ export %s=%s', n, Shellwords.escape(v)) }
83
85
  output_format :full_environment, proc { |h| Aruba.platform.simple_table(h) }
84
86
  output_format :timeout, '# %s-timeout: %s seconds'
87
+ output_format :stderr, "<<-STDERR\n%s\nSTDERR"
88
+ output_format :stdout, "<<-STDOUT\n%s\nSTDOUT"
85
89
 
86
90
  # rubocop:disable Metrics/LineLength
87
91
  if @options[:stdout]
@@ -26,21 +26,5 @@ module Aruba
26
26
  include Aruba::Api::Filesystem
27
27
  include Aruba::Api::Rvm
28
28
  include Aruba::Api::Deprecated
29
-
30
- # Access to announcer
31
- def announcer
32
- @announcer ||= Announcer.new(
33
- self,
34
- :stdout => defined?(@announce_stdout),
35
- :stderr => defined?(@announce_stderr),
36
- :dir => defined?(@announce_dir),
37
- :cmd => defined?(@announce_cmd),
38
- :env => defined?(@announce_env)
39
- )
40
-
41
- @announcer
42
- end
43
-
44
- module_function :announcer
45
29
  end
46
30
  end
@@ -63,205 +63,19 @@ module Aruba
63
63
  file_name = expand_path(file_name)
64
64
 
65
65
  File.open(file_name, 'r').each_line do |line|
66
- last_command.write(line)
66
+ last_command_started.write(line)
67
67
  end
68
68
  end
69
69
 
70
- # Fetch output (stdout, stderr) from command
70
+ # Return all commands
71
71
  #
72
- # @param [String] cmd
73
- # The command
74
- def output_from(cmd)
75
- process_monitor.output_from(cmd)
76
- end
77
-
78
- # Fetch stdout from command
79
- #
80
- # @param [String] cmd
81
- # The command
82
- def stdout_from(cmd)
83
- process_monitor.stdout_from(cmd)
84
- end
85
-
86
- # Fetch stderr from command
87
- #
88
- # @param [String] cmd
89
- # The command
90
- def stderr_from(cmd)
91
- process_monitor.stderr_from(cmd)
92
- end
93
-
94
- # Get stdout of all processes
95
- #
96
- # @return [String]
97
- # The stdout of all process which have run before
98
- def all_stdout
99
- process_monitor.all_stdout
100
- end
101
-
102
- # Get stderr of all processes
103
- #
104
- # @return [String]
105
- # The stderr of all process which have run before
106
- def all_stderr
107
- process_monitor.all_stderr
108
- end
109
-
110
- # Get stderr and stdout of all processes
111
- #
112
- # @return [String]
113
- # The stderr and stdout of all process which have run before
114
- def all_output
115
- process_monitor.all_output
116
- end
117
-
118
- # Full compare arg1 and arg2
119
- #
120
- # @return [TrueClass, FalseClass]
121
- # If arg1 is exactly the same as arg2 return true, otherwise false
122
- def assert_exact_output(expected, actual)
123
- actual.force_encoding(expected.encoding) if RUBY_VERSION >= "1.9"
124
-
125
- actual = unescape_text(actual)
126
- actual = extract_text(actual) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences
127
-
128
- expected = unescape_text(expected)
129
- expected = extract_text(expected) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences
130
-
131
- expect(actual).to eq expected
132
- end
133
-
134
- # Partial compare arg1 and arg2
135
- #
136
- # @return [TrueClass, FalseClass]
137
- # If arg2 contains arg1 return true, otherwise false
138
- def assert_partial_output(expected, actual)
139
- actual.force_encoding(expected.encoding) if RUBY_VERSION >= "1.9"
140
-
141
- actual = unescape_text(actual)
142
- actual = extract_text(actual) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences
143
-
144
- expected = unescape_text(expected)
145
- expected = extract_text(expected) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences
146
-
147
- expect(actual).to include expected
148
- end
149
-
150
- # Regex Compare arg1 and arg2
151
- #
152
- # @return [TrueClass, FalseClass]
153
- # If arg2 matches arg1 return true, otherwise false
154
- def assert_matching_output(expected, actual)
155
- actual.force_encoding(expected.encoding) if RUBY_VERSION >= "1.9"
156
-
157
- actual = unescape_text(actual)
158
- actual = extract_text(actual) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences
159
-
160
- expected = unescape_text(expected)
161
- expected = extract_text(expected) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences
162
-
163
- expect(actual).to match Regexp.new(expected, Regexp::MULTILINE)
164
- end
165
-
166
- # Negative regex compare arg1 and arg2
167
- #
168
- # @return [TrueClass, FalseClass]
169
- # If arg2 does not match arg1 return true, otherwise false
170
- def assert_not_matching_output(expected, actual)
171
- actual.force_encoding(expected.encoding) if RUBY_VERSION >= "1.9"
172
-
173
- actual = unescape_text(actual)
174
- actual = extract_text(actual) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences
175
-
176
- expected = unescape_text(expected)
177
- expected = extract_text(expected) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences
178
-
179
- expect(actual).not_to match Regexp.new(expected, Regexp::MULTILINE)
180
- end
181
-
182
- # Negative partial compare arg1 and arg2
183
- #
184
- # @return [TrueClass, FalseClass]
185
- # If arg2 does not match/include arg1 return true, otherwise false
186
- # rubocop:disable Metrics/CyclomaticComplexity
187
- def assert_no_partial_output(unexpected, actual)
188
- actual.force_encoding(unexpected.encoding) if RUBY_VERSION >= "1.9"
189
-
190
- actual = unescape_text(actual)
191
- actual = extract_text(actual) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences
192
-
193
- if Regexp === unexpected
194
- expect(actual).not_to match unexpected
195
- else
196
- unexpected = unescape_text(unexpected)
197
- unexpected = extract_text(unexpected) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences
198
-
199
- expect(actual).not_to include(unexpected)
200
- end
201
- end
202
- # rubocop:enable Metrics/CyclomaticComplexity
203
-
204
- # Partial compare output of interactive command and arg1
205
- #
206
- # @return [TrueClass, FalseClass]
207
- # If output of interactive command includes arg1 return true, otherwise false
208
- def assert_partial_output_interactive(expected)
209
- actual = unescape_text(last_command.stdout)
210
- actual = extract_text(actual) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences
211
-
212
- expected = unescape_text(expected)
213
- expected = extract_text(expected) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences
214
-
215
- actual.include?(expected) ? true : false
216
- end
217
-
218
- # Check if command succeeded and if arg1 is included in output
219
- #
220
- # @return [TrueClass, FalseClass]
221
- # If exit status is 0 and arg1 is included in output return true, otherwise false
222
- def assert_passing_with(expected)
223
- assert_success(true)
224
- assert_partial_output(expected, all_output)
225
- end
226
-
227
- # Check if command failed and if arg1 is included in output
228
- #
229
- # @return [TrueClass, FalseClass]
230
- # If exit status is not equal 0 and arg1 is included in output return true, otherwise false
231
- def assert_failing_with(expected)
232
- assert_success(false)
233
- assert_partial_output(expected, all_output)
234
- end
235
-
236
- # Check exit status of process
237
- #
238
- # @return [TrueClass, FalseClass]
239
- # If arg1 is true, return true if command was successful
240
- # If arg1 is false, return true if command failed
241
- def assert_success(success)
242
- if success
243
- expect(last_command).to be_successfully_executed
244
- else
245
- expect(last_command).not_to be_successfully_executed
246
- end
247
- end
248
-
249
- # @private
250
- def assert_exit_status(status)
251
- expect(last_command).to have_exit_status(status)
252
- end
253
-
254
- # @private
255
- def assert_not_exit_status(status)
256
- expect(last_exit_status).not_to eq(status),
257
- append_output_to("Exit status was #{last_exit_status} which was not expected.")
72
+ # @return [Array]
73
+ # List of commands
74
+ def all_commands
75
+ process_monitor.all_commands
258
76
  end
259
77
 
260
78
  # @private
261
- def append_output_to(message)
262
- "#{message} Output:\n\n#{all_output}\n"
263
- end
264
-
265
79
  def process_monitor
266
80
  return @process_monitor if defined? @process_monitor
267
81
 
@@ -275,29 +89,48 @@ module Aruba
275
89
  process_monitor.send(:processes)
276
90
  end
277
91
 
278
- # @private
279
- def stop_processes!
280
- process_monitor.stop_processes!
92
+ # Last command started
93
+ def last_command_started
94
+ process_monitor.last_command_started
281
95
  end
282
96
 
283
- # Terminate all running processes
284
- def terminate_processes!
285
- process_monitor.terminate_processes!
97
+ # Last command stopped
98
+ def last_command_stopped
99
+ process_monitor.last_command_stopped
286
100
  end
287
101
 
288
- # @private
289
- def last_command
290
- processes.last[1]
291
- end
102
+ # Stop all commands
103
+ #
104
+ # @yield [Command]
105
+ # If block is given use it to filter the commands which should be
106
+ # stoppend.
107
+ def stop_all_commands(&block)
108
+ cmds = if block_given?
109
+ all_commands.select(&block)
110
+ else
111
+ all_commands
112
+ end
292
113
 
293
- # @private
294
- def register_process(*args)
295
- process_monitor.register_process(*args)
114
+ cmds.each { |c| c.stop(announcer) }
115
+
116
+ self
296
117
  end
297
118
 
298
- # @private
299
- def get_process(wanted)
300
- process_monitor.get_process(wanted)
119
+ # Terminate all commands
120
+ #
121
+ # @yield [Command]
122
+ # If block is given use it to filter the commands which should be
123
+ # terminated.
124
+ def terminate_all_commands(&block)
125
+ cmds = if block_given?
126
+ all_commands.select(&block)
127
+ else
128
+ all_commands
129
+ end
130
+
131
+ cmds.each(&:terminate)
132
+
133
+ self
301
134
  end
302
135
 
303
136
  # Run given command and stop it if timeout is reached
@@ -312,17 +145,18 @@ module Aruba
312
145
  # Run block with process
313
146
  #
314
147
  # rubocop:disable Metrics/MethodLength
315
- def run(cmd, timeout = nil)
316
- timeout ||= exit_timeout
148
+ def run(cmd, exit_timeout = nil, io_wait_timeout = nil)
149
+ exit_timeout ||= aruba.config.exit_timeout
150
+ io_wait_timeout ||= aruba.config.io_wait_timeout
151
+
317
152
  @commands ||= []
318
153
  @commands << cmd
319
154
 
320
- cmd = Aruba.platform.detect_ruby(cmd)
321
-
322
- announcer.announce(:directory, Dir.pwd)
323
155
  announcer.announce(:command, cmd)
324
- announcer.announce(:timeout, 'exit', aruba.config.exit_timeout)
325
- announcer.announce(:full_environment, aruba.environment.to_h)
156
+
157
+ cmd = Aruba.platform.detect_ruby(cmd)
158
+ environment = aruba.environment.to_h
159
+ working_directory = expand_path('.')
326
160
 
327
161
  mode = if Aruba.process
328
162
  # rubocop:disable Metrics/LineLength
@@ -341,13 +175,19 @@ module Aruba
341
175
  else
342
176
  aruba.config.main_class
343
177
  end
178
+
179
+ announcer.announce(:directory, working_directory)
180
+ announcer.announce(:timeout, 'exit', exit_timeout)
181
+ announcer.announce(:timeout, 'io wait', io_wait_timeout)
182
+ announcer.announce(:full_environment, environment)
183
+
344
184
  command = Command.new(
345
185
  cmd,
346
186
  :mode => mode,
347
- :exit_timeout => timeout,
348
- :io_wait_timeout => io_wait,
349
- :working_directory => expand_path('.'),
350
- :environment => aruba.environment.to_h,
187
+ :exit_timeout => exit_timeout,
188
+ :io_wait_timeout => io_wait_timeout,
189
+ :working_directory => working_directory,
190
+ :environment => environment,
351
191
  :main_class => main_class
352
192
  )
353
193
 
@@ -361,7 +201,7 @@ module Aruba
361
201
  aruba.config.before(:command, self, command)
362
202
 
363
203
  process_monitor.register_process(cmd, command)
364
- command.run!
204
+ command.start
365
205
 
366
206
  aruba.config.after(:command, self, command)
367
207
 
@@ -369,27 +209,6 @@ module Aruba
369
209
  end
370
210
  # rubocop:enable Metrics/MethodLength
371
211
 
372
- # Default exit timeout for running commands with aruba
373
- #
374
- # Overwrite this method if you want a different timeout or set
375
- # `@aruba_timeout_seconds`.
376
- def exit_timeout
377
- aruba.config.exit_timeout
378
- end
379
-
380
- # Default io wait timeout
381
- #
382
- # Overwrite this method if you want a different timeout or set
383
- # `@aruba_io_wait_seconds
384
- def io_wait
385
- aruba.config.io_wait_timeout
386
- end
387
-
388
- # The root directory of aruba
389
- def root_directory
390
- aruba.config.root_directory
391
- end
392
-
393
212
  # Run a command with aruba
394
213
  #
395
214
  # Checks for error during command execution and checks the output to detect
@@ -403,8 +222,8 @@ module Aruba
403
222
  #
404
223
  # @param [Integer] timeout
405
224
  # Timeout for execution
406
- def run_simple(cmd, fail_on_error = true, timeout = nil)
407
- command = run(cmd, timeout)
225
+ def run_simple(cmd, fail_on_error = true, exit_timeout = nil, io_wait_timeout = nil)
226
+ command = run(cmd, exit_timeout, io_wait_timeout)
408
227
  @last_exit_status = process_monitor.stop_process(command)
409
228
 
410
229
  @timed_out = command.timed_out?
@@ -421,33 +240,12 @@ module Aruba
421
240
  # The input for the command
422
241
  def type(input)
423
242
  return close_input if "" == input
424
- last_command.write(input << "\n")
243
+ last_command_started.write(input << "\n")
425
244
  end
426
245
 
427
246
  # Close stdin
428
247
  def close_input
429
- last_command.close_io(:stdin)
430
- end
431
-
432
- # Only processes
433
- def only_processes
434
- process_monitor.only_processes
435
- end
436
-
437
- # TODO: move some more methods under here!
438
-
439
- private
440
-
441
- def last_exit_status
442
- process_monitor.last_exit_status
443
- end
444
-
445
- def stop_process(process)
446
- @last_exit_status = process_monitor.stop_process(process)
447
- end
448
-
449
- def terminate_process(process)
450
- process_monitor.terminate_process(process)
248
+ last_command_started.close_io(:stdin)
451
249
  end
452
250
  end
453
251
  end