aruba 0.6.2 → 0.7.0
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/.gitignore +3 -0
- data/.rubocop.yml +167 -3
- data/.simplecov +32 -0
- data/.travis.yml +5 -2
- data/.yardopts +8 -0
- data/CONTRIBUTING.md +18 -8
- data/Gemfile +25 -0
- data/History.md +8 -0
- data/README.md +80 -18
- data/Rakefile +1 -1
- data/aruba.gemspec +6 -8
- data/cucumber.yml +5 -6
- data/features/debug.feature +15 -0
- data/features/file_system_commands.feature +14 -2
- data/features/fixtures/copy/file.txt +1 -0
- data/features/fixtures/fixtures-app/test.txt +1 -0
- data/features/fixtures/spawn_process/stderr.sh +3 -0
- data/features/interactive.feature +2 -2
- data/features/step_definitions/aruba_dev_steps.rb +1 -1
- data/features/support/custom_main.rb +10 -6
- data/features/support/env.rb +27 -2
- data/features/support/simplecov_setup.rb +8 -0
- data/lib/aruba.rb +2 -2
- data/lib/aruba/announcer.rb +161 -0
- data/lib/aruba/api.rb +490 -251
- data/lib/aruba/config.rb +0 -1
- data/lib/aruba/cucumber.rb +71 -59
- data/lib/aruba/cucumber/hooks.rb +18 -13
- data/lib/aruba/errors.rb +6 -0
- data/lib/aruba/in_process.rb +5 -45
- data/lib/aruba/matchers/command.rb +79 -0
- data/lib/aruba/matchers/directory.rb +59 -0
- data/lib/aruba/matchers/file.rb +177 -0
- data/lib/aruba/matchers/mode.rb +52 -0
- data/lib/aruba/matchers/path.rb +99 -0
- data/lib/aruba/matchers/rspec_matcher_include_regexp.rb +21 -1
- data/lib/aruba/process_monitor.rb +113 -0
- data/lib/aruba/processes/basic_process.rb +25 -0
- data/lib/aruba/processes/debug_process.rb +59 -0
- data/lib/aruba/processes/in_process.rb +86 -0
- data/lib/aruba/processes/spawn_process.rb +159 -0
- data/lib/aruba/reporting.rb +2 -2
- data/lib/aruba/rspec.rb +26 -0
- data/lib/aruba/spawn_process.rb +5 -104
- data/lib/aruba/utils.rb +21 -0
- data/script/bootstrap +22 -0
- data/script/console +17 -0
- data/script/test +3 -0
- data/spec/aruba/api_spec.rb +813 -147
- data/spec/aruba/hooks_spec.rb +0 -1
- data/spec/aruba/matchers/command_spec.rb +43 -0
- data/spec/aruba/matchers/directory_spec.rb +58 -0
- data/spec/aruba/matchers/file_spec.rb +131 -0
- data/spec/aruba/matchers/path_spec.rb +85 -0
- data/spec/aruba/spawn_process_spec.rb +46 -28
- data/spec/spec_helper.rb +18 -13
- data/{config/rubocop/include.yml → spec/support/configs/.keep} +0 -0
- data/spec/support/configs/rspec.rb +15 -0
- data/spec/support/helpers/.keep +0 -0
- data/spec/support/helpers/reporting.rb +44 -0
- data/spec/support/matchers/.keep +0 -0
- data/spec/support/shared_contexts/.keep +0 -0
- data/spec/support/shared_contexts/aruba.rb +45 -0
- data/spec/support/shared_examples/.keep +0 -0
- data/spec/support/shared_examples/directory.rb +7 -0
- data/spec/support/shared_examples/file.rb +7 -0
- data/templates/js/jquery-1.11.3.min.js +5 -0
- data/templates/main.erb +1 -1
- metadata +87 -96
- data/config/rubocop/exclude.yml +0 -160
- data/templates/js/jquery-1.6.1.min.js +0 -18
@@ -0,0 +1,25 @@
|
|
1
|
+
module Aruba
|
2
|
+
module Processes
|
3
|
+
class BasicProcess
|
4
|
+
def initialize(cmd, exit_timeout, io_wait, working_directory)
|
5
|
+
@working_directory = working_directory
|
6
|
+
end
|
7
|
+
|
8
|
+
# Output stderr and stdout
|
9
|
+
def output
|
10
|
+
stdout + stderr
|
11
|
+
end
|
12
|
+
|
13
|
+
# Was process already stopped
|
14
|
+
def stopped?
|
15
|
+
@stopped == true
|
16
|
+
end
|
17
|
+
|
18
|
+
# Hook which is run before command is run
|
19
|
+
def before_run; end
|
20
|
+
|
21
|
+
# Hook which is run after command is run
|
22
|
+
def after_run; end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'aruba/processes/spawn_process'
|
2
|
+
|
3
|
+
module Aruba
|
4
|
+
module Processes
|
5
|
+
# Create process
|
6
|
+
#
|
7
|
+
# @params [String] cmd
|
8
|
+
# Command string
|
9
|
+
#
|
10
|
+
# @params [Integer] exit_timeout
|
11
|
+
# The timeout until we expect the command to be finished
|
12
|
+
#
|
13
|
+
# @params [Integer] io_wait
|
14
|
+
# The timeout until we expect the io to be finished
|
15
|
+
#
|
16
|
+
# @params [String] working_directory
|
17
|
+
# The directory where the command will be executed
|
18
|
+
class DebugProcess < BasicProcess
|
19
|
+
attr_reader :exit_status
|
20
|
+
|
21
|
+
# @see SpawnProcess
|
22
|
+
def initialize(cmd, _exit_timeout, _io_wait, working_directory)
|
23
|
+
@cmd = cmd
|
24
|
+
@working_directory = working_directory
|
25
|
+
|
26
|
+
super
|
27
|
+
end
|
28
|
+
|
29
|
+
# Return command line
|
30
|
+
def commandline
|
31
|
+
@cmd
|
32
|
+
end
|
33
|
+
|
34
|
+
def run!
|
35
|
+
@exit_status = system(@cmd, chdir: @working_directory) ? 0 : 1
|
36
|
+
end
|
37
|
+
|
38
|
+
def stdin(*); end
|
39
|
+
|
40
|
+
def stdout(*)
|
41
|
+
''
|
42
|
+
end
|
43
|
+
|
44
|
+
def stderr(*)
|
45
|
+
''
|
46
|
+
end
|
47
|
+
|
48
|
+
def stop(_reader)
|
49
|
+
@stopped = true
|
50
|
+
|
51
|
+
@exit_status
|
52
|
+
end
|
53
|
+
|
54
|
+
def terminate(*)
|
55
|
+
stop
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'shellwords'
|
2
|
+
require 'stringio'
|
3
|
+
require 'aruba/processes/basic_process'
|
4
|
+
|
5
|
+
module Aruba
|
6
|
+
module Processes
|
7
|
+
class InProcess < BasicProcess
|
8
|
+
attr_reader :exit_status
|
9
|
+
|
10
|
+
class FakeKernel
|
11
|
+
attr_reader :exitstatus
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
@exitstatus = 0
|
15
|
+
end
|
16
|
+
|
17
|
+
def exit(exitstatus)
|
18
|
+
@exitstatus = exitstatus
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class << self
|
23
|
+
attr_accessor :main_class
|
24
|
+
end
|
25
|
+
|
26
|
+
def initialize(cmd, exit_timeout, io_wait, working_directory)
|
27
|
+
args = Shellwords.split(cmd)
|
28
|
+
@argv = args[1..-1]
|
29
|
+
@stdin = StringIO.new
|
30
|
+
@stdout = StringIO.new
|
31
|
+
@stderr = StringIO.new
|
32
|
+
@kernel = FakeKernel.new
|
33
|
+
|
34
|
+
super
|
35
|
+
end
|
36
|
+
|
37
|
+
# Return the commandline
|
38
|
+
def commandline
|
39
|
+
self.class.main_class.to_s + @argv.join(" ")
|
40
|
+
end
|
41
|
+
|
42
|
+
def run!
|
43
|
+
raise "You need to call Aruba::InProcess.main_class = YourMainClass" unless self.class.main_class
|
44
|
+
|
45
|
+
Dir.chdir @working_directory do
|
46
|
+
before_run
|
47
|
+
self.class.main_class.new(@argv, @stdin, @stdout, @stderr, @kernel).execute!
|
48
|
+
after_run
|
49
|
+
|
50
|
+
yield self if block_given?
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def stop(reader)
|
55
|
+
@stopped = true
|
56
|
+
@exit_status = @kernel.exitstatus
|
57
|
+
end
|
58
|
+
|
59
|
+
def stdin
|
60
|
+
@stdin.string
|
61
|
+
end
|
62
|
+
|
63
|
+
def stdout
|
64
|
+
@stdout.string
|
65
|
+
end
|
66
|
+
|
67
|
+
def stderr
|
68
|
+
@stderr.string
|
69
|
+
end
|
70
|
+
|
71
|
+
def write(input)
|
72
|
+
@stdin.write input
|
73
|
+
end
|
74
|
+
|
75
|
+
def close_io(name)
|
76
|
+
fail ArgumentError, 'Only stdin stdout and stderr are allowed to close' unless [:stdin, :stdout, :stderr].include? name
|
77
|
+
|
78
|
+
get_instance_variable(name.to_sym).close
|
79
|
+
end
|
80
|
+
|
81
|
+
def terminate
|
82
|
+
stop
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,159 @@
|
|
1
|
+
require 'childprocess'
|
2
|
+
require 'tempfile'
|
3
|
+
require 'shellwords'
|
4
|
+
require 'aruba/errors'
|
5
|
+
require 'aruba/processes/basic_process'
|
6
|
+
|
7
|
+
module Aruba
|
8
|
+
module Processes
|
9
|
+
class SpawnProcess < BasicProcess
|
10
|
+
attr_reader :exit_status
|
11
|
+
|
12
|
+
# Create process
|
13
|
+
#
|
14
|
+
# @params [String] cmd
|
15
|
+
# Command string
|
16
|
+
#
|
17
|
+
# @params [Integer] exit_timeout
|
18
|
+
# The timeout until we expect the command to be finished
|
19
|
+
#
|
20
|
+
# @params [Integer] io_wait
|
21
|
+
# The timeout until we expect the io to be finished
|
22
|
+
#
|
23
|
+
# @params [String] working_directory
|
24
|
+
# The directory where the command will be executed
|
25
|
+
def initialize(cmd, exit_timeout, io_wait, working_directory)
|
26
|
+
@exit_timeout = exit_timeout
|
27
|
+
@io_wait = io_wait
|
28
|
+
|
29
|
+
@cmd = cmd
|
30
|
+
@process = nil
|
31
|
+
@exit_status = nil
|
32
|
+
@output_cache = nil
|
33
|
+
@error_cache = nil
|
34
|
+
|
35
|
+
super
|
36
|
+
end
|
37
|
+
|
38
|
+
# Return command line
|
39
|
+
def commandline
|
40
|
+
@cmd
|
41
|
+
end
|
42
|
+
|
43
|
+
# Run the command
|
44
|
+
#
|
45
|
+
# @yield [SpawnProcess]
|
46
|
+
# Run code for process which was started
|
47
|
+
def run!
|
48
|
+
@process = ChildProcess.build(*Shellwords.split(@cmd))
|
49
|
+
@out = Tempfile.new("aruba-out")
|
50
|
+
@err = Tempfile.new("aruba-err")
|
51
|
+
@exit_status = nil
|
52
|
+
@duplex = true
|
53
|
+
|
54
|
+
before_run
|
55
|
+
|
56
|
+
@process.io.stdout = @out
|
57
|
+
@process.io.stderr = @err
|
58
|
+
@process.duplex = @duplex
|
59
|
+
@process.cwd = @working_directory
|
60
|
+
|
61
|
+
begin
|
62
|
+
@process.start
|
63
|
+
rescue ChildProcess::LaunchError => e
|
64
|
+
raise LaunchError, e.message
|
65
|
+
end
|
66
|
+
|
67
|
+
after_run
|
68
|
+
|
69
|
+
yield self if block_given?
|
70
|
+
end
|
71
|
+
|
72
|
+
def stdin
|
73
|
+
@process.io.stdin
|
74
|
+
end
|
75
|
+
|
76
|
+
def stdout
|
77
|
+
wait_for_io do
|
78
|
+
@process.io.stdout.flush
|
79
|
+
read(@out)
|
80
|
+
end || @output_cache
|
81
|
+
end
|
82
|
+
|
83
|
+
def stderr
|
84
|
+
wait_for_io do
|
85
|
+
@process.io.stderr.flush
|
86
|
+
read(@err)
|
87
|
+
end || @error_cache
|
88
|
+
end
|
89
|
+
|
90
|
+
def read_stdout
|
91
|
+
warn('The use of "#read_stdout" is deprecated. Use "#stdout" instead.')
|
92
|
+
stdout
|
93
|
+
end
|
94
|
+
|
95
|
+
def write(input)
|
96
|
+
@process.io.stdin.write(input)
|
97
|
+
@process.io.stdin.flush
|
98
|
+
end
|
99
|
+
|
100
|
+
def close_io(name)
|
101
|
+
@process.io.public_send(name.to_sym).close
|
102
|
+
end
|
103
|
+
|
104
|
+
def stop(reader)
|
105
|
+
@stopped = true
|
106
|
+
|
107
|
+
return @exit_status unless @process
|
108
|
+
|
109
|
+
@process.poll_for_exit(@exit_timeout) unless @process.exited?
|
110
|
+
|
111
|
+
@exit_status = @process.exit_code
|
112
|
+
@process = nil
|
113
|
+
|
114
|
+
close_and_cache_out
|
115
|
+
close_and_cache_err
|
116
|
+
|
117
|
+
if reader
|
118
|
+
reader.stdout stdout
|
119
|
+
reader.stderr stderr
|
120
|
+
end
|
121
|
+
|
122
|
+
@exit_status
|
123
|
+
end
|
124
|
+
|
125
|
+
def terminate
|
126
|
+
return unless @process
|
127
|
+
|
128
|
+
@process.stop
|
129
|
+
stop nil
|
130
|
+
end
|
131
|
+
|
132
|
+
private
|
133
|
+
|
134
|
+
def wait_for_io(&block)
|
135
|
+
return unless @process
|
136
|
+
|
137
|
+
sleep @io_wait
|
138
|
+
yield
|
139
|
+
end
|
140
|
+
|
141
|
+
def read(io)
|
142
|
+
io.rewind
|
143
|
+
io.read
|
144
|
+
end
|
145
|
+
|
146
|
+
def close_and_cache_out
|
147
|
+
@output_cache = read @out
|
148
|
+
@out.close
|
149
|
+
@out = nil
|
150
|
+
end
|
151
|
+
|
152
|
+
def close_and_cache_err
|
153
|
+
@error_cache = read @err
|
154
|
+
@err.close
|
155
|
+
@err = nil
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
data/lib/aruba/reporting.rb
CHANGED
@@ -19,7 +19,7 @@ if(ENV['ARUBA_REPORT_DIR'])
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def pygmentize(file)
|
22
|
-
pygmentize = SpawnProcess.new(%{pygmentize -f html -O encoding=utf-8 "#{file}"}, 3, 0.5)
|
22
|
+
pygmentize = Processes::SpawnProcess.new(%{pygmentize -f html -O encoding=utf-8 "#{file}"}, 3, 0.5, Dir.getwd)
|
23
23
|
pygmentize.run! do |p|
|
24
24
|
exit_status = p.stop(false)
|
25
25
|
if(exit_status == 0)
|
@@ -64,7 +64,7 @@ if(ENV['ARUBA_REPORT_DIR'])
|
|
64
64
|
|
65
65
|
def files
|
66
66
|
erb = ERB.new(template('files.erb'), nil, '-')
|
67
|
-
file =
|
67
|
+
file = current_directory
|
68
68
|
erb.result(binding)
|
69
69
|
end
|
70
70
|
|
data/lib/aruba/rspec.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'rspec/core'
|
2
|
+
require 'aruba/api'
|
3
|
+
require 'aruba/reporting'
|
4
|
+
|
5
|
+
RSpec.configure do |config|
|
6
|
+
config.include Aruba::Api, type: :aruba
|
7
|
+
|
8
|
+
config.before :each do
|
9
|
+
next unless self.class.include?(Aruba::Api)
|
10
|
+
|
11
|
+
restore_env
|
12
|
+
clean_current_directory
|
13
|
+
end
|
14
|
+
|
15
|
+
# config.before do
|
16
|
+
# next unless self.class.include?(Aruba::Api)
|
17
|
+
|
18
|
+
# current_example = context.example
|
19
|
+
|
20
|
+
# announcer.activate(:environment) if current_example.metadata[:announce_env]
|
21
|
+
# announcer.activate(:command) if current_example.metadata[:announce_cmd]
|
22
|
+
# announcer.activate(:directory) if current_example.metadata[:announce_dir]
|
23
|
+
# announcer.activate(:stdout) if current_example.metadata[:announce_stdout]
|
24
|
+
# announcer.activate(:stderr) if current_example.metadata[:announce_stderr]
|
25
|
+
# end
|
26
|
+
end
|
data/lib/aruba/spawn_process.rb
CHANGED
@@ -1,110 +1,11 @@
|
|
1
|
-
require '
|
2
|
-
require 'tempfile'
|
3
|
-
require 'shellwords'
|
4
|
-
require 'aruba/errors'
|
1
|
+
require 'aruba/processes/spawn_process'
|
5
2
|
|
6
3
|
module Aruba
|
7
|
-
class SpawnProcess
|
8
|
-
|
4
|
+
class SpawnProcess < Aruba::Processes::SpawnProcess
|
5
|
+
def initialize(*args)
|
6
|
+
warn('The use of "Aruba::SpawnProcess" is deprecated. Use "Aruba::Processes::SpawnProcess" instead.')
|
9
7
|
|
10
|
-
|
11
|
-
@exit_timeout = exit_timeout
|
12
|
-
@io_wait = io_wait
|
13
|
-
|
14
|
-
@cmd = cmd
|
15
|
-
@process = nil
|
16
|
-
@exit_code = nil
|
17
|
-
@output_cache = nil
|
18
|
-
@error_cache = nil
|
19
|
-
end
|
20
|
-
|
21
|
-
def run!(&block)
|
22
|
-
@process = ChildProcess.build(*shellwords(@cmd))
|
23
|
-
@out = Tempfile.new("aruba-out")
|
24
|
-
@err = Tempfile.new("aruba-err")
|
25
|
-
@process.io.stdout = @out
|
26
|
-
@process.io.stderr = @err
|
27
|
-
@process.duplex = true
|
28
|
-
@exit_code = nil
|
29
|
-
begin
|
30
|
-
@process.start
|
31
|
-
rescue ChildProcess::LaunchError => e
|
32
|
-
raise LaunchError.new(e.message)
|
33
|
-
end
|
34
|
-
yield self if block_given?
|
35
|
-
end
|
36
|
-
|
37
|
-
def stdin
|
38
|
-
@process.io.stdin
|
39
|
-
end
|
40
|
-
|
41
|
-
def output
|
42
|
-
stdout + stderr
|
8
|
+
super
|
43
9
|
end
|
44
|
-
|
45
|
-
def stdout
|
46
|
-
wait_for_io { read(@out) } || @output_cache
|
47
|
-
end
|
48
|
-
|
49
|
-
def stderr
|
50
|
-
wait_for_io { read(@err) } || @error_cache
|
51
|
-
end
|
52
|
-
|
53
|
-
def read_stdout
|
54
|
-
wait_for_io do
|
55
|
-
@process.io.stdout.flush
|
56
|
-
open(@out.path).read
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
def stop(reader)
|
61
|
-
return @exit_code unless @process
|
62
|
-
unless @process.exited?
|
63
|
-
@process.poll_for_exit(@exit_timeout)
|
64
|
-
end
|
65
|
-
@exit_code = @process.exit_code
|
66
|
-
@process = nil
|
67
|
-
close_and_cache_out
|
68
|
-
close_and_cache_err
|
69
|
-
if reader
|
70
|
-
reader.stdout stdout
|
71
|
-
reader.stderr stderr
|
72
|
-
end
|
73
|
-
@exit_code
|
74
|
-
end
|
75
|
-
|
76
|
-
def terminate
|
77
|
-
if @process
|
78
|
-
@process.stop
|
79
|
-
stop nil
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
private
|
84
|
-
|
85
|
-
def wait_for_io(&block)
|
86
|
-
if @process
|
87
|
-
sleep @io_wait
|
88
|
-
yield
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
def read(io)
|
93
|
-
io.rewind
|
94
|
-
io.read
|
95
|
-
end
|
96
|
-
|
97
|
-
def close_and_cache_out
|
98
|
-
@output_cache = read @out
|
99
|
-
@out.close
|
100
|
-
@out = nil
|
101
|
-
end
|
102
|
-
|
103
|
-
def close_and_cache_err
|
104
|
-
@error_cache = read @err
|
105
|
-
@err.close
|
106
|
-
@err = nil
|
107
|
-
end
|
108
|
-
|
109
10
|
end
|
110
11
|
end
|