aruba 1.0.0.pre.alpha.3 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +0 -1
- data/.rubocop.yml +40 -1
- data/.rubocop_todo.yml +106 -254
- data/.simplecov +7 -5
- data/.travis.yml +25 -38
- data/CHANGELOG.md +246 -46
- data/CONTRIBUTING.md +8 -17
- data/Gemfile +5 -54
- data/LICENSE +1 -1
- data/README.md +37 -30
- data/Rakefile +23 -50
- data/appveyor.yml +4 -8
- data/aruba.gemspec +34 -13
- data/bin/console +1 -1
- data/cucumber.yml +4 -15
- data/exe/aruba +1 -1
- data/fixtures/cli-app/bin/aruba-test-cli +1 -1
- data/fixtures/cli-app/cli-app.gemspec +4 -5
- data/fixtures/cli-app/lib/cli/app.rb +1 -1
- data/fixtures/cli-app/spec/spec_helper.rb +3 -2
- data/fixtures/empty-app/cli-app.gemspec +4 -5
- data/fixtures/empty-app/lib/cli/app.rb +0 -2
- data/fixtures/getting-started-app/Gemfile +1 -1
- data/lib/aruba/api.rb +6 -6
- data/lib/aruba/api/bundler.rb +1 -1
- data/lib/aruba/api/commands.rb +36 -13
- data/lib/aruba/api/core.rb +74 -47
- data/lib/aruba/api/environment.rb +16 -4
- data/lib/aruba/api/filesystem.rb +48 -48
- data/lib/aruba/api/text.rb +15 -3
- data/lib/aruba/aruba_path.rb +24 -95
- data/lib/aruba/basic_configuration.rb +5 -6
- data/lib/aruba/basic_configuration/option.rb +2 -2
- data/lib/aruba/cli.rb +4 -1
- data/lib/aruba/colorizer.rb +10 -99
- data/lib/aruba/config/jruby.rb +15 -5
- data/lib/aruba/config_wrapper.rb +17 -2
- data/lib/aruba/configuration.rb +43 -14
- data/lib/aruba/console.rb +0 -2
- data/lib/aruba/console/help.rb +5 -2
- 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.rb +0 -2
- data/lib/aruba/cucumber/command.rb +190 -93
- data/lib/aruba/cucumber/file.rb +53 -35
- data/lib/aruba/cucumber/hooks.rb +4 -1
- data/lib/aruba/cucumber/testing_frameworks.rb +76 -50
- 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 +10 -3
- data/lib/aruba/initializer.rb +37 -31
- 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 +6 -0
- data/lib/aruba/matchers/command/have_exit_status.rb +15 -3
- 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/command/have_output_size.rb +1 -1
- data/lib/aruba/matchers/directory/be_an_existing_directory.rb +1 -1
- data/lib/aruba/matchers/directory/have_sub_directory.rb +8 -3
- data/lib/aruba/matchers/file/be_an_existing_file.rb +1 -1
- data/lib/aruba/matchers/file/have_file_size.rb +4 -2
- data/lib/aruba/matchers/path/have_permissions.rb +4 -2
- data/lib/aruba/platform.rb +0 -7
- data/lib/aruba/platforms/announcer.rb +36 -17
- 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/command_monitor.rb +39 -3
- data/lib/aruba/platforms/determine_disk_usage.rb +56 -19
- data/lib/aruba/platforms/simple_table.rb +2 -10
- data/lib/aruba/platforms/unix_environment_variables.rb +10 -13
- data/lib/aruba/platforms/unix_platform.rb +16 -12
- data/lib/aruba/platforms/unix_which.rb +1 -1
- data/lib/aruba/platforms/windows_command_string.rb +2 -2
- data/lib/aruba/platforms/windows_environment_variables.rb +9 -2
- data/lib/aruba/platforms/windows_platform.rb +4 -0
- data/lib/aruba/platforms/windows_which.rb +6 -2
- data/lib/aruba/processes/basic_process.rb +13 -15
- data/lib/aruba/processes/debug_process.rb +11 -5
- data/lib/aruba/processes/in_process.rb +4 -2
- data/lib/aruba/processes/spawn_process.rb +32 -16
- data/lib/aruba/rspec.rb +24 -14
- data/lib/aruba/runtime.rb +11 -4
- data/lib/aruba/setup.rb +27 -14
- data/lib/aruba/tasks/docker_helpers.rb +3 -1
- data/lib/aruba/version.rb +1 -1
- metadata +190 -34
- data/bin/build +0 -3
- data/bin/release +0 -3
- data/lib/aruba/platforms/disk_usage_calculator.rb +0 -20
@@ -32,8 +32,8 @@ module Aruba
|
|
32
32
|
contract = opts[:contract]
|
33
33
|
default = opts[:default]
|
34
34
|
|
35
|
-
|
36
|
-
|
35
|
+
raise ArgumentError, 'Either use block or default value' if block_given? && default
|
36
|
+
raise ArgumentError, 'contract-options is required' if contract.nil?
|
37
37
|
|
38
38
|
Contract contract
|
39
39
|
add_option(name, block_given? ? yield(InConfigWrapper.new(known_options)) : default)
|
@@ -61,9 +61,8 @@ module Aruba
|
|
61
61
|
contract = opts[:contract]
|
62
62
|
default = opts[:default]
|
63
63
|
|
64
|
-
|
65
|
-
|
66
|
-
fail ArgumentError, 'contract-options is required' if contract.nil?
|
64
|
+
raise ArgumentError, 'Either use block or default value' if block_given? && default
|
65
|
+
raise ArgumentError, 'contract-options is required' if contract.nil?
|
67
66
|
|
68
67
|
# Add writer
|
69
68
|
add_option(name, block_given? ? yield(InConfigWrapper.new(known_options)) : default)
|
@@ -210,7 +209,7 @@ module Aruba
|
|
210
209
|
end
|
211
210
|
|
212
211
|
def find_option(name)
|
213
|
-
|
212
|
+
raise NotImplementedError, %(Unknown option "#{name}") unless option? name
|
214
213
|
|
215
214
|
local_options[name]
|
216
215
|
end
|
@@ -15,8 +15,8 @@ module Aruba
|
|
15
15
|
name = opts[:name]
|
16
16
|
value = opts[:value]
|
17
17
|
|
18
|
-
|
19
|
-
|
18
|
+
raise ArgumentError, '"name" is required' unless opts.key? :name
|
19
|
+
raise ArgumentError, '"value" is required' unless opts.key? :value
|
20
20
|
|
21
21
|
@name = name
|
22
22
|
@value = value
|
data/lib/aruba/cli.rb
CHANGED
@@ -18,7 +18,10 @@ module Aruba
|
|
18
18
|
end
|
19
19
|
|
20
20
|
desc 'init', 'Initialize aruba'
|
21
|
-
option :test_framework,
|
21
|
+
option :test_framework,
|
22
|
+
default: 'cucumber',
|
23
|
+
enum: %w(cucumber rspec minitest),
|
24
|
+
desc: 'Choose which test framework to use'
|
22
25
|
def init
|
23
26
|
Aruba::Initializer.new.call(options[:test_framework])
|
24
27
|
end
|
data/lib/aruba/colorizer.rb
CHANGED
@@ -1,108 +1,19 @@
|
|
1
|
+
# Aruba
|
1
2
|
module Aruba
|
2
|
-
#
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
ATTRIBUTES = [
|
7
|
-
[:clear, 0],
|
8
|
-
[:reset, 0], # synonym for :clear
|
9
|
-
[:bold, 1],
|
10
|
-
[:dark, 2],
|
11
|
-
[:italic, 3], # not widely implemented
|
12
|
-
[:underline, 4],
|
13
|
-
[:underscore, 4], # synonym for :underline
|
14
|
-
[:blink, 5],
|
15
|
-
[:rapid_blink, 6], # not widely implemented
|
16
|
-
[:negative, 7], # no reverse because of String#reverse
|
17
|
-
[:concealed, 8],
|
18
|
-
[:strikethrough, 9], # not widely implemented
|
19
|
-
[:black, 30],
|
20
|
-
[:red, 31],
|
21
|
-
[:green, 32],
|
22
|
-
[:yellow, 33],
|
23
|
-
[:blue, 34],
|
24
|
-
[:magenta, 35],
|
25
|
-
[:cyan, 36],
|
26
|
-
[:white, 37],
|
27
|
-
[:on_black, 40],
|
28
|
-
[:on_red, 41],
|
29
|
-
[:on_green, 42],
|
30
|
-
[:on_yellow, 43],
|
31
|
-
[:on_blue, 44],
|
32
|
-
[:on_magenta, 45],
|
33
|
-
[:on_cyan, 46],
|
34
|
-
[:on_white, 47]
|
35
|
-
].freeze
|
36
|
-
|
37
|
-
ATTRIBUTE_NAMES = ATTRIBUTES.transpose.first
|
38
|
-
# :startdoc:
|
39
|
-
|
40
|
-
# Returns true, if the coloring function of this module
|
41
|
-
# is switched on, false otherwise.
|
42
|
-
def self.coloring?
|
43
|
-
@coloring
|
44
|
-
end
|
45
|
-
|
46
|
-
# Turns the coloring on or off globally, so you can easily do
|
47
|
-
# this for example:
|
48
|
-
# Cucumber::Term::ANSIColor::coloring = STDOUT.isatty
|
49
|
-
def self.coloring=(val)
|
50
|
-
@coloring = val
|
51
|
-
end
|
52
|
-
self.coloring = true
|
53
|
-
|
54
|
-
ATTRIBUTES.each do |c, v|
|
55
|
-
define_method(c) do |string|
|
56
|
-
result = ''
|
57
|
-
result << "\e[#{v}m" if Aruba::AnsiColor.coloring?
|
58
|
-
if block_given?
|
59
|
-
result << yield
|
60
|
-
elsif string
|
61
|
-
result << string
|
62
|
-
elsif respond_to?(:to_str)
|
63
|
-
result << to_str
|
64
|
-
else
|
65
|
-
return result # only switch on
|
66
|
-
end
|
67
|
-
result << "\e[0m" if Aruba::AnsiColor.coloring?
|
68
|
-
result
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
# Regular expression that is used to scan for ANSI-sequences while
|
73
|
-
# uncoloring strings.
|
74
|
-
COLORED_REGEXP = /\e\[(?:[34][0-7]|[0-9])?m/
|
75
|
-
|
76
|
-
def self.included(klass)
|
77
|
-
return unless klass == String
|
3
|
+
# Simple colorizer class. Only supports the color cyan
|
4
|
+
class Colorizer
|
5
|
+
class << self
|
6
|
+
attr_accessor :coloring
|
78
7
|
|
79
|
-
|
80
|
-
ATTRIBUTE_NAMES.delete(:clear)
|
8
|
+
alias coloring? coloring
|
81
9
|
end
|
82
10
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
if block_given?
|
87
|
-
yield.gsub(COLORED_REGEXP, '')
|
88
|
-
elsif string
|
89
|
-
string.gsub(COLORED_REGEXP, '')
|
90
|
-
elsif respond_to?(:to_str)
|
91
|
-
to_str.gsub(COLORED_REGEXP, '')
|
11
|
+
def cyan(string)
|
12
|
+
if self.class.coloring?
|
13
|
+
"\e[36m#{string}\e[0m"
|
92
14
|
else
|
93
|
-
|
15
|
+
string
|
94
16
|
end
|
95
17
|
end
|
96
|
-
|
97
|
-
# Returns an array of all Aruba::Platforms::AnsiColor attributes as symbols.
|
98
|
-
def attributes
|
99
|
-
ATTRIBUTE_NAMES
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
module Aruba
|
105
|
-
class Colorizer
|
106
|
-
include Aruba::AnsiColor
|
107
18
|
end
|
108
19
|
end
|
data/lib/aruba/config/jruby.rb
CHANGED
@@ -2,16 +2,26 @@ require 'rbconfig'
|
|
2
2
|
|
3
3
|
# ideas taken from: http://blog.headius.com/2010/03/jruby-startup-time-tips.html
|
4
4
|
Aruba.configure do |config|
|
5
|
-
config.before :command do
|
5
|
+
config.before :command do |command|
|
6
6
|
next unless RUBY_PLATFORM == 'java'
|
7
7
|
|
8
|
+
env = command.environment
|
9
|
+
|
10
|
+
jruby_opts = env['JRUBY_OPTS'] || ''
|
11
|
+
|
8
12
|
# disable JIT since these processes are so short lived
|
9
|
-
|
13
|
+
jruby_opts = "-X-C #{jruby_opts}" unless jruby_opts.include? '-X-C'
|
10
14
|
|
11
15
|
# Faster startup for jruby
|
12
|
-
|
16
|
+
jruby_opts = "--dev #{jruby_opts}" unless jruby_opts.include? '--dev'
|
17
|
+
|
18
|
+
env['JRUBY_OPTS'] = jruby_opts
|
19
|
+
|
20
|
+
if /solaris|sunos/i.match?(RbConfig::CONFIG['host_os'])
|
21
|
+
java_opts = env['JAVA_OPTS'] || ''
|
13
22
|
|
14
|
-
|
15
|
-
|
23
|
+
# force jRuby to use client JVM for faster startup times
|
24
|
+
env['JAVA_OPTS'] = "-d32 #{java_opts}" unless java_opts.include?('-d32')
|
25
|
+
end
|
16
26
|
end
|
17
27
|
end
|
data/lib/aruba/config_wrapper.rb
CHANGED
@@ -30,9 +30,11 @@ module Aruba
|
|
30
30
|
# If one method ends with "=", e.g. ":option1=", then notify the event
|
31
31
|
# queue, that the user changes the value of "option1"
|
32
32
|
def method_missing(name, *args, &block)
|
33
|
-
|
33
|
+
notify(name, args) if name.to_s.end_with?('=')
|
34
34
|
|
35
|
-
config.send(name, *args, &block)
|
35
|
+
return config.send(name, *args, &block) if config.respond_to? name
|
36
|
+
|
37
|
+
super
|
36
38
|
end
|
37
39
|
|
38
40
|
# Pass on respond_to?-calls
|
@@ -54,5 +56,18 @@ module Aruba
|
|
54
56
|
def respond_to?(m)
|
55
57
|
config.respond_to? m
|
56
58
|
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
def notify(name, args)
|
63
|
+
event_bus.notify(
|
64
|
+
Events::ChangedConfiguration.new(
|
65
|
+
changed: {
|
66
|
+
name: name.to_s.gsub(/=$/, ''),
|
67
|
+
value: args.first
|
68
|
+
}
|
69
|
+
)
|
70
|
+
)
|
71
|
+
end
|
57
72
|
end
|
58
73
|
end
|
data/lib/aruba/configuration.rb
CHANGED
@@ -19,7 +19,10 @@ module Aruba
|
|
19
19
|
class Configuration < BasicConfiguration
|
20
20
|
option_reader :root_directory, contract: { None => String }, default: Dir.getwd
|
21
21
|
|
22
|
-
option_accessor :working_directory,
|
22
|
+
option_accessor :working_directory,
|
23
|
+
contract: { Aruba::Contracts::RelativePath =>
|
24
|
+
Aruba::Contracts::RelativePath },
|
25
|
+
default: 'tmp/aruba'
|
23
26
|
|
24
27
|
option_reader :fixtures_path_prefix, contract: { None => String }, default: '%'
|
25
28
|
|
@@ -27,29 +30,55 @@ module Aruba
|
|
27
30
|
option_accessor :stop_signal, contract: { Maybe[String] => Maybe[String] }, default: nil
|
28
31
|
option_accessor :io_wait_timeout, contract: { Num => Num }, default: 0.1
|
29
32
|
option_accessor :startup_wait_time, contract: { Num => Num }, default: 0
|
30
|
-
option_accessor :fixtures_directories,
|
33
|
+
option_accessor :fixtures_directories,
|
34
|
+
contract: { Array => ArrayOf[String] },
|
35
|
+
default: %w(features/fixtures spec/fixtures test/fixtures fixtures)
|
36
|
+
|
31
37
|
option_accessor :command_runtime_environment, contract: { Hash => Hash }, default: {}
|
32
|
-
|
33
|
-
|
34
|
-
|
38
|
+
option_accessor :command_search_paths,
|
39
|
+
contract: { ArrayOf[String] => ArrayOf[String] } do |config|
|
40
|
+
[File.join(config.root_directory.value, 'bin'),
|
41
|
+
File.join(config.root_directory.value, 'exe')]
|
42
|
+
end
|
35
43
|
option_accessor :remove_ansi_escape_sequences, contract: { Bool => Bool }, default: true
|
36
|
-
|
37
|
-
|
44
|
+
option_accessor :command_launcher,
|
45
|
+
contract: {
|
46
|
+
Aruba::Contracts::Enum[:in_process, :spawn, :debug] =>
|
47
|
+
Aruba::Contracts::Enum[:in_process, :spawn, :debug]
|
48
|
+
},
|
49
|
+
default: :spawn
|
38
50
|
option_accessor :main_class, contract: { Class => Maybe[Class] }, default: nil
|
39
51
|
|
40
|
-
option_accessor :home_directory,
|
41
|
-
|
42
|
-
|
52
|
+
option_accessor :home_directory,
|
53
|
+
contract: {
|
54
|
+
Or[Aruba::Contracts::AbsolutePath, Aruba::Contracts::RelativePath] =>
|
55
|
+
Or[Aruba::Contracts::AbsolutePath, Aruba::Contracts::RelativePath]
|
56
|
+
} do |config|
|
57
|
+
File.join(config.root_directory.value, config.working_directory.value)
|
58
|
+
end
|
43
59
|
|
44
|
-
option_accessor :log_level,
|
60
|
+
option_accessor :log_level,
|
61
|
+
contract: {
|
62
|
+
Aruba::Contracts::Enum[:fatal, :warn, :debug, :info,
|
63
|
+
:error, :unknown, :silent] =>
|
64
|
+
Aruba::Contracts::Enum[:fatal, :warn, :debug, :info,
|
65
|
+
:error, :unknown, :silent]
|
66
|
+
},
|
67
|
+
default: :info
|
45
68
|
|
46
69
|
# TODO: deprecate this value and replace with "filesystem allocation unit"
|
47
70
|
# equal to 4096 by default. "filesystem allocation unit" would represent
|
48
71
|
# the actual MINIMUM space taken in bytes by a 1-byte file
|
49
|
-
option_accessor :physical_block_size,
|
50
|
-
|
72
|
+
option_accessor :physical_block_size,
|
73
|
+
contract: { Aruba::Contracts::IsPowerOfTwo =>
|
74
|
+
Aruba::Contracts::IsPowerOfTwo },
|
75
|
+
default: 512
|
76
|
+
option_accessor :console_history_file, contract: { String => String },
|
77
|
+
default: '~/.aruba_history'
|
51
78
|
|
52
|
-
option_accessor :activate_announcer_on_command_failure,
|
79
|
+
option_accessor :activate_announcer_on_command_failure,
|
80
|
+
contract: { ArrayOf[Symbol] => ArrayOf[Symbol] },
|
81
|
+
default: []
|
53
82
|
option_accessor :allow_absolute_paths, contract: { Bool => Bool }, default: false
|
54
83
|
end
|
55
84
|
end
|
data/lib/aruba/console.rb
CHANGED
@@ -9,7 +9,6 @@ module Aruba
|
|
9
9
|
class Console
|
10
10
|
# Start the aruba console
|
11
11
|
#
|
12
|
-
# rubocop:disable Metrics/MethodLength
|
13
12
|
def start
|
14
13
|
# Start IRB with current context:
|
15
14
|
# http://stackoverflow.com/questions/4189818/how-to-run-irb-start-in-context-of-current-class
|
@@ -63,6 +62,5 @@ module Aruba
|
|
63
62
|
IRB.irb_at_exit
|
64
63
|
end
|
65
64
|
end
|
66
|
-
# rubocop:enable Metrics/MethodLength
|
67
65
|
end
|
68
66
|
end
|
data/lib/aruba/console/help.rb
CHANGED
@@ -10,7 +10,8 @@ module Aruba
|
|
10
10
|
def aruba_help
|
11
11
|
puts 'Aruba Version: ' + Aruba::VERSION
|
12
12
|
puts 'Issue Tracker: ' + 'https://github.com/cucumber/aruba/issues'
|
13
|
-
puts
|
13
|
+
puts 'Documentation:'
|
14
|
+
puts '* http://www.rubydoc.info/gems/aruba'
|
14
15
|
puts
|
15
16
|
|
16
17
|
nil
|
@@ -18,7 +19,9 @@ module Aruba
|
|
18
19
|
|
19
20
|
# List available methods in aruba
|
20
21
|
def aruba_methods
|
21
|
-
ms = (Aruba::Api.instance_methods - Module.instance_methods)
|
22
|
+
ms = (Aruba::Api.instance_methods - Module.instance_methods)
|
23
|
+
.each_with_object([]) { |e, a| a << format('* %s', e) }
|
24
|
+
.sort
|
22
25
|
|
23
26
|
puts "Available Methods:\n" + ms.join("\n")
|
24
27
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'aruba/
|
1
|
+
require 'aruba/platform'
|
2
2
|
|
3
3
|
# Aruba
|
4
4
|
module Aruba
|
@@ -11,8 +11,8 @@ module Aruba
|
|
11
11
|
# @param [Object] value
|
12
12
|
# The value to be checked
|
13
13
|
def self.valid?(value)
|
14
|
-
|
15
|
-
rescue
|
14
|
+
Aruba.platform.absolute_path? value
|
15
|
+
rescue StandardError
|
16
16
|
false
|
17
17
|
end
|
18
18
|
end
|
@@ -13,8 +13,8 @@ module Aruba
|
|
13
13
|
def self.valid?(value)
|
14
14
|
# explanation for algorithm can be found here:
|
15
15
|
# http://www.exploringbinary.com/ten-ways-to-check-if-an-integer-is-a-power-of-two-in-c/
|
16
|
-
value
|
17
|
-
rescue
|
16
|
+
value.positive? && (value & (value - 1)).zero?
|
17
|
+
rescue StandardError
|
18
18
|
false
|
19
19
|
end
|
20
20
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'aruba/
|
1
|
+
require 'aruba/platform'
|
2
2
|
|
3
3
|
# Aruba
|
4
4
|
module Aruba
|
@@ -11,8 +11,8 @@ module Aruba
|
|
11
11
|
# @param [String] value
|
12
12
|
# The path to be checked
|
13
13
|
def self.valid?(value)
|
14
|
-
|
15
|
-
rescue
|
14
|
+
Aruba.platform.relative_path? value
|
15
|
+
rescue StandardError
|
16
16
|
false
|
17
17
|
end
|
18
18
|
end
|
data/lib/aruba/cucumber.rb
CHANGED
@@ -12,7 +12,8 @@ When(/^I successfully run `(.*?)`(?: for up to ([\d.]+) seconds)?$/) do |cmd, se
|
|
12
12
|
run_command_and_stop(cmd, fail_on_error: true, exit_timeout: secs && secs.to_f)
|
13
13
|
end
|
14
14
|
|
15
|
-
When(/^I run the following (?:commands|script)(?: (?:with|in) `([^`]+)`)?:$/)
|
15
|
+
When(/^I run the following (?:commands|script)(?: (?:with|in) `([^`]+)`)?:$/) \
|
16
|
+
do |shell, commands|
|
16
17
|
full_path = expand_path('bin/myscript')
|
17
18
|
|
18
19
|
Aruba.platform.mkdir(expand_path('bin'))
|
@@ -23,8 +24,7 @@ When(/^I run the following (?:commands|script)(?: (?:with|in) `([^`]+)`)?:$/) do
|
|
23
24
|
end
|
24
25
|
|
25
26
|
When(/^I run `([^`]*)` interactively$/) do |cmd|
|
26
|
-
|
27
|
-
@interactive = run_command(cmd)
|
27
|
+
run_command(sanitize_text(cmd))
|
28
28
|
end
|
29
29
|
|
30
30
|
# Merge interactive and background after refactoring with event queue
|
@@ -62,7 +62,8 @@ When(/^I (terminate|stop) the command (?:"([^"]*)"|(?:started last))$/) do |sign
|
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
|
-
When(/^I stop the command(?: started last)? if (output|stdout|stderr) contains:$/)
|
65
|
+
When(/^I stop the command(?: started last)? if (output|stdout|stderr) contains:$/) \
|
66
|
+
do |channel, expected|
|
66
67
|
begin
|
67
68
|
Timeout.timeout(aruba.config.exit_timeout) do
|
68
69
|
loop do
|
@@ -80,7 +81,7 @@ When(/^I stop the command(?: started last)? if (output|stdout|stderr) contains:$
|
|
80
81
|
sleep 0.1
|
81
82
|
end
|
82
83
|
end
|
83
|
-
rescue ChildProcess::TimeoutError,
|
84
|
+
rescue ChildProcess::TimeoutError, Timeout::Error
|
84
85
|
last_command_started.terminate
|
85
86
|
end
|
86
87
|
end
|
@@ -119,21 +120,10 @@ Then(/^the output should be (\d+) bytes long$/) do |size|
|
|
119
120
|
expect(last_command_started.output).to have_output_size size.to_i
|
120
121
|
end
|
121
122
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
when :stderr
|
127
|
-
:have_output_on_stderr
|
128
|
-
when :stdout
|
129
|
-
:have_output_on_stdout
|
130
|
-
end
|
131
|
-
|
132
|
-
commands = if cmd
|
133
|
-
[aruba.command_monitor.find(Aruba.platform.detect_ruby(cmd))]
|
134
|
-
else
|
135
|
-
all_commands
|
136
|
-
end
|
123
|
+
## the stderr should contain "hello"
|
124
|
+
Then(/^(?:the )?(output|stderr|stdout) should( not)? contain( exactly)? "([^"]*)"$/) \
|
125
|
+
do |channel, negated, exactly, expected|
|
126
|
+
combined_output = send("all_#{channel}")
|
137
127
|
|
138
128
|
output_string_matcher = if exactly
|
139
129
|
:an_output_string_being_eq
|
@@ -142,33 +132,112 @@ Then(/^(?:the )?(output|stderr|stdout)(?: from "([^"]*)")? should( not)? contain
|
|
142
132
|
end
|
143
133
|
|
144
134
|
if negated
|
145
|
-
expect(
|
135
|
+
expect(combined_output).not_to send(output_string_matcher, expected)
|
146
136
|
else
|
147
|
-
expect(
|
137
|
+
expect(combined_output).to send(output_string_matcher, expected)
|
148
138
|
end
|
149
139
|
end
|
150
140
|
|
151
|
-
## the stderr should contain "hello"
|
152
141
|
## the stderr from "echo -n 'Hello'" should contain "hello"
|
142
|
+
Then(
|
143
|
+
/^(?:the )?(output|stderr|stdout) from "([^"]*)" should contain( exactly)? "([^"]*)"$/
|
144
|
+
) do |channel, cmd, exactly, expected|
|
145
|
+
matcher = case channel
|
146
|
+
when 'output'; then :have_output
|
147
|
+
when 'stderr'; then :have_output_on_stderr
|
148
|
+
when 'stdout'; then :have_output_on_stdout
|
149
|
+
end
|
150
|
+
|
151
|
+
command = aruba.command_monitor.find(Aruba.platform.detect_ruby(cmd))
|
152
|
+
|
153
|
+
output_string_matcher = if exactly
|
154
|
+
:an_output_string_being_eq
|
155
|
+
else
|
156
|
+
:an_output_string_including
|
157
|
+
end
|
158
|
+
|
159
|
+
expect(command).to send(matcher, send(output_string_matcher, expected))
|
160
|
+
end
|
161
|
+
|
162
|
+
## the stderr from "echo -n 'Hello'" should not contain "hello"
|
163
|
+
Then(
|
164
|
+
/^(?:the )?(output|stderr|stdout) from "([^"]*)" should not contain( exactly)? "([^"]*)"$/
|
165
|
+
) do |channel, cmd, exactly, expected|
|
166
|
+
matcher = case channel
|
167
|
+
when 'output'; then :have_output
|
168
|
+
when 'stderr'; then :have_output_on_stderr
|
169
|
+
when 'stdout'; then :have_output_on_stdout
|
170
|
+
end
|
171
|
+
|
172
|
+
command = aruba.command_monitor.find(Aruba.platform.detect_ruby(cmd))
|
173
|
+
|
174
|
+
output_string_matcher = if exactly
|
175
|
+
:an_output_string_being_eq
|
176
|
+
else
|
177
|
+
:an_output_string_including
|
178
|
+
end
|
179
|
+
|
180
|
+
expect(command).not_to send(matcher, send(output_string_matcher, expected))
|
181
|
+
end
|
182
|
+
|
183
|
+
## the stderr should not contain exactly:
|
184
|
+
Then(/^(?:the )?(output|stderr|stdout) should not contain( exactly)?:$/) \
|
185
|
+
do |channel, exactly, expected|
|
186
|
+
combined_output = send("all_#{channel}")
|
187
|
+
|
188
|
+
output_string_matcher = if exactly
|
189
|
+
:an_output_string_being_eq
|
190
|
+
else
|
191
|
+
:an_output_string_including
|
192
|
+
end
|
193
|
+
|
194
|
+
expect(combined_output).not_to send(output_string_matcher, expected)
|
195
|
+
end
|
196
|
+
|
153
197
|
## the stderr should contain exactly:
|
198
|
+
Then(/^(?:the )?(output|stderr|stdout) should contain( exactly)?:$/) \
|
199
|
+
do |channel, exactly, expected|
|
200
|
+
combined_output = send("all_#{channel}")
|
201
|
+
|
202
|
+
output_string_matcher = if exactly
|
203
|
+
:an_output_string_being_eq
|
204
|
+
else
|
205
|
+
:an_output_string_including
|
206
|
+
end
|
207
|
+
|
208
|
+
expect(combined_output).to send(output_string_matcher, expected)
|
209
|
+
end
|
210
|
+
|
211
|
+
## the stderr from "echo -n 'Hello'" should not contain exactly:
|
212
|
+
Then(/^(?:the )?(output|stderr|stdout) from "([^"]*)" should not contain( exactly)?:$/) \
|
213
|
+
do |channel, cmd, exactly, expected|
|
214
|
+
matcher = case channel
|
215
|
+
when 'output'; then :have_output
|
216
|
+
when 'stderr'; then :have_output_on_stderr
|
217
|
+
when 'stdout'; then :have_output_on_stdout
|
218
|
+
end
|
219
|
+
|
220
|
+
command = aruba.command_monitor.find(Aruba.platform.detect_ruby(cmd))
|
221
|
+
|
222
|
+
output_string_matcher = if exactly
|
223
|
+
:an_output_string_being_eq
|
224
|
+
else
|
225
|
+
:an_output_string_including
|
226
|
+
end
|
227
|
+
|
228
|
+
expect(command).not_to send(matcher, send(output_string_matcher, expected))
|
229
|
+
end
|
230
|
+
|
154
231
|
## the stderr from "echo -n 'Hello'" should contain exactly:
|
155
|
-
Then(/^(?:the )?(output|stderr|stdout)
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
when :
|
160
|
-
|
161
|
-
when :stdout
|
162
|
-
:have_output_on_stdout
|
163
|
-
else
|
164
|
-
fail ArgumentError, %(Invalid channel "#{channel}" chosen. Only "output", "stderr" or "stdout" are allowed.)
|
232
|
+
Then(/^(?:the )?(output|stderr|stdout) from "([^"]*)" should contain( exactly)?:$/) \
|
233
|
+
do |channel, cmd, exactly, expected|
|
234
|
+
matcher = case channel
|
235
|
+
when 'output'; then :have_output
|
236
|
+
when 'stderr'; then :have_output_on_stderr
|
237
|
+
when 'stdout'; then :have_output_on_stdout
|
165
238
|
end
|
166
239
|
|
167
|
-
|
168
|
-
[aruba.command_monitor.find(Aruba.platform.detect_ruby(cmd))]
|
169
|
-
else
|
170
|
-
all_commands
|
171
|
-
end
|
240
|
+
command = aruba.command_monitor.find(Aruba.platform.detect_ruby(cmd))
|
172
241
|
|
173
242
|
output_string_matcher = if exactly
|
174
243
|
:an_output_string_being_eq
|
@@ -176,45 +245,45 @@ Then(/^(?:the )?(output|stderr|stdout)(?: from "([^"]*)")? should( not)? contain
|
|
176
245
|
:an_output_string_including
|
177
246
|
end
|
178
247
|
|
179
|
-
|
180
|
-
expect(commands).not_to include_an_object send(matcher, send(output_string_matcher, expected))
|
181
|
-
else
|
182
|
-
expect(commands).to include_an_object send(matcher, send(output_string_matcher, expected))
|
183
|
-
end
|
248
|
+
expect(command).to send(matcher, send(output_string_matcher, expected))
|
184
249
|
end
|
185
250
|
|
186
251
|
# "the output should match" allows regex in the partial_output, if
|
187
252
|
# you don't need regex, use "the output should contain" instead since
|
188
253
|
# that way, you don't have to escape regex characters that
|
189
254
|
# appear naturally in the output
|
190
|
-
Then(
|
255
|
+
Then(%r{^the output should( not)? match /([^/]*)/$}) do |negated, expected|
|
191
256
|
if negated
|
192
|
-
expect(all_commands)
|
257
|
+
expect(all_commands)
|
258
|
+
.not_to include_an_object have_output an_output_string_matching(expected)
|
193
259
|
else
|
194
|
-
expect(all_commands)
|
260
|
+
expect(all_commands)
|
261
|
+
.to include_an_object have_output an_output_string_matching(expected)
|
195
262
|
end
|
196
263
|
end
|
197
264
|
|
198
265
|
Then(/^the output should( not)? match %r<([^>]*)>$/) do |negated, expected|
|
199
266
|
if negated
|
200
|
-
expect(all_commands)
|
267
|
+
expect(all_commands)
|
268
|
+
.not_to include_an_object have_output an_output_string_matching(expected)
|
201
269
|
else
|
202
|
-
expect(all_commands)
|
270
|
+
expect(all_commands)
|
271
|
+
.to include_an_object have_output an_output_string_matching(expected)
|
203
272
|
end
|
204
273
|
end
|
205
274
|
|
206
275
|
Then(/^the output should( not)? match:$/) do |negated, expected|
|
207
276
|
if negated
|
208
|
-
expect(all_commands)
|
277
|
+
expect(all_commands)
|
278
|
+
.not_to include_an_object have_output an_output_string_matching(expected)
|
209
279
|
else
|
210
|
-
expect(all_commands)
|
280
|
+
expect(all_commands)
|
281
|
+
.to include_an_object have_output an_output_string_matching(expected)
|
211
282
|
end
|
212
283
|
end
|
213
284
|
|
214
285
|
Then(/^the exit status should( not)? be (\d+)$/) do |negated, exit_status|
|
215
|
-
if last_command_stopped.nil?
|
216
|
-
last_command_started.stop
|
217
|
-
end
|
286
|
+
last_command_started.stop if last_command_stopped.nil?
|
218
287
|
|
219
288
|
if negated
|
220
289
|
expect(last_command_stopped).not_to have_exit_status exit_status.to_i
|
@@ -223,7 +292,7 @@ Then(/^the exit status should( not)? be (\d+)$/) do |negated, exit_status|
|
|
223
292
|
end
|
224
293
|
end
|
225
294
|
|
226
|
-
Then(/^it should
|
295
|
+
Then(/^it should not (pass|fail) with "(.*?)"$/) do |pass_fail, expected|
|
227
296
|
last_command_started.stop
|
228
297
|
|
229
298
|
if pass_fail == 'pass'
|
@@ -232,14 +301,22 @@ Then(/^it should( not)? (pass|fail) with "(.*?)"$/) do |negated, pass_fail, expe
|
|
232
301
|
expect(last_command_stopped).not_to be_successfully_executed
|
233
302
|
end
|
234
303
|
|
235
|
-
|
236
|
-
|
304
|
+
expect(last_command_stopped).not_to have_output an_output_string_including(expected)
|
305
|
+
end
|
306
|
+
|
307
|
+
Then(/^it should (pass|fail) with "(.*?)"$/) do |pass_fail, expected|
|
308
|
+
last_command_started.stop
|
309
|
+
|
310
|
+
if pass_fail == 'pass'
|
311
|
+
expect(last_command_stopped).to be_successfully_executed
|
237
312
|
else
|
238
|
-
expect(last_command_stopped).
|
313
|
+
expect(last_command_stopped).not_to be_successfully_executed
|
239
314
|
end
|
315
|
+
|
316
|
+
expect(last_command_stopped).to have_output an_output_string_including(expected)
|
240
317
|
end
|
241
318
|
|
242
|
-
Then(/^it should
|
319
|
+
Then(/^it should not (pass|fail) with:$/) do |pass_fail, expected|
|
243
320
|
last_command_started.stop
|
244
321
|
|
245
322
|
if pass_fail == 'pass'
|
@@ -248,14 +325,22 @@ Then(/^it should( not)? (pass|fail) with:$/) do |negated, pass_fail, expected|
|
|
248
325
|
expect(last_command_stopped).not_to be_successfully_executed
|
249
326
|
end
|
250
327
|
|
251
|
-
|
252
|
-
|
328
|
+
expect(last_command_stopped).not_to have_output an_output_string_including(expected)
|
329
|
+
end
|
330
|
+
|
331
|
+
Then(/^it should (pass|fail) with:$/) do |pass_fail, expected|
|
332
|
+
last_command_started.stop
|
333
|
+
|
334
|
+
if pass_fail == 'pass'
|
335
|
+
expect(last_command_stopped).to be_successfully_executed
|
253
336
|
else
|
254
|
-
expect(last_command_stopped).
|
337
|
+
expect(last_command_stopped).not_to be_successfully_executed
|
255
338
|
end
|
339
|
+
|
340
|
+
expect(last_command_stopped).to have_output an_output_string_including(expected)
|
256
341
|
end
|
257
342
|
|
258
|
-
Then(/^it should
|
343
|
+
Then(/^it should not (pass|fail) with exactly:$/) do |pass_fail, expected|
|
259
344
|
last_command_started.stop
|
260
345
|
|
261
346
|
if pass_fail == 'pass'
|
@@ -264,14 +349,22 @@ Then(/^it should( not)? (pass|fail) with exactly:$/) do |negated, pass_fail, exp
|
|
264
349
|
expect(last_command_stopped).not_to be_successfully_executed
|
265
350
|
end
|
266
351
|
|
267
|
-
|
268
|
-
|
352
|
+
expect(last_command_stopped).not_to have_output an_output_string_eq(expected)
|
353
|
+
end
|
354
|
+
|
355
|
+
Then(/^it should (pass|fail) with exactly:$/) do |pass_fail, expected|
|
356
|
+
last_command_started.stop
|
357
|
+
|
358
|
+
if pass_fail == 'pass'
|
359
|
+
expect(last_command_stopped).to be_successfully_executed
|
269
360
|
else
|
270
|
-
expect(last_command_stopped).
|
361
|
+
expect(last_command_stopped).not_to be_successfully_executed
|
271
362
|
end
|
363
|
+
|
364
|
+
expect(last_command_stopped).to have_output an_output_string_being_eq(expected)
|
272
365
|
end
|
273
366
|
|
274
|
-
Then(/^it should
|
367
|
+
Then(/^it should not (pass|fail) (?:with regexp?|matching):$/) do |pass_fail, expected|
|
275
368
|
last_command_started.stop
|
276
369
|
|
277
370
|
if pass_fail == 'pass'
|
@@ -280,45 +373,48 @@ Then(/^it should( not)? (pass|fail) (?:with regexp?|matching):$/) do |negated, p
|
|
280
373
|
expect(last_command_stopped).not_to be_successfully_executed
|
281
374
|
end
|
282
375
|
|
283
|
-
|
284
|
-
|
376
|
+
expect(last_command_stopped).not_to have_output an_output_string_matching(expected)
|
377
|
+
end
|
378
|
+
|
379
|
+
Then(/^it should (pass|fail) (?:with regexp?|matching):$/) do |pass_fail, expected|
|
380
|
+
last_command_started.stop
|
381
|
+
|
382
|
+
if pass_fail == 'pass'
|
383
|
+
expect(last_command_stopped).to be_successfully_executed
|
285
384
|
else
|
286
|
-
expect(last_command_stopped).
|
385
|
+
expect(last_command_stopped).not_to be_successfully_executed
|
287
386
|
end
|
387
|
+
|
388
|
+
expect(last_command_stopped).to have_output an_output_string_matching(expected)
|
288
389
|
end
|
289
390
|
|
290
391
|
Then(/^(?:the )?(output|stderr|stdout) should not contain anything$/) do |channel|
|
291
|
-
matcher = case channel
|
292
|
-
when :
|
293
|
-
|
294
|
-
when :
|
295
|
-
:have_output_on_stderr
|
296
|
-
when :stdout
|
297
|
-
:have_output_on_stdout
|
298
|
-
else
|
299
|
-
fail ArgumentError, %(Invalid channel "#{channel}" chosen. Only "output", "stdout" and "stderr" are supported.)
|
392
|
+
matcher = case channel
|
393
|
+
when 'output'; then :have_output
|
394
|
+
when 'stderr'; then :have_output_on_stderr
|
395
|
+
when 'stdout'; then :have_output_on_stdout
|
300
396
|
end
|
301
397
|
|
302
398
|
expect(all_commands).to include_an_object send(matcher, be_nil.or(be_empty))
|
303
399
|
end
|
304
400
|
|
305
|
-
Then(/^(?:the )?(output|stdout|stderr) should( not)? contain all of these lines:$/)
|
401
|
+
Then(/^(?:the )?(output|stdout|stderr) should( not)? contain all of these lines:$/) \
|
402
|
+
do |channel, negated, table|
|
306
403
|
table.raw.flatten.each do |expected|
|
307
|
-
case channel
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
else
|
315
|
-
fail ArgumentError, %(Invalid channel "#{channel}" chosen. Only "output", "stdout" and "stderr" are supported.)
|
316
|
-
end
|
404
|
+
_matcher = case channel
|
405
|
+
when 'output'; then :have_output
|
406
|
+
when 'stderr'; then :have_output_on_stderr
|
407
|
+
when 'stdout'; then :have_output_on_stdout
|
408
|
+
end
|
409
|
+
|
410
|
+
# TODO: This isn't actually using the above. It's hardcoded to use have_output only
|
317
411
|
|
318
412
|
if negated
|
319
|
-
expect(all_commands)
|
413
|
+
expect(all_commands)
|
414
|
+
.not_to include_an_object have_output an_output_string_including(expected)
|
320
415
|
else
|
321
|
-
expect(all_commands)
|
416
|
+
expect(all_commands)
|
417
|
+
.to include_an_object have_output an_output_string_including(expected)
|
322
418
|
end
|
323
419
|
end
|
324
420
|
end
|
@@ -339,10 +435,11 @@ Given(/^I wait ([\d.]+) seconds? for (?:a|the) command to start up$/) do |second
|
|
339
435
|
aruba.config.startup_wait_time = seconds.to_f
|
340
436
|
end
|
341
437
|
|
342
|
-
When(/^I send the signal "([^"]*)" to the command (?:"([^"]*)"|(?:started last))$/)
|
438
|
+
When(/^I send the signal "([^"]*)" to the command (?:"([^"]*)"|(?:started last))$/) \
|
439
|
+
do |signal, command|
|
343
440
|
if command
|
344
441
|
cmd = all_commands.find { |c| c.commandline == command }
|
345
|
-
|
442
|
+
raise ArgumentError, %(No command "#{command}" found) if cmd.nil?
|
346
443
|
|
347
444
|
cmd.send_signal signal
|
348
445
|
else
|