aruba 0.10.2 → 0.11.0.pre

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 (35) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +6 -5
  3. data/Gemfile +0 -4
  4. data/History.md +17 -1
  5. data/features/api/command/run.feature +101 -1
  6. data/features/api/command/send_signal.feature +53 -0
  7. data/features/api/command/stop.feature +79 -0
  8. data/features/api/text/replace_variables.feature +45 -0
  9. data/features/configuration/startup_wait_time.feature +48 -0
  10. data/features/step_definitions/hooks.rb +85 -6
  11. data/features/steps/{commands → command}/exit_statuses.feature +0 -0
  12. data/features/steps/{commands → command}/in_process.feature +174 -0
  13. data/features/steps/{commands → command}/run.feature +1 -0
  14. data/features/steps/command/send_signal.feature +104 -0
  15. data/features/steps/command/stop.feature +313 -0
  16. data/features/steps/overview.feature +60 -0
  17. data/lib/aruba/announcer.rb +2 -0
  18. data/lib/aruba/api/command.rb +24 -9
  19. data/lib/aruba/api/text.rb +9 -0
  20. data/lib/aruba/command.rb +4 -1
  21. data/lib/aruba/config.rb +2 -0
  22. data/lib/aruba/cucumber/command.rb +75 -0
  23. data/lib/aruba/cucumber/core.rb +0 -24
  24. data/lib/aruba/cucumber/hooks.rb +10 -0
  25. data/lib/aruba/errors.rb +3 -0
  26. data/lib/aruba/matchers/command/have_output.rb +1 -1
  27. data/lib/aruba/process_monitor.rb +25 -1
  28. data/lib/aruba/processes/basic_process.rb +22 -2
  29. data/lib/aruba/processes/debug_process.rb +7 -1
  30. data/lib/aruba/processes/in_process.rb +15 -1
  31. data/lib/aruba/processes/null_process.rb +26 -0
  32. data/lib/aruba/processes/spawn_process.rb +81 -48
  33. data/lib/aruba/rspec.rb +6 -0
  34. data/lib/aruba/version.rb +1 -1
  35. metadata +26 -11
@@ -0,0 +1,60 @@
1
+ Feature: Overview of steps
2
+
3
+ Given you're a system administrator
4
+ Who would like to use `aruba`
5
+ But didn't know which steps are available
6
+
7
+ Background:
8
+ Given I use a fixture named "cli-app"
9
+
10
+ Scenario: Use information found in repository
11
+ Given an executable named "bin/cli" with:
12
+ """
13
+ #!/bin/bash
14
+ git clone https://github.com/cucumber/aruba.git
15
+ cd aruba
16
+ grep -E "When|Given|Then" lib/aruba/cucumber/*.rb | awk -F ":" '{ $1 = ""; print $0}' |sort
17
+ """
18
+ And a file named "features/run.feature" with:
19
+ """
20
+ Feature: Run it
21
+ Scenario: Run command
22
+ When I run `cli`
23
+ Then the output should contain:
24
+ \"\"\"
25
+ Cloning into 'aruba'...
26
+ \"\"\"
27
+ And the output should contain:
28
+ \"\"\"
29
+ Given(/^
30
+ \"\"\"
31
+ And the output should contain:
32
+ \"\"\"
33
+ When(/^
34
+ \"\"\"
35
+ And the output should contain:
36
+ \"\"\"
37
+ Then(/^
38
+ \"\"\"
39
+ """
40
+ When I run `cucumber`
41
+ Then the features should all pass
42
+
43
+ Scenario: Use cucumber output formatter
44
+ Given a file named "features/run.feature" with:
45
+ """
46
+ Feature: Run it
47
+ Scenario: Run command
48
+ Given a directory named "features"
49
+ And a file named "features/support/env.rb" with:
50
+ \"\"\"
51
+ require 'aruba/cucumber'
52
+ \"\"\"
53
+ When I run `cucumber --format stepdefs`
54
+ Then the output should contain:
55
+ \"\"\"
56
+ NOT MATCHED BY ANY STEPS
57
+ \"\"\"
58
+ """
59
+ When I run `cucumber`
60
+ Then the features should all pass
@@ -84,6 +84,8 @@ module Aruba
84
84
  output_format :modified_environment, proc { |n, v| format('$ export %s=%s', n, Shellwords.escape(v)) }
85
85
  output_format :full_environment, proc { |h| Aruba.platform.simple_table(h) }
86
86
  output_format :timeout, '# %s-timeout: %s seconds'
87
+ output_format :wait_time, '# %s: %s seconds'
88
+ output_format :stop_signal, proc { |p, s| format('Command will be stopped with `kill -%s %s`', s, p) }
87
89
  output_format :stderr, "<<-STDERR\n%s\nSTDERR"
88
90
  output_format :stdout, "<<-STDOUT\n%s\nSTDOUT"
89
91
 
@@ -122,22 +122,37 @@ module Aruba
122
122
  # @param [Integer] timeout
123
123
  # If the timeout is reached the command will be killed
124
124
  #
125
+ # @param [String] stop_signal
126
+ # Use signal to stop command (Private)
127
+ #
125
128
  # @yield [SpawnProcess]
126
129
  # Run block with process
127
130
  #
128
131
  # rubocop:disable Metrics/MethodLength
129
- def run(cmd, exit_timeout = nil, io_wait_timeout = nil)
132
+ # rubocop:disable Metrics/CyclomaticComplexity
133
+ def run(cmd, exit_timeout = nil, io_wait_timeout = nil, stop_signal = nil, startup_wait_time = nil)
130
134
  exit_timeout ||= aruba.config.exit_timeout
131
135
  io_wait_timeout ||= aruba.config.io_wait_timeout
136
+ stop_signal ||= aruba.config.stop_signal
137
+ startup_wait_time ||= aruba.config.startup_wait_time
138
+
139
+ cmd = replace_variables(cmd)
132
140
 
133
141
  @commands ||= []
134
142
  @commands << cmd
135
143
 
144
+ environment = aruba.environment.to_h
145
+ working_directory = expand_path('.')
146
+
147
+ announcer.announce(:full_environment, environment)
148
+ announcer.announce(:timeout, 'exit', exit_timeout)
149
+ announcer.announce(:timeout, 'io wait', io_wait_timeout)
150
+ announcer.announce(:wait_time, 'startup wait time', startup_wait_time)
151
+
152
+ announcer.announce(:directory, working_directory)
136
153
  announcer.announce(:command, cmd)
137
154
 
138
155
  cmd = Aruba.platform.detect_ruby(cmd)
139
- environment = aruba.environment.to_h
140
- working_directory = expand_path('.')
141
156
 
142
157
  mode = if Aruba.process
143
158
  # rubocop:disable Metrics/LineLength
@@ -157,11 +172,6 @@ module Aruba
157
172
  aruba.config.main_class
158
173
  end
159
174
 
160
- announcer.announce(:directory, working_directory)
161
- announcer.announce(:timeout, 'exit', exit_timeout)
162
- announcer.announce(:timeout, 'io wait', io_wait_timeout)
163
- announcer.announce(:full_environment, environment)
164
-
165
175
  command = Command.new(
166
176
  cmd,
167
177
  :mode => mode,
@@ -169,7 +179,9 @@ module Aruba
169
179
  :io_wait_timeout => io_wait_timeout,
170
180
  :working_directory => working_directory,
171
181
  :environment => environment,
172
- :main_class => main_class
182
+ :main_class => main_class,
183
+ :stop_signal => stop_signal,
184
+ :startup_wait_time => startup_wait_time
173
185
  )
174
186
 
175
187
  if aruba.config.before? :cmd
@@ -184,10 +196,13 @@ module Aruba
184
196
  process_monitor.register_process(cmd, command)
185
197
  command.start
186
198
 
199
+ announcer.announce(:stop_signal, command.pid, stop_signal) if stop_signal
200
+
187
201
  aruba.config.after(:command, self, command)
188
202
 
189
203
  block_given? ? yield(command) : command
190
204
  end
205
+ # rubocop:enable Metrics/CyclomaticComplexity
191
206
  # rubocop:enable Metrics/MethodLength
192
207
 
193
208
  # Run a command with aruba
@@ -36,6 +36,15 @@ module Aruba
36
36
 
37
37
  text.chomp
38
38
  end
39
+
40
+ # @experimental
41
+ #
42
+ # Replace variables in command string
43
+ def replace_variables(text)
44
+ text = text.gsub(/<pid-last-command-started>/, last_command_started.pid.to_s)
45
+
46
+ text
47
+ end
39
48
  end
40
49
  end
41
50
  end
data/lib/aruba/command.rb CHANGED
@@ -8,6 +8,7 @@ module Aruba
8
8
  launchers = []
9
9
  launchers << Processes::DebugProcess
10
10
  launchers << Processes::InProcess
11
+ launchers << Processes::NullProcess
11
12
  launchers << Processes::SpawnProcess
12
13
 
13
14
  launcher = launchers.find { |l| l.match? opts[:mode] }
@@ -18,7 +19,9 @@ module Aruba
18
19
  opts.fetch(:io_wait_timeout),
19
20
  opts.fetch(:working_directory),
20
21
  opts.fetch(:environment),
21
- opts.fetch(:main_class)
22
+ opts.fetch(:main_class),
23
+ opts.fetch(:stop_signal),
24
+ opts.fetch(:startup_wait_time)
22
25
  )
23
26
  rescue KeyError => e
24
27
  raise ArgumentError, e.message
data/lib/aruba/config.rb CHANGED
@@ -29,7 +29,9 @@ module Aruba
29
29
  end
30
30
 
31
31
  option_accessor :exit_timeout, :contract => { Num => Num }, :default => 15
32
+ option_accessor :stop_signal, :contract => { Maybe[String] => Maybe[String] }, :default => nil
32
33
  option_accessor :io_wait_timeout, :contract => { Num => Num }, :default => 0.1
34
+ option_accessor :startup_wait_time, :contract => { Num => Num }, :default => 0
33
35
  option_accessor :fixtures_directories, :contract => { Array => ArrayOf[String] }, :default => %w(features/fixtures spec/fixtures test/fixtures fixtures)
34
36
  option_accessor :command_runtime_environment, :contract => { Hash => Hash }, :default => ENV.to_hash.dup
35
37
  # rubocop:disable Metrics/LineLength
@@ -1,3 +1,7 @@
1
+ if Aruba::VERSION < '1.0.0'
2
+ require 'aruba/cucumber/core'
3
+ end
4
+
1
5
  When(/^I run "(.*)"$/)do |cmd|
2
6
  warn(%{\e[35m The /^I run "(.*)"$/ step definition is deprecated. Please use the `backticks` version\e[0m})
3
7
 
@@ -35,6 +39,11 @@ When(/^I run `([^`]*)` interactively$/)do |cmd|
35
39
  @interactive = run(cmd)
36
40
  end
37
41
 
42
+ # Merge interactive and background after refactoring with event queue
43
+ When(/^I run `([^`]*)` in background$/)do |cmd|
44
+ run(sanitize_text(cmd))
45
+ end
46
+
38
47
  When(/^I type "([^"]*)"$/) do |input|
39
48
  type(unescape_text(input))
40
49
  end
@@ -49,6 +58,29 @@ When(/^I pipe in (?:a|the) file(?: named)? "([^"]*)"$/) do |file|
49
58
  close_input
50
59
  end
51
60
 
61
+ When(/^I (terminate|stop) the command (?:"([^"]*)"|(?:started last))$/) do |signal, command|
62
+ if command
63
+ cmd = all_commands.find { |c| c.commandline == command }
64
+ fail ArgumentError, %(No command "#{command}" found) if cmd.nil?
65
+
66
+ if signal == 'terminate'
67
+ # last_command_started.terminate
68
+ process_monitor.terminate_process!(process_monitor.get_process(command))
69
+ else
70
+ # last_command_started.stop
71
+ process_monitor.stop_process(process_monitor.get_process(command))
72
+ end
73
+ else
74
+ if signal == 'terminate'
75
+ # last_command_started.terminate
76
+ process_monitor.terminate_process!(last_command_started)
77
+ else
78
+ # last_command_started.stop
79
+ process_monitor.stop_process(last_command_started)
80
+ end
81
+ end
82
+ end
83
+
52
84
  When(/^I stop the command(?: started last)? if (output|stdout|stderr) contains:$/) do |channel, expected|
53
85
  fail %(Invalid output channel "#{channel}" chosen. Please choose one of "output, stdout or stderr") unless %w(output stdout stderr).include? channel
54
86
 
@@ -332,3 +364,46 @@ Then(/^(?:the )?(output|stdout|stderr) should( not)? contain all of these lines:
332
364
  end
333
365
  end
334
366
  end
367
+
368
+ Given(/the default aruba timeout is (\d+) seconds/) do |seconds|
369
+ # rubocop:disable Metrics/LineLength
370
+ Aruba.platform.deprecated(%{The /^the default aruba timeout is (\d+) seconds/ step definition is deprecated. Please use /^the default aruba exit timeout is (\d+) seconds/ step definition is deprecated.})
371
+ # rubocop:enable Metrics/LineLength
372
+
373
+ aruba.config.exit_timeout = seconds.to_i
374
+ end
375
+
376
+ Given(/The default aruba timeout is (\d+) seconds/) do |seconds|
377
+ # rubocop:disable Metrics/LineLength
378
+ Aruba.platform.deprecated(%{The /^The default aruba timeout is (\d+) seconds/ step definition is deprecated. Please use /^the default aruba exit timeout is (\d+) seconds/ step definition is deprecated.})
379
+ # rubocop:enable Metrics/LineLength
380
+
381
+ aruba.config.exit_timeout = seconds.to_i
382
+ end
383
+
384
+ Given(/^the (?:default )?aruba io wait timeout is (\d+) seconds?$/) do |seconds|
385
+ aruba.config.io_wait_timeout = seconds.to_i
386
+ end
387
+
388
+ Given(/^the (?:default )?aruba exit timeout is (\d+) seconds?$/) do |seconds|
389
+ aruba.config.exit_timeout = seconds.to_i
390
+ end
391
+
392
+ Given(/^the (?:default )?aruba stop signal is "([^"]*)"$/) do |signal|
393
+ aruba.config.stop_signal = signal
394
+ end
395
+
396
+ Given(/^I wait (\d+) seconds? for (?:a|the) command to start up$/) do |seconds|
397
+ aruba.config.startup_wait_time = seconds.to_i
398
+ end
399
+
400
+ When(/^I send the signal "([^"]*)" to the command (?:"([^"]*)"|(?:started last))$/) do |signal, command|
401
+ if command
402
+ cmd = all_commands.find { |c| c.commandline == command }
403
+ fail ArgumentError, %(No command "#{command}" found) if cmd.nil?
404
+
405
+ cmd.send_signal signal
406
+ else
407
+ last_command_started.send_signal signal
408
+ end
409
+ end
@@ -3,27 +3,3 @@ if Aruba::VERSION >= '1.0.0'
3
3
  config.working_directory = 'tmp/cucumber'
4
4
  end
5
5
  end
6
-
7
- Given(/the default aruba timeout is (\d+) seconds/) do |seconds|
8
- # rubocop:disable Metrics/LineLength
9
- Aruba.platform.deprecated(%{The /^the default aruba timeout is (\d+) seconds/ step definition is deprecated. Please use /^the default aruba exit timeout is (\d+) seconds/ step definition is deprecated.})
10
- # rubocop:enable Metrics/LineLength
11
-
12
- aruba.config.exit_timeout = seconds.to_i
13
- end
14
-
15
- Given(/The default aruba timeout is (\d+) seconds/) do |seconds|
16
- # rubocop:disable Metrics/LineLength
17
- Aruba.platform.deprecated(%{The /^The default aruba timeout is (\d+) seconds/ step definition is deprecated. Please use /^the default aruba exit timeout is (\d+) seconds/ step definition is deprecated.})
18
- # rubocop:enable Metrics/LineLength
19
-
20
- aruba.config.exit_timeout = seconds.to_i
21
- end
22
-
23
- Given(/the default aruba io wait timeout is (\d+) seconds/) do |seconds|
24
- aruba.config.io_wait_timeout = seconds.to_i
25
- end
26
-
27
- Given(/the default aruba exit timeout is (\d+) seconds/) do |seconds|
28
- aruba.config.exit_timeout = seconds.to_i
29
- end
@@ -65,6 +65,10 @@ Before('@announce-directory') do
65
65
  announcer.activate :directory
66
66
  end
67
67
 
68
+ Before('@announce-stop-signal') do
69
+ announcer.activate :stop_signal
70
+ end
71
+
68
72
  Before('@announce-env') do
69
73
  Aruba.platform.deprecated 'The use of "@announce-env"-hook is deprecated. Please use "@announce-modified-environment"'
70
74
 
@@ -89,6 +93,10 @@ Before('@announce-timeout') do
89
93
  announcer.activate :timeout
90
94
  end
91
95
 
96
+ Before('@announce-wait-time') do
97
+ announcer.activate :wait_time
98
+ end
99
+
92
100
  Before('@announce') do
93
101
  announcer.activate :command
94
102
  announcer.activate :stdout
@@ -98,6 +106,8 @@ Before('@announce') do
98
106
  announcer.activate :full_environment
99
107
  announcer.activate :environment
100
108
  announcer.activate :timeout
109
+ announcer.activate :wait_time
110
+ announcer.activate :stop_signal
101
111
  end
102
112
 
103
113
  Before('@debug') do
data/lib/aruba/errors.rb CHANGED
@@ -10,4 +10,7 @@ module Aruba
10
10
 
11
11
  # Raised if one tries to use an unknown configuration option
12
12
  class UnknownOptionError < ArgumentError; end
13
+
14
+ # Rais if command already died
15
+ class CommandAlreadyStoppedError < Error; end
13
16
  end
@@ -28,7 +28,7 @@ RSpec::Matchers.define :have_output do |expected|
28
28
  :env => @announce_env
29
29
  )
30
30
 
31
- @old_actual.stop(@announcer) unless @old_actual.stopped?
31
+ @old_actual.stop(@announcer)
32
32
 
33
33
  @actual = sanitize_text(actual.output)
34
34
 
@@ -1,3 +1,5 @@
1
+ require 'aruba/processes/null_process'
2
+
1
3
  module Aruba
2
4
  class ProcessMonitor
3
5
  private
@@ -21,6 +23,16 @@ module Aruba
21
23
 
22
24
  def last_command_stopped
23
25
  return @last_command_stopped if @last_command_stopped
26
+ return Command.new('false',
27
+ :mode => :null,
28
+ :exit_timeout => 0,
29
+ :io_wait_timeout => 0,
30
+ :working_directory => '/tmp',
31
+ :environment => {},
32
+ :main_class => nil,
33
+ :stop_signal => nil,
34
+ :startup_wait_time => nil
35
+ ) if all_commands.empty?
24
36
 
25
37
  all_commands.each { |c| stop_process(c) }
26
38
 
@@ -28,6 +40,17 @@ module Aruba
28
40
  end
29
41
 
30
42
  def last_command_started
43
+ return Command.new('false',
44
+ :mode => :null,
45
+ :exit_timeout => 0,
46
+ :io_wait_timeout => 0,
47
+ :working_directory => '/tmp',
48
+ :environment => {},
49
+ :main_class => nil,
50
+ :stop_signal => nil,
51
+ :startup_wait_time => nil
52
+ ) unless processes.last.is_a? Array
53
+
31
54
  processes.last[1]
32
55
  end
33
56
 
@@ -37,7 +60,8 @@ module Aruba
37
60
  end
38
61
 
39
62
  def terminate_process!(process)
40
- process.terminate
63
+ @last_command_stopped = process
64
+ @last_exit_status = process.terminate
41
65
  end
42
66
 
43
67
  def stop_processes!
@@ -3,15 +3,22 @@ require 'shellwords'
3
3
 
4
4
  module Aruba
5
5
  module Processes
6
+ # Basic Process
7
+ #
8
+ # `BasicProcess` is not meant for direct use - `BasicProcess.new` - by users.
9
+ #
10
+ # @private
6
11
  class BasicProcess
7
- attr_reader :exit_status, :environment
12
+ attr_reader :exit_status, :environment, :startup_wait_time
8
13
 
9
- def initialize(cmd, exit_timeout, io_wait, working_directory, environment = ENV.to_hash.dup, main_class = nil)
14
+ def initialize(cmd, exit_timeout, io_wait, working_directory, environment = ENV.to_hash.dup, main_class = nil, stop_signal = nil, startup_wait_time = 0)
10
15
  @cmd = cmd
11
16
  @working_directory = working_directory
12
17
  @environment = environment
13
18
  @main_class = main_class
14
19
  @exit_status = nil
20
+ @stop_signal = stop_signal
21
+ @startup_wait_time = startup_wait_time
15
22
 
16
23
  @exit_timeout = exit_timeout
17
24
  @io_wait = io_wait
@@ -22,6 +29,11 @@ module Aruba
22
29
  @cmd
23
30
  end
24
31
 
32
+ # Output pid of process
33
+ def pid
34
+ 'No implemented'
35
+ end
36
+
25
37
  # Output stderr and stdout
26
38
  def output(opts = {})
27
39
  stdout(opts) + stderr(opts)
@@ -47,6 +59,14 @@ module Aruba
47
59
  NotImplementedError
48
60
  end
49
61
 
62
+ def send_signal(*)
63
+ NotImplementedError
64
+ end
65
+
66
+ def wait
67
+ NotImplementedError
68
+ end
69
+
50
70
  # Was process already stopped
51
71
  def stopped?
52
72
  @stopped == true